Skip to content

Commit 0e8f130

Browse files
authored
Merge pull request #16977 from kcbanner/lib_getauxval_fixup
linux: export getauxval when not compiling with libc
2 parents ec5a068 + 2e2d6d2 commit 0e8f130

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/std/os/linux.zig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,22 @@ pub usingnamespace @import("linux/io_uring.zig");
154154
/// Set by startup code, used by `getauxval`.
155155
pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
156156

157-
/// See `std.elf` for the constants.
158-
pub fn getauxval(index: usize) usize {
157+
pub usingnamespace if (switch (builtin.zig_backend) {
158+
// Calling extern functions is not yet supported with these backends
159+
.stage2_x86_64, .stage2_aarch64, .stage2_arm, .stage2_riscv64, .stage2_sparc64 => false,
160+
else => !builtin.link_libc,
161+
}) struct {
162+
/// See `std.elf` for the constants.
163+
/// This matches the libc getauxval function.
164+
pub extern fn getauxval(index: usize) usize;
165+
comptime {
166+
@export(getauxvalImpl, .{ .name = "getauxval", .linkage = .Weak });
167+
}
168+
} else struct {
169+
pub const getauxval = getauxvalImpl;
170+
};
171+
172+
fn getauxvalImpl(index: usize) callconv(.C) usize {
159173
const auxv = elf_aux_maybe orelse return 0;
160174
var i: usize = 0;
161175
while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {

0 commit comments

Comments
 (0)