linux: fixup for platforms that don't support extern functions yet

This commit is contained in:
kcbanner 2023-08-27 19:50:57 -04:00
parent fb0cef8522
commit 2e2d6d2c3d

View File

@ -154,9 +154,21 @@ 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.
/// This matches the libc getauxval function.
pub extern 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;
@ -166,11 +178,6 @@ fn getauxvalImpl(index: usize) callconv(.C) usize {
}
return 0;
}
comptime {
if (!builtin.link_libc) {
@export(getauxvalImpl, .{ .name = "getauxval", .linkage = .Weak });
}
}
// Some architectures (and some syscalls) require 64bit parameters to be passed
// in a even-aligned register pair.