1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
mold/test/reloc.sh

164 lines
2.6 KiB
Bash
Raw Normal View History

2020-12-17 14:21:51 +03:00
#!/bin/bash
set -e
2021-03-01 10:28:16 +03:00
cd $(dirname $0)
2021-01-25 05:02:01 +03:00
echo -n "Testing $(basename -s .sh $0) ... "
2020-12-17 14:21:51 +03:00
t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t
2021-02-27 14:28:33 +03:00
cat <<'EOF' | cc -fPIC -c -o $t/a.o -x assembler -
.data
.globl ext_var
.type ext_var, @object
.size ext_var, 56
ext_var:
.long 56
EOF
cat <<'EOF' | cc -fPIC -c -o $t/b.o -xc -
#include <stdio.h>
int print(int x) {
printf("%d\n", x);
return 0;
}
int print64(long x) {
printf("%ld\n", x);
return 0;
}
2021-02-27 14:28:33 +03:00
EOF
cc -shared -o $t/c.so $t/a.o $t/b.o
# Absolute symbol
cat <<'EOF' > $t/d.s
.globl abs_sym
.set abs_sym, 42
.globl main
main:
lea abs_sym, %edi
call print
ret
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -no-pie
$t/exe | grep -q 42
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -pie
$t/exe | grep -q 42
# GOT
cat <<'EOF' > $t/d.s
.globl main
main:
mov ext_var@GOTPCREL(%rip), %rdi
mov (%rdi), %edi
call print
ret
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -no-pie
$t/exe | grep -q 56
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -pie
$t/exe | grep -q 56
# Copyrel
cat <<'EOF' > $t/d.s
.globl main
main:
mov ext_var(%rip), %edi
call print
ret
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -no-pie
$t/exe | grep -q 56
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -pie
$t/exe | grep -q 56
# Copyrel
cat <<'EOF' > $t/d.s
.globl main
main:
mov foo(%rip), %rdi
mov (%rdi), %edi
call print
ret
.data
foo:
.quad ext_var
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -no-pie
$t/exe | grep -q 56
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -pie
$t/exe | grep -q 56
# PLT
cat <<'EOF' > $t/d.s
.globl main
main:
mov $76, %edi
call print@PLT
ret
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -no-pie
$t/exe | grep -q 76
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -pie
$t/exe | grep -q 76
# PLT
cat <<'EOF' > $t/d.s
.globl main
main:
mov $76, %edi
lea print(%rip), %rax
call *%rax
ret
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -no-pie
$t/exe | grep -q 76
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s -pie
$t/exe | grep -q 76
2020-12-17 14:21:51 +03:00
# SIZE32
cat <<'EOF' > $t/d.s
.globl main
main:
mov $foo+2@SIZE, %edi
call print@PLT
ret
.data
.globl foo
.type foo, %object
.size foo, 24
foo:
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s
$t/exe | grep -q 26
# SIZE64
cat <<'EOF' > $t/d.s
.globl main
main:
movabs $foo+5@SIZE, %rdi
call print64@PLT
ret
.data
.globl foo
.type foo, %object
.size foo, 56
foo:
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/d.s
$t/exe | grep -q 61
2021-01-25 05:02:01 +03:00
echo OK