1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-15 14:36:25 +03:00
mold/test/versioned-undef.sh
2021-07-21 16:27:29 +09:00

52 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
set -e
cd $(dirname $0)
mold=`pwd`/../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t
# 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; }
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
clang -fuse-ld=$mold -shared -o $t/c.so $t/a.o -Wl,--version-script=$t/b.ver
cat <<EOF | cc -c -o $t/d.o -x assembler -
.globl bar1, bar2, bar3
bar1:
call "foo@VER1"
ret
bar2:
call "foo@VER2"
ret
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
clang -fuse-ld=$mold -o $t/exe $t/d.o $t/e.o $t/c.so
$t/exe | grep -q '^1 2$'
echo OK