1
1
mirror of https://github.com/rui314/mold.git synced 2024-08-16 16:30:27 +03:00

Improve a test

We want to make sure that absolute symbols in DSOs are dynamically
resolved.
This commit is contained in:
Rui Ueyama 2024-04-12 16:31:12 +09:00
parent 496e2f3eb3
commit 60ce1aaf01

View File

@ -1,27 +1,31 @@
#!/bin/bash
. $(dirname $0)/common.inc
cat <<EOF | $CC -fPIC -c -o $t/a.o -xassembler -
cat <<EOF | $CC -B. -fPIC -shared -o $t/a.so -xassembler -
.globl foo
foo = 3;
EOF
$CC -B. -shared -o $t/b.so $t/a.o
cat <<EOF | $CC -B. -fPIC -shared -o $t/b.so -xassembler -
.globl foo
foo = 5;
EOF
cat <<EOF > $t/c.c
cat <<EOF | $CC -fPIC -c -o $t/c.o -xc -
#include <stdio.h>
extern char foo;
int main() { printf("foo=%p\n", &foo); }
EOF
$CC -fPIC -c -o $t/d.o $t/c.c
# This test fails with older glibc
$CC -o $t/exe1 -pie $t/d.o $t/b.so 2> /dev/null || skip
$CC -B. -o $t/exe1 -pie $t/c.o $t/a.so 2> /dev/null || skip
$QEMU $t/exe1 | grep -q 'foo=0x3' || skip
LD_PRELOAD=$t/b.so $QEMU $t/exe1 | grep -q 'foo=0x5'
$CC -B. -o $t/exe2 -pie $t/d.o $t/b.so
$CC -B. -o $t/exe2 -pie $t/c.o $t/a.so
$QEMU $t/exe2 | grep -q 'foo=0x3'
LD_PRELOAD=$t/b.so $QEMU $t/exe2 | grep -q 'foo=0x5'
$CC -B. -o $t/exe3 -no-pie $t/d.o $t/b.so
$CC -B. -o $t/exe3 -no-pie $t/c.o $t/a.so
$QEMU $t/exe3 | grep -q 'foo=0x3'
LD_PRELOAD=$t/b.so $QEMU $t/exe3 | grep -q 'foo=0x5'