| ... | @@ -482,22 +482,22 @@ pub const O = switch (native_arch) { | ... | @@ -482,22 +482,22 @@ pub const O = switch (native_arch) { |
| 482 | /// Set by startup code, used by `getauxval`. | 482 | /// Set by startup code, used by `getauxval`. |
| 483 | pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; | 483 | pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; |
| 484 | | 484 | |
| | 485 | /// Whether an external or internal getauxval implementation is used. |
| 485 | const extern_getauxval = switch (builtin.zig_backend) { | 486 | const extern_getauxval = switch (builtin.zig_backend) { |
| 486 | // Calling extern functions is not yet supported with these backends | 487 | // Calling extern functions is not yet supported with these backends |
| 487 | .stage2_aarch64, .stage2_arm, .stage2_riscv64, .stage2_sparc64 => false, | 488 | .stage2_aarch64, .stage2_arm, .stage2_riscv64, .stage2_sparc64 => false, |
| 488 | else => !builtin.link_libc, | 489 | else => !builtin.link_libc, |
| 489 | }; | 490 | }; |
| 490 | | 491 | |
| 491 | comptime { | | |
| 492 | const root = @import("root"); | | |
| 493 | // Export this only when building executable, otherwise it is overriding | | |
| 494 | // the libc implementation | | |
| 495 | if (extern_getauxval and (builtin.output_mode == .Exe or @hasDecl(root, "main"))) { | | |
| 496 | @export(&getauxvalImpl, .{ .name = "getauxval", .linkage = .weak }); | | |
| 497 | } | | |
| 498 | } | | |
| 499 | | | |
| 500 | pub const getauxval = if (extern_getauxval) struct { | 492 | pub const getauxval = if (extern_getauxval) struct { |
| | 493 | comptime { |
| | 494 | const root = @import("root"); |
| | 495 | // Export this only when building an executable, otherwise it is overriding |
| | 496 | // the libc implementation |
| | 497 | if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { |
| | 498 | @export(&getauxvalImpl, .{ .name = "getauxval", .linkage = .weak }); |
| | 499 | } |
| | 500 | } |
| 501 | extern fn getauxval(index: usize) usize; | 501 | extern fn getauxval(index: usize) usize; |
| 502 | }.getauxval else getauxvalImpl; | 502 | }.getauxval else getauxvalImpl; |
| 503 | | 503 | |