aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/linux.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-09-04 09:11:15 +0200
committerGitHub <noreply@github.com>2023-09-04 09:11:15 +0200
commit0e8f130aedce1e17299a8505bf997ae06e83b334 (patch)
treee081912815e652b9d966bbef7f38c697b8cdc582 /lib/std/os/linux.zig
parentec5a068ac133d01477da340fc34cd987a817300d (diff)
parent2e2d6d2c3dcaccb101c97cf81e7a5f2afdf1ed49 (diff)
downloadzig-0e8f130aedce1e17299a8505bf997ae06e83b334.tar.gz
zig-0e8f130aedce1e17299a8505bf997ae06e83b334.zip
Merge pull request #16977 from kcbanner/lib_getauxval_fixup
linux: export getauxval when not compiling with libc
Diffstat (limited to 'lib/std/os/linux.zig')
-rw-r--r--lib/std/os/linux.zig18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig
index 443bf8edf9..9d3dcac559 100644
--- a/lib/std/os/linux.zig
+++ b/lib/std/os/linux.zig
@@ -154,8 +154,22 @@ pub usingnamespace @import("linux/io_uring.zig");
/// Set by startup code, used by `getauxval`.
pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
-/// See `std.elf` for the constants.
-pub fn getauxval(index: usize) usize {
+pub usingnamespace if (switch (builtin.zig_backend) {
+ // Calling extern functions is not yet supported with these backends
+ .stage2_x86_64, .stage2_aarch64, .stage2_arm, .stage2_riscv64, .stage2_sparc64 => false,
+ else => !builtin.link_libc,
+}) struct {
+ /// See `std.elf` for the constants.
+ /// This matches the libc getauxval function.
+ pub extern fn getauxval(index: usize) usize;
+ comptime {
+ @export(getauxvalImpl, .{ .name = "getauxval", .linkage = .Weak });
+ }
+} else struct {
+ pub const getauxval = getauxvalImpl;
+};
+
+fn getauxvalImpl(index: usize) callconv(.C) usize {
const auxv = elf_aux_maybe orelse return 0;
var i: usize = 0;
while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {