diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2024-07-25 01:15:46 +0200 |
|---|---|---|
| committer | Alex Rønne Petersen <alex@alexrp.com> | 2024-07-29 10:05:28 +0200 |
| commit | d6c637c36b399ae9d876592826f3e62d7636dc8e (patch) | |
| tree | 6ab0b639eac480c6d3b678ca6c5ba956027c87b8 /lib/std/start.zig | |
| parent | e33af8e9021199696e413057b57fb86e750a9de0 (diff) | |
| download | zig-d6c637c36b399ae9d876592826f3e62d7636dc8e.tar.gz zig-d6c637c36b399ae9d876592826f3e62d7636dc8e.zip | |
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.
Diffstat (limited to 'lib/std/start.zig')
| -rw-r--r-- | lib/std/start.zig | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig index fcc7fcd100..5bbb4dadce 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -455,7 +455,6 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn { if (native_os == .linux) { // Find the beginning of the auxiliary vector const auxv: [*]elf.Auxv = @ptrCast(@alignCast(envp.ptr + envp_count + 1)); - std.os.linux.elf_aux_maybe = auxv; var at_hwcap: usize = 0; const phdrs = init: { @@ -479,6 +478,10 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn { std.os.linux.pie.relocate(phdrs); } + // This must be done after PIE relocations have been applied or we may crash + // while trying to access the global variable (happens on MIPS at least). + std.os.linux.elf_aux_maybe = auxv; + if (!builtin.single_threaded) { // ARMv6 targets (and earlier) have no support for TLS in hardware. // FIXME: Elide the check for targets >= ARMv7 when the target feature API |
