2021-06-16 11:18:19 +03:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
cd $(dirname $0)
|
2021-07-21 08:49:02 +03:00
|
|
|
mold=`pwd`/../mold
|
2021-06-16 11:18:19 +03:00
|
|
|
echo -n "Testing $(basename -s .sh $0) ... "
|
|
|
|
t=$(pwd)/tmp/$(basename -s .sh $0)
|
|
|
|
mkdir -p $t
|
|
|
|
|
2021-07-15 18:11:03 +03:00
|
|
|
# Skip if libc is musl because musl does not fully support GNU-style
|
|
|
|
# symbol versioning.
|
|
|
|
echo 'int main() {}' | cc -o $t/exe -xc -
|
|
|
|
ldd $t/exe | grep -q ld-musl && { echo OK; exit; }
|
|
|
|
|
2021-06-16 11:18:19 +03:00
|
|
|
cat <<EOF | cc -fPIC -c -o $t/a.o -xc -
|
|
|
|
int foo1() { return 1; }
|
|
|
|
int foo2() { return 2; }
|
|
|
|
int foo3() { return 3; }
|
|
|
|
|
|
|
|
__asm__(".symver foo1, foo@VER1");
|
|
|
|
__asm__(".symver foo2, foo@VER2");
|
|
|
|
__asm__(".symver foo3, foo@@VER3");
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo 'VER1 { local: *; }; VER2 { local: *; }; VER3 { local: *; };' > $t/b.ver
|
2021-07-19 18:21:12 +03:00
|
|
|
clang -fuse-ld=$mold -shared -o $t/c.so $t/a.o -Wl,--version-script=$t/b.ver
|
2021-06-16 11:18:19 +03:00
|
|
|
|
2021-08-23 07:44:38 +03:00
|
|
|
cat <<EOF | cc -c -o $t/d.o -xc -
|
|
|
|
int foo1();
|
|
|
|
int foo2();
|
|
|
|
|
|
|
|
__asm__(".symver foo1, foo@VER1");
|
|
|
|
__asm__(".symver foo2, foo@VER2");
|
|
|
|
|
|
|
|
int bar1() {
|
|
|
|
return foo1();
|
|
|
|
}
|
|
|
|
|
|
|
|
int bar2() {
|
|
|
|
return foo2();
|
|
|
|
}
|
2021-06-16 11:18:19 +03:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<EOF | cc -c -o $t/e.o -xc -
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int bar1();
|
|
|
|
int bar2();
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
printf("%d %d\n", bar1(), bar2());
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2021-07-19 18:21:12 +03:00
|
|
|
clang -fuse-ld=$mold -o $t/exe $t/d.o $t/e.o $t/c.so
|
2021-06-16 11:18:19 +03:00
|
|
|
$t/exe | grep -q '^1 2$'
|
|
|
|
|
|
|
|
echo OK
|