1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-24 00:43:18 +03:00
mold/test/dt-init.sh

34 lines
799 B
Bash
Raw Normal View History

2021-03-01 06:45:13 +03:00
#!/bin/bash
set -e
2021-03-01 10:28:16 +03:00
cd $(dirname $0)
2021-07-21 08:49:02 +03:00
mold=`pwd`/../mold
2021-03-01 06:45:13 +03:00
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t
cat <<EOF | clang -c -o $t/a.o -x assembler -
2021-03-01 06:49:09 +03:00
.globl main, init, fini
2021-03-01 06:45:13 +03:00
main:
ret
2021-03-01 06:49:09 +03:00
init:
ret
fini:
ret
2021-03-01 06:45:13 +03:00
EOF
clang -fuse-ld=$mold -o $t/exe $t/a.o
2021-03-01 06:45:13 +03:00
readelf -a $t/exe > $t/log
2021-07-15 18:11:03 +03:00
grep -Pqz '(?s)\(INIT\)\s+0x([0-9a-f]+)\b.*\1\s+0 \w+\s+GLOBAL \w+\s+\d+ _init\b' $t/log
2021-07-15 18:11:03 +03:00
grep -Pqz '(?s)\(FINI\)\s+0x([0-9a-f]+)\b.*\1\s+0 \w+\s+GLOBAL \w+\s+\d+ _fini\b' $t/log
2021-03-01 06:45:13 +03:00
clang -fuse-ld=$mold -o $t/exe $t/a.o -Wl,-init,init -Wl,-fini,fini
2021-03-01 06:49:09 +03:00
readelf -a $t/exe > $t/log
grep -Pqz '(?s)\(INIT\)\s+0x([0-9a-f]+)\b.*\1\s+0 NOTYPE GLOBAL DEFAULT\s+\d+ init\b' $t/log
grep -Pqz '(?s)\(FINI\)\s+0x([0-9a-f]+)\b.*\1\s+0 NOTYPE GLOBAL DEFAULT\s+\d+ fini\b' $t/log
2021-03-01 06:49:09 +03:00
2021-03-01 06:45:13 +03:00
echo OK