1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
mold/test/elf/tls-ie.sh
Rui Ueyama d1161137d9 [ELF] Fix Initial-Exec TLS variables
Previously, GOTTPOFF relocations against Initial-Exec TLS variables
got wrong value.

Fixes https://github.com/rui314/mold/issues/197
2021-12-26 20:51:37 +09:00

61 lines
989 B
Bash
Executable File

#!/bin/bash
export LANG=
set -e
cd $(dirname $0)
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
if [ $(uname -m) = x86_64 ]; then
dialect=gnu
elif [ $(uname -m) = aarch64 ]; then
dialect=trad
else
echo skipped
exit 0
fi
cat <<EOF | gcc -ftls-model=initial-exec -mtls-dialect=$dialect -fPIC -c -o $t/a.o -xc -
#include <stdio.h>
static _Thread_local int foo;
static _Thread_local int bar;
void set() {
foo = 3;
bar = 5;
}
void print() {
printf("%d %d ", foo, bar);
}
EOF
clang -fuse-ld=$mold -shared -o $t/b.so $t/a.o
cat <<EOF | gcc -c -o $t/c.o -xc -
#include <stdio.h>
_Thread_local int baz;
void set();
void print();
int main() {
baz = 7;
print();
set();
print();
printf("%d\n", baz);
}
EOF
clang -fuse-ld=$mold -o $t/exe $t/b.so $t/c.o
$t/exe | grep -q '^0 0 3 5 7$'
clang -fuse-ld=$mold -o $t/exe $t/b.so $t/c.o -Wl,-no-relax
$t/exe | grep -q '^0 0 3 5 7$'
echo OK