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-07-21 16:27:29 +09:00

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