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 @@...@@ -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
1comptime {18comptime {
2 _ = @import("elf/auxv.zig");19 if (use_zig_start) {
3 _ = @import("elf/tls.zig");20 _ = @import("elf/auxv.zig");
21 _ = @import("elf/tls.zig");
22 }
4}23}
lib/compiler_rt/elf/auxv.zig+1-4
...@@ -5,10 +5,7 @@ const compiler_rt = @import("../../compiler_rt.zig");...@@ -5,10 +5,7 @@ const compiler_rt = @import("../../compiler_rt.zig");
5const symbol = compiler_rt.symbol;5const symbol = compiler_rt.symbol;
66
7comptime {7comptime {
8 // FreeBSD, NetBSD, and OpenBSD are expected to also use this in the future.8 symbol(@ptrCast(&__zig_elf_auxv), "__zig_elf_auxv");
9 if (!builtin.link_libc and builtin.target.os.tag == .linux) {
10 symbol(@ptrCast(&__zig_elf_auxv), "__zig_elf_auxv");
11 }
12}9}
1310
14/// Populated by `std.start` when libc is not linked on targets that provide an ELF auxiliary vector11/// 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 @@...@@ -11,32 +11,28 @@
1111
12const builtin = @import("builtin");12const builtin = @import("builtin");
13const std = @import("std");13const std = @import("std");
14
15const compiler_rt = @import("../../compiler_rt.zig");
16const symbol = compiler_rt.symbol;
17
18const elf = std.elf;14const elf = std.elf;
19const assert = std.debug.assert;15const assert = std.debug.assert;
20const native_arch = builtin.cpu.arch;16const native_arch = builtin.cpu.arch;
21const linux = std.os.linux;17const linux = std.os.linux;
22const page_size_min = std.heap.page_size_min;18const page_size_min = std.heap.page_size_min;
2319
20const compiler_rt = @import("../../compiler_rt.zig");
21const symbol = compiler_rt.symbol;
22
24comptime {23comptime {
25 // FreeBSD, NetBSD, and OpenBSD are expected to also use this in the future.24 symbol(&__zig_elf_static_tls, "__zig_elf_static_tls");
26 if (!builtin.link_libc and builtin.target.os.tag == .linux) {25 symbol(&__zig_elf_static_tls_init, "__zig_elf_static_tls_init");
27 symbol(&__zig_elf_static_tls, "__zig_elf_static_tls");26 symbol(&__zig_elf_static_tls_fill, "__zig_elf_static_tls_fill");
28 symbol(&__zig_elf_static_tls_init, "__zig_elf_static_tls_init");27
29 symbol(&__zig_elf_static_tls_fill, "__zig_elf_static_tls_fill");28 // To make static executables without libc work, it is our job to provide the TLS accessor
3029 // function for the GD and LD models. This function is unlikely to actually be used, since the
31 // To make static executables without libc work, it is our job to provide the TLS accessor30 // linker should be able to relax every TLS access to the LE model and therefore eliminate all
32 // function for the GD and LD models. This function is unlikely to actually be used, since31 // calls to this function, but that isn't guaranteed.
33 // the linker should be able to relax every TLS access to the LE model and therefore32 if (native_arch == .s390x)
34 // eliminate all calls to this function, but that isn't guaranteed.33 symbol(&__tls_get_offset, "__tls_get_offset")
35 if (native_arch == .s390x)34 else
36 symbol(&__tls_get_offset, "__tls_get_offset")35 symbol(&__tls_get_addr, "__tls_get_addr");
37 else
38 symbol(&__tls_get_addr, "__tls_get_addr");
39 }
40}36}
4137
42/// Represents an ELF TLS variant.38/// Represents an ELF TLS variant.