Hi Herman, Thank you for reporting these TLS issues.
I have pushed fixes to the mob branch. The latest follow-up commit is: 97a6d8c7 tls: fix local-exec addresses and external symbols Together with the recent TLS review changes already on mob, this addresses the reported points: 1. The unreachable i386 TLS store condition has been fixed, and an i386 Linux job is now present in the GitHub workflow. The follow-up commit also fixes preservation of nonzero offsets when materializing i386 TLS addresses. 2. TLS loads and stores now honor the actual object width. Test 144 covers char, short, integer, floating-point, pointer, enum and structure objects. I extended it further with signed and unsigned narrow types, address-taking, runtime array indexing, nonzero member offsets and per-thread address/value isolation. 3. Test 144 is skipped on OpenBSD, FreeBSD and NetBSD, where the TLS runtime support is not available. The new external TLS test is skipped there as well, and DragonFly is covered too. 4. The ARM64 mixed-declaration warning has been fixed. ARM64 now builds cleanly with -Wdeclaration-after-statement. During the review I found and fixed a few related cases: - ARM64 TLS addresses are now derived from the thread pointer instead of using ordinary GOT relocations. - RISC-V applies symbolic TLS offsets consistently to both TPREL relocations, including offsets larger than a 12-bit immediate. - Undefined TLS symbols in ELF objects retain STT_TLS, allowing TCC-generated objects to be linked correctly by GNU ld. - A new test 146 checks external TLS definitions through the system linker. I ran the complete test suite on x86-64, i386 and i386 PIE. I also validated tests 144 and 146 for ARM64 and RISC-V under QEMU, including linking the TCC-generated objects with GNU ld. No additional ARM64 or RISC-V GitHub CI jobs were introduced by this commit, the existing workflow entries were left unchanged. Regards, Mounir IDRASSI From: Herman ten Brugge via Tinycc-devel <[email protected]> To: "Herman ten Brugge via Tinycc-devel"<[email protected]> Cc: "Herman ten Brugge"<[email protected]> Date: Wed, 01 Jul 2026 18:37:04 +0900 Subject: [Tinycc-devel] Some TLS problems > I found some TLS problems: > > 1) The i386 target does not work. > > The store function has: > fr = v->r & VT_VALMASK; > ... > if ((fr & VT_SYM) && v->sym->type.t & VT_TLS) { > > The if statement if always false. > So the code is probably never tested? > > Perhaps we should add the i386 to .github/workflows/build.yml > > 2) The store/load tls code only support 32/64 bits types. > > I had code where a short was used. > This failed beause a 4 byte load/store was used. > > See attached adapted test case 144. > > 3) BSD does not support TLS code. > > The tests/tests2/Makefile should exclude test case 144 for: > OpenBSD FreeBSD NetBSD > > 4) warning: > > arm64-link.c: In function ‘relocate’: > arm64-link.c:384:13: warning: ISO C90 forbids mixed declarations and > code [-Wdeclaration-after-statement] > 384 | int64_t tp_offset = val - tls_start + 16; > > > Herman > _______________________________________________ > Tinycc-devel mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/tinycc-devel > _______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
