authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-08-27 19:50:57-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-08-27 19:50:57-04:00
log2e2d6d2c3dcaccb101c97cf81e7a5f2afdf1ed49
tree450bad25324a013eb79b4cf057afd13ce3416eb1
parentfb0cef8522968af6a15fe953b8f259f3f0a7b37c

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


1 files changed, 15 insertions(+), 8 deletions(-)

lib/std/os/linux.zig+15-8
......@@ -154,9 +154,21 @@ pub usingnamespace @import("linux/io_uring.zig");
154154/// Set by startup code, used by `getauxval`.
155155pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
156156
157/// See `std.elf` for the constants.
158/// This matches the libc getauxval function.
159pub extern fn getauxval(index: usize) usize;
157pub 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
160172fn getauxvalImpl(index: usize) callconv(.C) usize {
161173 const auxv = elf_aux_maybe orelse return 0;
162174 var i: usize = 0;
......@@ -166,11 +178,6 @@ fn getauxvalImpl(index: usize) callconv(.C) usize {
166178 }
167179 return 0;
168180}
169comptime {
170 if (!builtin.link_libc) {
171 @export(getauxvalImpl, .{ .name = "getauxval", .linkage = .Weak });
172 }
173}
174181
175182// Some architectures (and some syscalls) require 64bit parameters to be passed
176183// in a even-aligned register pair.