authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-04 09:11:15+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-09-04 09:11:15+02:00
log0e8f130aedce1e17299a8505bf997ae06e83b334
treee081912815e652b9d966bbef7f38c697b8cdc582
parentec5a068ac133d01477da340fc34cd987a817300d
parent2e2d6d2c3dcaccb101c97cf81e7a5f2afdf1ed49
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16977 from kcbanner/lib_getauxval_fixup

linux: export getauxval when not compiling with libc

1 files changed, 16 insertions(+), 2 deletions(-)

lib/std/os/linux.zig+16-2
...@@ -154,8 +154,22 @@ pub usingnamespace @import("linux/io_uring.zig");...@@ -154,8 +154,22 @@ pub usingnamespace @import("linux/io_uring.zig");
154/// Set by startup code, used by `getauxval`.154/// Set by startup code, used by `getauxval`.
155pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;155pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
156156
157/// See `std.elf` for the constants.157pub usingnamespace if (switch (builtin.zig_backend) {
158pub fn getauxval(index: usize) usize {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
172fn getauxvalImpl(index: usize) callconv(.C) usize {
159 const auxv = elf_aux_maybe orelse return 0;173 const auxv = elf_aux_maybe orelse return 0;
160 var i: usize = 0;174 var i: usize = 0;
161 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {175 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {