From 0c355bef9e424fbf06085f12fc28979d73b3d6af Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 18 Oct 2020 21:54:24 +0200 Subject: [PATCH] std: Slim down the error code path in initStaticTLS Calling @panic made the executable ~30x times bigger, use a simple `abort()` and let the user figure out what went wrong. Supporting ARMv6 (and earlier?) platforms is not a priority. Closes #6676 --- lib/std/os/linux/tls.zig | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index 0330a4e410..69e7816f13 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -211,12 +211,16 @@ fn initTLS() void { } } - // If the cpu is ARM-based, check if it supports the TLS register - if (comptime builtin.arch.isARM() and at_hwcap & std.os.linux.HWCAP_TLS == 0) { - // If the CPU does not support TLS via a coprocessor register, - // a kernel helper function can be used instead on certain linux kernels. - // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c. - @panic("TODO: Implement ARM fallback TLS functionality"); + // ARMv6 targets (and earlier) have no support for TLS in hardware + // FIXME: Elide the check for targets >= ARMv7 when the target feature API + // becomes less verbose (and more usable). + if (comptime builtin.arch.isARM()) { + if (at_hwcap & std.os.linux.HWCAP_TLS == 0) { + // FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls + // For the time being use a simple abort instead of a @panic call to + // keep the binary bloat under control. + std.os.abort(); + } } var tls_align_factor: usize = undefined;