2021-03-08 09:25:23 +03:00
|
|
|
#!/bin/bash
|
2021-12-17 14:05:14 +03:00
|
|
|
export LANG=
|
2021-03-08 09:25:23 +03:00
|
|
|
set -e
|
2022-01-07 06:51:36 +03:00
|
|
|
CC="${CC:-cc}"
|
|
|
|
CXX="${CXX:-c++}"
|
2021-12-30 05:11:06 +03:00
|
|
|
testname=$(basename -s .sh "$0")
|
|
|
|
echo -n "Testing $testname ... "
|
|
|
|
cd "$(dirname "$0")"/../..
|
|
|
|
mold="$(pwd)/mold"
|
|
|
|
t="$(pwd)/out/test/elf/$testname"
|
2021-12-22 13:38:00 +03:00
|
|
|
mkdir -p "$t"
|
2021-03-08 09:25:23 +03:00
|
|
|
|
2022-01-07 06:51:36 +03:00
|
|
|
cat <<EOF | $CC -fPIC -xc -c -o "$t"/a.o -
|
2021-08-23 07:44:38 +03:00
|
|
|
int foo() {
|
|
|
|
return 3;
|
|
|
|
}
|
2021-03-08 09:25:23 +03:00
|
|
|
EOF
|
|
|
|
|
2022-01-07 06:51:36 +03:00
|
|
|
cat <<EOF | $CC -fPIC -xc -c -o "$t"/b.o -
|
2021-08-23 07:44:38 +03:00
|
|
|
int bar() {
|
|
|
|
return 5;
|
|
|
|
}
|
2021-03-08 09:25:23 +03:00
|
|
|
EOF
|
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
rm -f "$t"/c.a
|
|
|
|
ar crs "$t"/c.a "$t"/a.o
|
2021-03-08 09:25:23 +03:00
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
rm -f "$t"/d.a
|
|
|
|
ar crs "$t"/d.a "$t"/b.o
|
2021-03-08 09:25:23 +03:00
|
|
|
|
2022-01-07 06:51:36 +03:00
|
|
|
cat <<EOF | $CC -fPIC -xc -c -o "$t"/e.o -
|
2021-03-08 09:25:23 +03:00
|
|
|
int foo();
|
|
|
|
int bar();
|
|
|
|
|
|
|
|
int baz() {
|
|
|
|
foo();
|
|
|
|
bar();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2022-01-07 06:51:36 +03:00
|
|
|
$CC -B. -shared -o "$t"/f.so "$t"/e.o "$t"/c.a "$t"/d.a
|
2021-12-22 13:38:00 +03:00
|
|
|
readelf --dyn-syms "$t"/f.so > "$t"/log
|
|
|
|
fgrep -q foo "$t"/log
|
|
|
|
fgrep -q bar "$t"/log
|
|
|
|
fgrep -q baz "$t"/log
|
|
|
|
|
2022-01-07 06:51:36 +03:00
|
|
|
$CC -B. -shared -o "$t"/f.so "$t"/e.o "$t"/c.a "$t"/d.a -Wl,-exclude-libs=c.a
|
2021-12-22 13:38:00 +03:00
|
|
|
readelf --dyn-syms "$t"/f.so > "$t"/log
|
|
|
|
! fgrep -q foo "$t"/log || false
|
|
|
|
fgrep -q bar "$t"/log
|
|
|
|
fgrep -q baz "$t"/log
|
|
|
|
|
2022-01-07 06:51:36 +03:00
|
|
|
$CC -B. -shared -o "$t"/f.so "$t"/e.o "$t"/c.a "$t"/d.a -Wl,-exclude-libs=c.a -Wl,-exclude-libs=d.a
|
2021-12-22 13:38:00 +03:00
|
|
|
readelf --dyn-syms "$t"/f.so > "$t"/log
|
|
|
|
! fgrep -q foo "$t"/log || false
|
|
|
|
! fgrep -q bar "$t"/log || false
|
|
|
|
fgrep -q baz "$t"/log
|
|
|
|
|
2022-01-07 06:51:36 +03:00
|
|
|
$CC -B. -shared -o "$t"/f.so "$t"/e.o "$t"/c.a "$t"/d.a -Wl,-exclude-libs=ALL
|
2021-12-22 13:38:00 +03:00
|
|
|
readelf --dyn-syms "$t"/f.so > "$t"/log
|
|
|
|
! fgrep -q foo "$t"/log || false
|
|
|
|
! fgrep -q bar "$t"/log || false
|
|
|
|
fgrep -q baz "$t"/log
|
2021-03-08 09:25:23 +03:00
|
|
|
|
|
|
|
echo OK
|