Skip to content

Commit 7bc7896

Browse files
committed
start: Fix _start() to initialize the ToC for powerpc64.
The previous version of this function referenced the argc_argv_ptr global variable as an inline asm operand. This caused LLVM to generate prologue code to initialize the ToC so that the global variable can actually be accessed. Ordinarily, there's nothing wrong with that. But _start() is a naked function! This makes it actually super surprising that LLVM did this. It also means that the old version only really worked by accident. Once the reference to the global variable was removed, no ToC was set up, thus violating the calling convention once we got to posixCallMainAndExit(). This then caused any attempt to access global variables here to crash - namely when setting std.os.linux.elf_aux_maybe. The fix is to just initialize the ToC manually in _start().
1 parent ecd459b commit 7bc7896

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/std/start.zig

+2
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ fn _start() callconv(.Naked) noreturn {
341341
.powerpc64, .powerpc64le =>
342342
// Setup the initial stack frame and clear the back chain pointer.
343343
// TODO: Support powerpc64 (big endian) on ELFv2.
344+
\\ addis 2, 12, .TOC. - _start@ha
345+
\\ addi 2, 2, .TOC. - _start@l
344346
\\ mr 3, 1
345347
\\ li 0, 0
346348
\\ stdu 0, -32(1)

0 commit comments

Comments
 (0)