1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 08:37:28 +03:00
mold/test/elf/bsymbolic.sh
2022-09-29 20:02:33 +08:00

36 lines
641 B
Bash
Executable File

#!/bin/bash
export LC_ALL=C
set -e
CC="${TEST_CC:-cc}"
CXX="${TEST_CXX:-c++}"
GCC="${TEST_GCC:-gcc}"
GXX="${TEST_GXX:-g++}"
MACHINE="${MACHINE:-$(uname -m)}"
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
t=out/test/elf/$MACHINE/$testname
mkdir -p $t
cat <<EOF | $CC -c -fPIC -o$t/a.o -xc -
int foo = 4;
int get_foo() { return foo; }
EOF
$CC -B. -shared -fPIC -o $t/b.so $t/a.o -Wl,-Bsymbolic
cat <<EOF | $CC -c -o $t/c.o -xc - -fno-PIE
#include <stdio.h>
int foo = 3;
int get_foo();
int main() {
printf("%d %d\n", foo, get_foo());
}
EOF
$CC -B. -no-pie -o $t/exe $t/c.o $t/b.so
$QEMU $t/exe | grep -q '3 4'
echo OK