2021-04-13 15:06:21 +03:00
|
|
|
#!/bin/bash
|
2021-12-17 14:05:14 +03:00
|
|
|
export LANG=
|
2021-04-13 15:06:21 +03:00
|
|
|
set -e
|
2021-12-30 05:11:06 +03:00
|
|
|
testname=$(basename -s .sh "$0")
|
|
|
|
echo -n "Testing $testname ... "
|
|
|
|
cd "$(dirname "$0")"/../..
|
|
|
|
mold="$(pwd)/mold"
|
|
|
|
t="$(pwd)/out/test/elf/$testname"
|
2021-12-22 13:38:00 +03:00
|
|
|
mkdir -p "$t"
|
2021-04-13 15:06:21 +03:00
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
echo 'int main() {}' | cc -m32 -o "$t"/exe -xc - >& /dev/null \
|
2021-07-16 19:22:10 +03:00
|
|
|
|| { echo skipped; exit; }
|
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
cat <<EOF | cc -ftls-model=local-dynamic -fPIC -c -o "$t"/a.o -xc - -m32
|
2021-04-13 15:06:21 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
extern _Thread_local int foo;
|
|
|
|
static _Thread_local int bar;
|
|
|
|
|
|
|
|
int *get_foo_addr() { return &foo; }
|
|
|
|
int *get_bar_addr() { return &bar; }
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
bar = 5;
|
|
|
|
|
|
|
|
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
cat <<EOF | cc -ftls-model=local-dynamic -fPIC -c -o "$t"/b.o -xc - -m32
|
2021-04-13 15:06:21 +03:00
|
|
|
_Thread_local int foo = 3;
|
|
|
|
EOF
|
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.o "$t"/b.o -m32
|
|
|
|
"$t"/exe | grep -q '3 5 3 5'
|
2021-04-13 15:06:21 +03:00
|
|
|
|
2021-12-22 13:38:00 +03:00
|
|
|
clang -fuse-ld="$mold" -o "$t"/exe "$t"/a.o "$t"/b.o -Wl,-no-relax -m32
|
|
|
|
"$t"/exe | grep -q '3 5 3 5'
|
2021-04-13 15:06:21 +03:00
|
|
|
|
|
|
|
echo OK
|