| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | . $(dirnamescip-shell system . . dirname. $0)/common.inc |
| 3 | |
| 4 | catscip-shell system . . cat. <<EOF | $CC -fPIC -fno-plt -c -o $t/a.o -xc - |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | __attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; |
| 8 | __attribute__((tls_model("global-dynamic"))) static _Thread_local int x2; |
| 9 | __attribute__((tls_model("global-dynamic"))) extern _Thread_local int x3; |
| 10 | __attribute__((tls_model("global-dynamic"))) extern _Thread_local int x4; |
| 11 | int get_x5(); |
| 12 | int get_x6(); |
| 13 | |
| 14 | int main() { |
| 15 | x2 = 2; |
| 16 | |
| 17 | printf("%d %d %d %d %d %d\n", x1, x2, x3, x4, get_x5(), get_x6()); |
| 18 | return 0; |
| 19 | } |
| 20 | EOF |
| 21 | |
| 22 | catscip-shell system . . cat. <<EOF | $CC -fPIC -fno-plt -c -o $t/b.o -xc - |
| 23 | __attribute__((tls_model("global-dynamic"))) _Thread_local int x3 = 3; |
| 24 | __attribute__((tls_model("global-dynamic"))) static _Thread_local int x5 = 5; |
| 25 | int get_x5() { return x5; } |
| 26 | EOF |
| 27 | |
| 28 | catscip-shell system . . cat. <<EOF | $CC -fPIC -fno-plt -c -o $t/c.o -xc - |
| 29 | __attribute__((tls_model("global-dynamic"))) _Thread_local int x4 = 4; |
| 30 | __attribute__((tls_model("global-dynamic"))) static _Thread_local int x6 = 6; |
| 31 | int get_x6() { return x6; } |
| 32 | EOF |
| 33 | |
| 34 | $CC -B. -shared -o $t/d.so $t/b.o |
| 35 | $CC -B. -shared -o $t/e.so $t/c.o -Wl,--no-relax |
| 36 | |
| 37 | $CC -B. -o $t/exe $t/a.o $t/d.so $t/e.so |
| 38 | $QEMU $t/exe | grepscip-shell system . . grep. '1 2 3 4 5 6' |
| 39 | |
| 40 | $CC -B. -o $t/exe $t/a.o $t/d.so $t/e.so -Wl,-no-relax |
| 41 | $QEMU $t/exe | grepscip-shell system . . grep. '1 2 3 4 5 6' |