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

46 lines
767 B
Bash
Raw Normal View History

2021-02-25 14:26:10 +03:00
#!/bin/bash
export LANG=
2021-02-25 14:26:10 +03:00
set -e
CC="${CC:-cc}"
CXX="${CXX:-c++}"
2022-01-24 04:21:08 +03:00
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
2022-01-07 12:06:53 +03:00
t=out/test/elf/$testname
mkdir -p $t
2021-02-25 14:26:10 +03:00
2022-01-07 12:06:53 +03:00
cat <<'EOF' | $CC -fPIC -c -o $t/a.o -xc -
2021-08-20 06:48:12 +03:00
void fn2();
void fn1() { fn2(); }
void fn3() {}
2021-02-25 14:26:10 +03:00
EOF
2022-01-07 12:06:53 +03:00
$CC -B. -shared -o $t/b.so $t/a.o
2021-02-25 14:26:10 +03:00
2022-01-07 12:06:53 +03:00
readelf --dyn-syms $t/b.so > $t/log
2021-02-25 14:26:10 +03:00
2022-01-07 12:06:53 +03:00
grep -q '0000000000000000 0 NOTYPE GLOBAL DEFAULT UND fn2' $t/log
2022-01-24 04:21:08 +03:00
grep -Eq 'FUNC GLOBAL DEFAULT .* fn1' $t/log
2021-02-25 14:26:10 +03:00
2022-01-07 12:06:53 +03:00
cat <<EOF | $CC -fPIC -c -o $t/c.o -xc -
2021-02-25 14:55:57 +03:00
#include <stdio.h>
2021-02-25 14:46:43 +03:00
int fn1();
2021-02-25 14:55:57 +03:00
void fn2() {
printf("hello\n");
2021-02-25 14:46:43 +03:00
}
int main() {
2021-02-25 14:55:57 +03:00
fn1();
return 0;
2021-02-25 14:46:43 +03:00
}
EOF
2022-01-07 12:06:53 +03:00
$CC -B. -o $t/exe $t/c.o $t/b.so
$t/exe | grep -q hello
! readelf --symbols $t/exe | grep -q fn3 || false
2021-02-25 14:46:43 +03:00
2021-02-25 14:26:10 +03:00
echo OK