Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.os.linux.start_pie: Add mips and powerpc support #20823

Merged
merged 6 commits into from
Aug 1, 2024

Conversation

alexrp
Copy link
Member

@alexrp alexrp commented Jul 27, 2024

Requires #20822 to actually work.

.mips64, .mips64el => asm volatile (
\\ .weak _DYNAMIC
\\ .hidden _DYNAMIC
\\ .balign 8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexrp alexrp force-pushed the start-pie-mips-ppc branch from ad21c0c to e459240 Compare July 28, 2024 15:09
alexrp added 4 commits July 30, 2024 01:24
On MIPS, this call will require a relocation, which we can't do until after PIE
relocations have been applied.
…ibcalls.

The code would cause LLVM to emit a jump table for the switch in the loop over
the dynamic tags. That jump table was far enough away that the compiler decided
to go through the GOT, which would of course break at this early stage as we
haven't applied MIPS's local GOT relocations yet, nor can we until we've walked
through the _DYNAMIC array.

The first attempt at rewriting this used code like this:

    var sorted_dynv = [_]elf.Addr{0} ** elf.DT_NUM;

But this is also problematic as it results in a memcpy() call. Instead, we
explicitly initialize it to undefined and use a loop of volatile stores to
clear it.
@alexrp alexrp force-pushed the start-pie-mips-ppc branch from e459240 to 595edff Compare July 29, 2024 23:26
@alexrp
Copy link
Member Author

alexrp commented Jul 29, 2024

cc @kubkon you might want to check the relocation stuff?

lib/std/os/linux/start_pie.zig Outdated Show resolved Hide resolved
@alexrp alexrp force-pushed the start-pie-mips-ppc branch from 595edff to 2e719f3 Compare July 30, 2024 16:03
@andrewrk andrewrk merged commit 9c22a6b into ziglang:master Aug 1, 2024
10 checks passed
@andrewrk
Copy link
Member

andrewrk commented Aug 1, 2024

Nice!

@alexrp alexrp deleted the start-pie-mips-ppc branch August 1, 2024 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants