History

Some more TLS changes

tccgen.c: remove VT_TLS in gen_cast libtcc.c: remove warning for gcc 16 i386-gen.c: fix gen_modrm for VT_LDOUBLE riscv64-gen.c: add fc to TLS address x86_64-gen.c: add TLS prefix in gen_opf tests2/144_tls.c/tests2/144_tls.expect: updated test case tests/tests2/Makefile skip TLS test for BSD

herman ten brugge committed 4 months ago

Commit 04206d21 parent b895aa78 files · +120 −31Browse files

Unified · Split

8 files
  1. i386-gen.c +2 −0
  2. libtcc.c +1 −1
  3. riscv64-gen.c +2 −0
  4. tccgen.c +1 −1
  5. tests/tests2/144_tls.c +65 −28
  6. tests/tests2/144_tls.expect +45 −1
  7. tests/tests2/Makefile +1 −0
  8. x86_64-gen.c +3 −0
i386-gen.c+2−0
@@ -242,6 +242,8 @@ static void gen_modrm(int opc, int op_r2, int r, Sym *sym, int c) · 241 unmodified lines
242 int op_reg = REG_VALUE(op_r2) << 3;242 int op_reg = REG_VALUE(op_r2) << 3;
243 243
244 if ((r & VT_SYM) && (sym->type.t & VT_TLS)) {244 if ((r & VT_SYM) && (sym->type.t & VT_TLS)) {
245 if (opc == 0xdbc0d9) // VT_LDOUBLE
246 o(0xc0d9), opc = 0xdb;
245 o(0x65); /* gs segment prefix */247 o(0x65); /* gs segment prefix */
246 o(opc);248 o(opc);
247 oad(0x05 | op_reg, c);249 oad(0x05 | op_reg, c);
libtcc.c+1−1
@@ -194,7 +194,7 @@ ST_FUNC char *pstrncpy(char *out, size_t buf_size, const char *s, size_t num) · 193 unmodified lines
194/* extract the basename of a file */194/* extract the basename of a file */
195PUB_FUNC char *tcc_basename(const char *name)195PUB_FUNC char *tcc_basename(const char *name)
196{196{
197 char *p = strchr(name, 0);197 char *p = (char *)strchr(name, 0);
198 while (p > name && !IS_DIRSEP(p[-1]))198 while (p > name && !IS_DIRSEP(p[-1]))
199 --p;199 --p;
200 return p;200 return p;
riscv64-gen.c+2−0
@@ -188,6 +188,8 @@ static int load_symofs(int r, SValue *sv, int forstore, int *new_fc) · 187 unmodified lines
188 greloca(cur_text_section, sv->sym, ind,188 greloca(cur_text_section, sv->sym, ind,
189 R_RISCV_TPREL_LO12_I, 0);189 R_RISCV_TPREL_LO12_I, 0);
190 EI(0x13, 0, rr, rr, 0); // addi RR, RR, 0 %tprel_lo(sym)190 EI(0x13, 0, rr, rr, 0); // addi RR, RR, 0 %tprel_lo(sym)
191 if (fc)
192 EI(0x13, 0, rr, rr, fc); // addi RR, RR, fc
191 ER(0x33, 0, rr, rr, 4, 0); // add RR, RR, tp193 ER(0x33, 0, rr, rr, 4, 0); // add RR, RR, tp
192 *new_fc = 0;194 *new_fc = 0;
193 return rr;195 return rr;
tccgen.c+1−1
@@ -3487,7 +3487,7 @@ error: · 3486 unmodified lines
3487 }3487 }
3488done:3488done:
3489 vtop->type = *type;3489 vtop->type = *type;
3490 vtop->type.t &= ~ ( VT_CONSTANT | VT_VOLATILE | VT_ARRAY );3490 vtop->type.t &= ~ ( VT_CONSTANT | VT_VOLATILE | VT_ARRAY | VT_TLS );
3491}3491}
3492 3492
3493/* return type size as known at compile time. Put alignment at 'a' */3493/* return type size as known at compile time. Put alignment at 'a' */
tests/tests2/144_tls.c+65−28
@@ -1,50 +1,87 @@
1#include <stdio.h>1#include <stdio.h>
2#include <pthread.h>2#include <pthread.h>
3 3
4__thread int tls_init = 42;4#define CHECK(var,fmt,val) printf(fmt "\n",var); if (var != val) errors = 1
5
6typedef enum { tls_a, tls_b, tls_c } tls_enum_type;
7typedef struct { int tls_d, tls_e, tls_f; } tls_struct_type;
8
9__thread char tls_char = 42;
10__thread short tls_short = 43;
11__thread int tls_init = 44;
12__thread long long tls_long_long = 45;
5__thread int tls_zero;13__thread int tls_zero;
14__thread float tls_float = 46.0;
15__thread double tls_double = 47.0;
16__thread long double tls_long_double = 48.0;
17__thread int *tls_ptr = (int *)49;
18__thread tls_enum_type tls_enum = tls_b;
19__thread tls_struct_type tls_struct = { 50, 51, 52 };
6 20
7static void *thread_func(void *arg)21static int check(void)
8{22{
9 (void)arg;23 int errors = 0;
10 24
11 printf("%d\n", tls_init);25 CHECK(tls_char, "%d", 42);
12 if (tls_init != 42) return (void *)1;26 CHECK(tls_short, "%d", 43);
27 CHECK(tls_init, "%d", 44);
28 CHECK(tls_long_long, "%lld", 45);
29 CHECK(tls_zero, "%d", 0);
30 CHECK(tls_float, "%g", 46.0);
31 CHECK(tls_double, "%g", 47.0);
32 CHECK(tls_long_double, "%Lg", 48.0);
33 CHECK(tls_ptr, "%p", (int *)49);
34 CHECK(tls_enum, "%d", tls_b);
35 CHECK(tls_struct.tls_d, "%d", 50);
36 CHECK(tls_struct.tls_e, "%d", 51);
37 CHECK(tls_struct.tls_f, "%d", 52);
38 return errors;
39}
13 40
14 printf("%d\n", tls_zero);41static void *thread_func(void *arg)
15 if (tls_zero != 0) return (void *)1;42{
43 (void)arg;
44 long errors = check();
16 45
17 tls_init = 100;46 tls_char = 10;
18 tls_zero = 200;47 tls_short = 20;
48 tls_init = 30;
49 tls_long_long = 40;
50 tls_zero = 50;
51 tls_float = 60.0;
52 tls_double = 70.0;
53 tls_long_double = 80.0;
54 tls_ptr = (int *)90;
55 tls_enum = tls_c;
56 tls_struct.tls_d = 100;
57 tls_struct.tls_e = 110;
58 tls_struct.tls_f = 120;
19 59
20 printf("%d\n", tls_init);60 CHECK(tls_char, "%d", 10);
21 printf("%d\n", tls_zero);61 CHECK(tls_short, "%d", 20);
62 CHECK(tls_init, "%d", 30);
63 CHECK(tls_long_long, "%lld", 40);
64 CHECK(tls_zero, "%d", 50);
65 CHECK(tls_float, "%g", 60.0);
66 CHECK(tls_double, "%g", 70.0);
67 CHECK(tls_long_double, "%Lg", 80.0);
68 CHECK(tls_enum, "%d", tls_c);
69 CHECK(tls_ptr, "%p", (int *)90);
70 CHECK(tls_struct.tls_d, "%d", 100);
71 CHECK(tls_struct.tls_e, "%d", 110);
72 CHECK(tls_struct.tls_f, "%d", 120);
22 73
23 return (void *)0;74 return (void *)errors;
24}75}
25 76
26int main()77int main()
27{78{
28 pthread_t t;79 pthread_t t;
29 void *ret;80 void *ret;
30 int errors = 0;81 int errors = check();
31
32 printf("%d\n", tls_init);
33 if (tls_init != 42) errors = 1;
34
35 printf("%d\n", tls_zero);
36 if (tls_zero != 0) errors = 1;
37 82
38 pthread_create(&t, NULL, thread_func, NULL);83 pthread_create(&t, NULL, thread_func, NULL);
39 pthread_join(t, &ret);84 pthread_join(t, &ret);
40 85
41 if (ret) errors = 1;86 return (ret ? 1 : 0) | errors | check();
42
43 printf("%d\n", tls_init);
44 if (tls_init != 42) errors = 1;
45
46 printf("%d\n", tls_zero);
47 if (tls_zero != 0) errors = 1;
48
49 return errors;
50}87}
tests/tests2/144_tls.expect+45−1
@@ -1,8 +1,52 @@
142142
243
344
445
2050
646
747
848
90x31
101
1150
1251
1352
3421442
1543
1644
1745
40180
1946
2047
2148
220x31
231
2450
2551
2652
2710
2820
2930
3040
3150
3260
3370
3480
352
360x5a
510037100
620038110
39120
7424042
4143
4244
4345
80440
4546
4647
4748
480x31
491
5050
5151
5252
tests/tests2/Makefile+1−0
@@ -53,6 +53,7 @@ ifneq (,$(filter OpenBSD FreeBSD NetBSD,$(TARGETOS))) · 52 unmodified lines
53 SKIP += 106_versym.test # no pthread_condattr_setpshared53 SKIP += 106_versym.test # no pthread_condattr_setpshared
54 SKIP += 114_bound_signal.test # libc problem signal/fork54 SKIP += 114_bound_signal.test # libc problem signal/fork
55 SKIP += 116_bound_setjmp2.test # No TLS_FUNC/TLS_VAR in bcheck.c55 SKIP += 116_bound_setjmp2.test # No TLS_FUNC/TLS_VAR in bcheck.c
56 SKIP += 144_tls.test # No tls support
56endif57endif
57ifeq ($(CONFIG_OSX),yes)58ifeq ($(CONFIG_OSX),yes)
58 SKIP += 144_tls.test # TLS runtime not supported on Mach-O59 SKIP += 144_tls.test # TLS runtime not supported on Mach-O
x86_64-gen.c+3−0
@@ -1932,6 +1932,9 @@ void gen_opf(int op) · 1931 unmodified lines
1932 }1932 }
1933 assert(!(vtop[-1].r & VT_LVAL));1933 assert(!(vtop[-1].r & VT_LVAL));
1934 1934
1935 if ((vtop->r & VT_SYM) && (vtop->sym->type.t & VT_TLS))
1936 o(0x64); /* fs segment prefix */
1937
1935 if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)1938 if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)
1936 o(0x66);1939 o(0x66);
1937 if (op == TOK_EQ || op == TOK_NE)1940 if (op == TOK_EQ || op == TOK_NE)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t