authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-11 09:18:36+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-11 10:10:15+02:00
logdae7c7c466500733ef74c72874e7755cc3f218b1
tree9ebe30e5db3e2475e88db5f0706e466b2ed1737a
parentc692aced232da210469b2c04270edc5a980b72d7
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler_rt.elf.tls: add ___tls_get_addr() which is used by 32-bit x86

As per usual, we have GNU to thank.

1 files changed, 19 insertions(+), 3 deletions(-)

lib/compiler_rt/elf/tls.zig+19-3
...@@ -29,10 +29,14 @@ comptime {...@@ -29,10 +29,14 @@ comptime {
29 // function for the GD and LD models. This function is unlikely to actually be used, since the29 // function for the GD and LD models. This function is unlikely to actually be used, since the
30 // linker should be able to relax every TLS access to the LE model and therefore eliminate all30 // linker should be able to relax every TLS access to the LE model and therefore eliminate all
31 // calls to this function, but that isn't guaranteed.31 // calls to this function, but that isn't guaranteed.
32 if (native_arch == .s390x)32 if (native_arch == .s390x) {
33 symbol(&__tls_get_offset, "__tls_get_offset")33 symbol(&__tls_get_offset, "__tls_get_offset");
34 else34 } else {
35 symbol(&__tls_get_addr, "__tls_get_addr");35 symbol(&__tls_get_addr, "__tls_get_addr");
36 if (native_arch == .x86) {
37 symbol(&___tls_get_addr, "___tls_get_addr");
38 }
39 }
36}40}
3741
38/// Represents an ELF TLS variant.42/// Represents an ELF TLS variant.
...@@ -740,6 +744,18 @@ fn __tls_get_addr(ti: *const TlsIndex) callconv(.c) *anyopaque {...@@ -740,6 +744,18 @@ fn __tls_get_addr(ti: *const TlsIndex) callconv(.c) *anyopaque {
740 return block[@intCast(ti.offset)..];744 return block[@intCast(ti.offset)..];
741}745}
742746
747fn ___tls_get_addr() callconv(.naked) *anyopaque {
748 comptime assert(native_arch == .x86);
749
750 // We receive the `TlsIndex` pointer in eax.
751 comptime assert(@sizeOf(AbiTcb) + @sizeOf(ZigTcb) + @offsetOf(Dtv, "tls_block") == 12);
752 asm volatile (
753 \\ mov 4(%%eax), %%eax
754 \\ add %%gs:12, %%eax
755 \\ ret
756 );
757}
758
743fn __tls_get_offset() callconv(.naked) noreturn {759fn __tls_get_offset() callconv(.naked) noreturn {
744 comptime assert(native_arch == .s390x);760 comptime assert(native_arch == .s390x);
745761