File: init-array-priorities.sh

package info (click to toggle)
mold 2.37.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 43,640 kB
  • sloc: ansic: 190,908; cpp: 153,224; asm: 29,233; sh: 13,504; python: 4,247; makefile: 3,322; ada: 1,681; pascal: 1,139; xml: 278; objc: 176; javascript: 37
file content (52 lines) | stat: -rwxr-xr-x 1,260 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
. $(dirname $0)/common.inc

# musl does not support GNU-style init/fini priorities
is_musl && skip

cat <<'EOF' | $CC -c -o $t/a.o -xc -
#include <stdio.h>
__attribute__((constructor(10000))) void init4() { printf("1"); }
EOF

cat <<'EOF' | $CC -c -o $t/b.o -xc -
#include <stdio.h>
__attribute__((constructor(1000))) void init3() { printf("2"); }
EOF

cat <<'EOF' | $CC -c -o $t/c.o -xc -
#include <stdio.h>
__attribute__((constructor)) void init1() { printf("3"); }
EOF

cat <<'EOF' | $CC -c -o $t/d.o -xc -
#include <stdio.h>
__attribute__((constructor)) void init2() { printf("4"); }
EOF

cat <<'EOF' | $CC -c -o $t/e.o -xc -
#include <stdio.h>
__attribute__((destructor(10000))) void fini4() { printf("5"); }
EOF

cat <<'EOF' | $CC -c -o $t/f.o -xc -
#include <stdio.h>
__attribute__((destructor(1000))) void fini3() { printf("6"); }
EOF

cat <<'EOF' | $CC -c -o $t/g.o -xc -
#include <stdio.h>
__attribute__((destructor)) void fini1() { printf("7"); }
EOF

cat <<'EOF' | $CC -c -o $t/h.o -xc -
#include <stdio.h>
__attribute__((destructor)) void fini2() { printf("8"); }
EOF

cat <<EOF | $CC -c -o $t/i.o -xc -
int main() {}
EOF

$CC -B. -o $t/exe $t/a.o $t/b.o $t/c.o $t/d.o $t/e.o $t/f.o $t/g.o $t/h.o $t/i.o
$QEMU $t/exe | grep '21348756'