forked from bluewhalesystems/sold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdt-init.sh
executable file
·45 lines (32 loc) · 832 Bytes
/
dt-init.sh
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
#!/bin/bash
. $(dirname $0)/common.inc
[ $MACHINE = riscv64 -o $MACHINE = riscv32 ] && skip
# musl libc does not support init/fini on ARM
# https://github.com/rui314/mold/issues/951
[ $MACHINE = arm -o $MACHINE = aarch64 ] && ldd --help 2>&1 | grep -q musl && skip
cat <<EOF | $CC -c -fPIC -o $t/a.o -xc -
void keep();
int main() {
keep();
}
EOF
cat <<EOF | $CC -c -fPIC -o $t/b.o -xc -
#include <stdio.h>
void init() {
printf("init\n");
}
void fini() {
printf("fini\n");
}
void keep() {}
EOF
$CC -B. -o $t/c.so -shared $t/b.o
$CC -B. -o $t/d.so -shared $t/b.o -Wl,-init,init -Wl,-fini,fini
$CC -B. -o $t/exe1 $t/a.o $t/c.so
$CC -B. -o $t/exe2 $t/a.o $t/d.so
$QEMU $t/exe1 > $t/log1
$QEMU $t/exe2 > $t/log2
! grep -q init $t/log1 || false
! grep -q fini $t/log1 || false
grep -q init $t/log2
grep -q fini $t/log2