1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-15 14:36:25 +03:00
mold/test/weak-export2.sh
Rui Ueyama 34558f410d Do not generate dynrels against RO sections for weak undef symbols
Previously, we created dynamic relocations against read-only sections
if the sections contain relocations against weak undefined symbols.
Since such dynamic relocations cannot be applied at load-time, the
generated executables failed with SEGV.

Now, such relocations are resolved to address 0.

Reported at https://github.com/rui314/mold/pull/110
2021-08-17 17:23:22 +09:00

37 lines
664 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)) extern int foo;
static int * const bar[] = {&foo};
int main() {
printf("%d\n", bar[0] ? *bar[0] : 3);
}
EOF
cc -c -o $t/b.o $t/a.c -fno-PIC
cc -c -o $t/c.o $t/a.c -fPIC
clang -fuse-ld=$mold -no-pie -o $t/exe1 $t/b.o
clang -fuse-ld=$mold -no-pie -o $t/exe2 $t/c.o
$t/exe1 | grep -q 3
$t/exe2 | grep -q 3
cat <<EOF | cc -shared -o $t/d.so -xc -
int foo = 7;
EOF
LD_PRELOAD=$t/d.so $t/exe1 | grep -q 3
LD_PRELOAD=$t/d.so $t/exe2 | grep -q 7
echo OK