From 9304f5414295bcebea3c8d0858e4038791bd762e Mon Sep 17 00:00:00 2001 From: wooster0 Date: Fri, 20 Dec 2024 14:14:38 +0900 Subject: [PATCH] linux: don't export getauxval when not required --- lib/std/os/linux.zig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index e9a84d806256..71eae33b42e3 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -475,22 +475,22 @@ pub const O = switch (native_arch) { /// Set by startup code, used by `getauxval`. pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; -const extern_getauxval = switch (builtin.zig_backend) { +/// Whether an external or internal getauxval implementation is used. +pub const extern_getauxval = switch (builtin.zig_backend) { // Calling extern functions is not yet supported with these backends .stage2_aarch64, .stage2_arm, .stage2_riscv64, .stage2_sparc64 => false, else => !builtin.link_libc, }; -comptime { - const root = @import("root"); - // Export this only when building executable, otherwise it is overriding - // the libc implementation - if (extern_getauxval and (builtin.output_mode == .Exe or @hasDecl(root, "main"))) { - @export(&getauxvalImpl, .{ .name = "getauxval", .linkage = .weak }); - } -} - pub const getauxval = if (extern_getauxval) struct { + comptime { + const root = @import("root"); + // Export this only when building executable, otherwise it is overriding + // the libc implementation + if (extern_getauxval and (builtin.output_mode == .Exe or @hasDecl(root, "main"))) { + @export(&getauxvalImpl, .{ .name = "getauxval", .linkage = .weak }); + } + } extern fn getauxval(index: usize) usize; }.getauxval else getauxvalImpl;