Skip to content

feat(ppc64): REL24 local entry plus REL32/ADDR32/REL64#1999

Merged
davidlattimore merged 3 commits into
wild-linker:mainfrom
runlevel5:ppc64-relocs
May 31, 2026
Merged

feat(ppc64): REL24 local entry plus REL32/ADDR32/REL64#1999
davidlattimore merged 3 commits into
wild-linker:mainfrom
runlevel5:ppc64-relocs

Conversation

@runlevel5
Copy link
Copy Markdown
Contributor

Extends the ppc64le static-relocation support added in #1977 with the
remaining pieces needed for a static link to come out correct on ELFv2:

  • REL24 local entry. An ELFv2 callee that sets up r2 has a separate
    local entry point. A direct call that already shares the callee's TOC
    should branch there, skipping the global-entry prologue. The offset is
    encoded in the callee's st_other (STO_PPC64_LOCAL); functions with
    no separate local entry (offset 0) are unaffected.

  • REL32 / ADDR32. 32-bit PC-relative and absolute. REL32 is what
    .eh_frame is built out of, so without it nothing with exception
    tables links cleanly.

  • REL64. 64-bit PC-relative — same shape as REL32 but 8 bytes.

A small generic hook Arch::local_entry_offset(st_other) is added so the
REL24 path can ask the target which entry to bias the branch by; default
is 0 (no other architecture cares).

Comment thread linker-utils/src/ppc64.rs
RelocationKind::Absolute,
RelocationSize::ByteSize(4),
// Can represent either a signed or an unsigned 32-bit value.
AllowedRange::new(-(2i64.pow(31)), 2i64.pow(32)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does a negative absolute address make sense? What does it mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I merely match the binutils' complain_overflow_bitfield. The R_AARCH64_ABS32 in linker-utils/src/aarch64.rs is also the same. Hence my decision to keep it that way for consistency. Having said that I am more than happy to make it stricter as you suggested.

Comment thread libwild/src/elf_ppc64.rs
runlevel5 added 3 commits May 30, 2026 23:57
ELFv2 functions that set up r2 have a separate local entry point. For a
direct call that already shares the callee's TOC, branch to that local
entry (skipping the global-entry prologue) by adding the callee's
st_other local-entry offset to the branch target. Functions with no
separate local entry (offset 0) are unaffected.
REL32 (32-bit PC-relative, used pervasively by .eh_frame) and ADDR32
(32-bit absolute). Both are simple 4-byte values.
R_PPC64_REL64 (64-bit PC-relative), an 8-byte value mirroring REL32.
@davidlattimore davidlattimore merged commit a973fa8 into wild-linker:main May 31, 2026
25 checks passed
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.

2 participants