Skip to content

fix: error on R_X86_64_32/32S relocations in shared objects #2083

Open
deepakshirkem wants to merge 1 commit into
wild-linker:mainfrom
deepakshirkem:fix/2074-wrong-dynamic-reloc-type-no-gc-sections
Open

fix: error on R_X86_64_32/32S relocations in shared objects #2083
deepakshirkem wants to merge 1 commit into
wild-linker:mainfrom
deepakshirkem:fix/2074-wrong-dynamic-reloc-type-no-gc-sections

Conversation

@deepakshirkem

Copy link
Copy Markdown
Contributor

R_X86_64_32 and R_X86_64_32S cannot be used when making a shared object because the dynamic linker has no way to patch 32-bit absolute relocations at runtime. Wild was silently emitting R_X86_64_64 instead of erroring, producing a broken shared object.

Add an early check in apply_relocation to error when these relocation types are encountered while building a shared object, matching the behavior of GNU ld and lld.

Fixes #2074

@deepakshirkem deepakshirkem changed the title fix: error on R_X86_64_32/32S relocations in shared objects (#2074) fix: error on R_X86_64_32/32S relocations in shared objects Jun 16, 2026
// Both GNU ld and lld error: recompile with -fPIC
//#Arch:x86_64
//#LinkArgs:--no-gc-sections -shared
//#SkipLinker:ld

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.

Could be good to enable ld (and possibly lld) for the test. If all linkers have "recompile with -fPIC" then you could have that as the error matcher. If you want to verify that Wild says the message below, then you could add "ExpectErrorWild" (implementing it should be pretty trivial - there's already an "ExpectWarningWild")

…ker#2074)

R_X86_64_32 and R_X86_64_32S cannot be used when making a shared
object because the dynamic linker has no way to patch 32-bit absolute
relocations at runtime. Wild was silently emitting R_X86_64_64 instead
of erroring, producing a broken shared object.

Add an early check in apply_relocation to error when these relocation
types are encountered while building a shared object, matching the
behavior of GNU ld and lld.

Also add ExpectErrorWild test directive (analogous to ExpectWarningWild)
to allow testing Wild-specific error messages independently.

Fixes wild-linker#2074
@deepakshirkem deepakshirkem force-pushed the fix/2074-wrong-dynamic-reloc-type-no-gc-sections branch from d188457 to 0d781f8 Compare June 17, 2026 19:49
@deepakshirkem

Copy link
Copy Markdown
Contributor Author

@davidlattimore, One question: should we extend this PR to also report an error for sub-pointer-size absolute relocations on other 64-bit architectures such as AArch64, RISC-V64, PPC64, and LoongArch64?
They seem to have the same fundamental issue with ByteSize(4) absolute relocations in shared objects.
I could either implement a generic check based on the architecture trait, or add explicit relocation-type checks in each architecture file, similar to what we did for x86_64. Which approach do you think would be preferable?

@davidlattimore

Copy link
Copy Markdown
Member

That'd be great if you can make the check generic. It could also be good to look to see if the check can be done in the layout phase rather than the write phase. That said, it's OK if it stays in the write phase.

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.

Wild emits wrong dynamic relocation type for absolute relocations in shared objects with --no-gc-sections

2 participants