diff --git a/lib/compiler_rt/elf.zig b/lib/compiler_rt/elf.zig index 11f934d30edde31a6c5f4ec01092636fa602620c..713fe4845c9f77d1dcf7903a5b23b3a1484e7ed0 100644 --- a/lib/compiler_rt/elf.zig +++ b/lib/compiler_rt/elf.zig @@ -1,4 +1,23 @@ +const builtin = @import("builtin"); +const std = @import("std"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; + +/// More operating systems are expected to be added here: +/// +/// * FreeBSD: https://codeberg.org/ziglang/zig/issues/30981 +/// * NetBSD: https://codeberg.org/ziglang/zig/issues/30980 +/// * OpenBSD: https://codeberg.org/ziglang/zig/issues/30982 +const use_zig_start = switch (builtin.target.os.tag) { + .linux, + => !builtin.link_libc, + else => false, +}; + comptime { - _ = @import("elf/auxv.zig"); - _ = @import("elf/tls.zig"); + if (use_zig_start) { + _ = @import("elf/auxv.zig"); + _ = @import("elf/tls.zig"); + } } diff --git a/lib/compiler_rt/elf/auxv.zig b/lib/compiler_rt/elf/auxv.zig index de5a45e501b5850f8f25aa18ffec75ccf23927ac..e8452202a8b085144a08a925153271b94b39ad7f 100644 --- a/lib/compiler_rt/elf/auxv.zig +++ b/lib/compiler_rt/elf/auxv.zig @@ -5,10 +5,7 @@ const compiler_rt = @import("../../compiler_rt.zig"); const symbol = compiler_rt.symbol; comptime { - // FreeBSD, NetBSD, and OpenBSD are expected to also use this in the future. - if (!builtin.link_libc and builtin.target.os.tag == .linux) { - symbol(@ptrCast(&__zig_elf_auxv), "__zig_elf_auxv"); - } + symbol(@ptrCast(&__zig_elf_auxv), "__zig_elf_auxv"); } /// Populated by `std.start` when libc is not linked on targets that provide an ELF auxiliary vector diff --git a/lib/compiler_rt/elf/tls.zig b/lib/compiler_rt/elf/tls.zig index b4231387593edb88fdaff50d5d526b5eec5e3eda..75dda8d300ec7e079979528af638fdc3e8e90347 100644 --- a/lib/compiler_rt/elf/tls.zig +++ b/lib/compiler_rt/elf/tls.zig @@ -11,32 +11,28 @@ const builtin = @import("builtin"); const std = @import("std"); - -const compiler_rt = @import("../../compiler_rt.zig"); -const symbol = compiler_rt.symbol; - const elf = std.elf; const assert = std.debug.assert; const native_arch = builtin.cpu.arch; const linux = std.os.linux; const page_size_min = std.heap.page_size_min; +const compiler_rt = @import("../../compiler_rt.zig"); +const symbol = compiler_rt.symbol; + comptime { - // FreeBSD, NetBSD, and OpenBSD are expected to also use this in the future. - if (!builtin.link_libc and builtin.target.os.tag == .linux) { - symbol(&__zig_elf_static_tls, "__zig_elf_static_tls"); - symbol(&__zig_elf_static_tls_init, "__zig_elf_static_tls_init"); - symbol(&__zig_elf_static_tls_fill, "__zig_elf_static_tls_fill"); + symbol(&__zig_elf_static_tls, "__zig_elf_static_tls"); + symbol(&__zig_elf_static_tls_init, "__zig_elf_static_tls_init"); + symbol(&__zig_elf_static_tls_fill, "__zig_elf_static_tls_fill"); - // To make static executables without libc work, it is our job to provide the TLS accessor - // function for the GD and LD models. This function is unlikely to actually be used, since - // the linker should be able to relax every TLS access to the LE model and therefore - // eliminate all calls to this function, but that isn't guaranteed. - if (native_arch == .s390x) - symbol(&__tls_get_offset, "__tls_get_offset") - else - symbol(&__tls_get_addr, "__tls_get_addr"); - } + // To make static executables without libc work, it is our job to provide the TLS accessor + // function for the GD and LD models. This function is unlikely to actually be used, since the + // linker should be able to relax every TLS access to the LE model and therefore eliminate all + // calls to this function, but that isn't guaranteed. + if (native_arch == .s390x) + symbol(&__tls_get_offset, "__tls_get_offset") + else + symbol(&__tls_get_addr, "__tls_get_addr"); } /// Represents an ELF TLS variant.