authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-25 01:15:46+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-29 10:05:28+02:00
logd6c637c36b399ae9d876592826f3e62d7636dc8e
tree6ab0b639eac480c6d3b678ca6c5ba956027c87b8
parente33af8e9021199696e413057b57fb86e750a9de0
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

start: Set std.os.linux.elf_aux_maybe after PIE relocations.

Accesses to this global variable can require relocations on some platforms (e.g. MIPS). If we do it before PIE relocations have been applied, we'll crash.

1 files changed, 4 insertions(+), 1 deletions(-)

lib/std/start.zig+4-1
......@@ -455,7 +455,6 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn {
455455 if (native_os == .linux) {
456456 // Find the beginning of the auxiliary vector
457457 const auxv: [*]elf.Auxv = @ptrCast(@alignCast(envp.ptr + envp_count + 1));
458 std.os.linux.elf_aux_maybe = auxv;
459458
460459 var at_hwcap: usize = 0;
461460 const phdrs = init: {
......@@ -479,6 +478,10 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn {
479478 std.os.linux.pie.relocate(phdrs);
480479 }
481480
481 // This must be done after PIE relocations have been applied or we may crash
482 // while trying to access the global variable (happens on MIPS at least).
483 std.os.linux.elf_aux_maybe = auxv;
484
482485 if (!builtin.single_threaded) {
483486 // ARMv6 targets (and earlier) have no support for TLS in hardware.
484487 // FIXME: Elide the check for targets >= ARMv7 when the target feature API