authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-19 11:28:03+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-05 03:26:41+02:00
logf0d0412942e52a38bcd4914a50f686f5a59ed37b
treea61f07dd076bcf57e6ab632dfed70ba1f39fcd7f
parent736d37ad161b255cf29fb3050026ad4852639b11
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler-rt: move some checks up to elf.zig


3 files changed, 37 insertions(+), 25 deletions(-)

lib/compiler_rt/elf.zig+21-2
......@@ -1,4 +1,23 @@
1const builtin = @import("builtin");
2const std = @import("std");
3
4const compiler_rt = @import("../compiler_rt.zig");
5const symbol = compiler_rt.symbol;
6
7/// More operating systems are expected to be added here:
8///
9/// * FreeBSD: https://codeberg.org/ziglang/zig/issues/30981
10/// * NetBSD: https://codeberg.org/ziglang/zig/issues/30980
11/// * OpenBSD: https://codeberg.org/ziglang/zig/issues/30982
12const use_zig_start = switch (builtin.target.os.tag) {
13 .linux,
14 => !builtin.link_libc,
15 else => false,
16};
17
118comptime {
2 _ = @import("elf/auxv.zig");
3 _ = @import("elf/tls.zig");
19 if (use_zig_start) {
20 _ = @import("elf/auxv.zig");
21 _ = @import("elf/tls.zig");
22 }
423}
lib/compiler_rt/elf/auxv.zig+1-4
......@@ -5,10 +5,7 @@ const compiler_rt = @import("../../compiler_rt.zig");
55const symbol = compiler_rt.symbol;
66
77comptime {
8 // FreeBSD, NetBSD, and OpenBSD are expected to also use this in the future.
9 if (!builtin.link_libc and builtin.target.os.tag == .linux) {
10 symbol(@ptrCast(&__zig_elf_auxv), "__zig_elf_auxv");
11 }
8 symbol(@ptrCast(&__zig_elf_auxv), "__zig_elf_auxv");
129}
1310
1411/// Populated by `std.start` when libc is not linked on targets that provide an ELF auxiliary vector
lib/compiler_rt/elf/tls.zig+15-19
......@@ -11,32 +11,28 @@
1111
1212const builtin = @import("builtin");
1313const std = @import("std");
14
15const compiler_rt = @import("../../compiler_rt.zig");
16const symbol = compiler_rt.symbol;
17
1814const elf = std.elf;
1915const assert = std.debug.assert;
2016const native_arch = builtin.cpu.arch;
2117const linux = std.os.linux;
2218const page_size_min = std.heap.page_size_min;
2319
20const compiler_rt = @import("../../compiler_rt.zig");
21const symbol = compiler_rt.symbol;
22
2423comptime {
25 // FreeBSD, NetBSD, and OpenBSD are expected to also use this in the future.
26 if (!builtin.link_libc and builtin.target.os.tag == .linux) {
27 symbol(&__zig_elf_static_tls, "__zig_elf_static_tls");
28 symbol(&__zig_elf_static_tls_init, "__zig_elf_static_tls_init");
29 symbol(&__zig_elf_static_tls_fill, "__zig_elf_static_tls_fill");
30
31 // To make static executables without libc work, it is our job to provide the TLS accessor
32 // function for the GD and LD models. This function is unlikely to actually be used, since
33 // the linker should be able to relax every TLS access to the LE model and therefore
34 // eliminate all calls to this function, but that isn't guaranteed.
35 if (native_arch == .s390x)
36 symbol(&__tls_get_offset, "__tls_get_offset")
37 else
38 symbol(&__tls_get_addr, "__tls_get_addr");
39 }
24 symbol(&__zig_elf_static_tls, "__zig_elf_static_tls");
25 symbol(&__zig_elf_static_tls_init, "__zig_elf_static_tls_init");
26 symbol(&__zig_elf_static_tls_fill, "__zig_elf_static_tls_fill");
27
28 // To make static executables without libc work, it is our job to provide the TLS accessor
29 // 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 all
31 // calls to this function, but that isn't guaranteed.
32 if (native_arch == .s390x)
33 symbol(&__tls_get_offset, "__tls_get_offset")
34 else
35 symbol(&__tls_get_addr, "__tls_get_addr");
4036}
4137
4238/// Represents an ELF TLS variant.