1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-15 14:36:25 +03:00
mold/test/weak-export.sh
2021-08-28 20:47:45 +09:00

39 lines
740 B
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
cat <<EOF | cc -fPIC -c -o $t/a.o -xc -
#include <stdio.h>
__attribute__((weak)) int foo();
__attribute__((weak)) int bar();
int main() {
printf("%d %d\n", foo ? foo() : 3, &bar ? bar() : 5);
}
EOF
cat <<EOF | cc -shared -fPIC -o $t/b.so -xc -
int foo() {
return 42;
}
EOF
clang -fuse-ld=$mold -o $t/exe $t/a.o $t/b.so
readelf --dyn-syms $t/exe | grep -q 'FUNC WEAK DEFAULT UND foo'
! readelf --dyn-syms $t/exe | grep -q 'FUNC WEAK DEFAULT UND bar' || false
$t/exe | grep -q '^42 5$'
cat <<EOF | cc -shared -fPIC -o $t/b.so -xc -
EOF
$t/exe | grep -q '^3 5$'
echo OK