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

47 lines
749 B
Bash
Raw Normal View History

2021-03-02 14:24:31 +03:00
#!/bin/bash
export LC_ALL=C
2021-03-02 14:24:31 +03:00
set -e
CC="${CC:-cc}"
CXX="${CXX:-c++}"
GCC="${GCC:-gcc}"
GXX="${GXX:-g++}"
OBJDUMP="${OBJDUMP:-objdump}"
MACHINE="${MACHINE:-$(uname -m)}"
2022-01-24 04:21:08 +03:00
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
2022-01-07 12:06:53 +03:00
t=out/test/elf/$testname
mkdir -p $t
2021-03-02 14:24:31 +03:00
2022-01-07 12:06:53 +03:00
cat <<EOF | $CC -c -fPIC -o$t/a.o -xc -
2021-03-02 15:47:19 +03:00
int foo = 4;
int get_foo() {
2021-03-02 14:24:31 +03:00
return foo;
}
void *bar() {
return bar;
}
EOF
2022-01-07 12:06:53 +03:00
$CC -B. -shared -fPIC -o $t/b.so $t/a.o -Wl,-Bsymbolic
2022-01-07 12:06:53 +03:00
cat <<EOF | $CC -c -o $t/c.o -xc - -fno-PIE
2021-03-02 14:24:31 +03:00
#include <stdio.h>
2021-03-02 15:47:19 +03:00
extern int foo;
int get_foo();
2021-03-02 14:24:31 +03:00
void *bar();
int main() {
2021-03-02 15:47:19 +03:00
foo = 3;
printf("%d %d %d\n", foo, get_foo(), bar == bar());
2021-03-02 14:24:31 +03:00
}
EOF
2022-01-07 12:06:53 +03:00
$CC -B. -no-pie -o $t/exe $t/c.o $t/b.so
$QEMU $t/exe | grep -q '3 4 0'
2021-03-02 14:24:31 +03:00
echo OK