Skip to content

fix: Error on R_X86_64_32 to DSO symbols in PIE output #2125

Draft
deepakshirkem wants to merge 1 commit into
wild-linker:mainfrom
deepakshirkem:fix/2114-invalid-reloc-pie-shared
Draft

fix: Error on R_X86_64_32 to DSO symbols in PIE output #2125
deepakshirkem wants to merge 1 commit into
wild-linker:mainfrom
deepakshirkem:fix/2114-invalid-reloc-pie-shared

Conversation

@deepakshirkem

@deepakshirkem deepakshirkem commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Wild was silently succeeding when R_X86_64_32 or R_X86_64_32S relocations were used against DSO symbols in PIE output. Both GNU ld and lld correctly error with "recompile with -fPIC".

What still needs fixing (#2114)

  • R_X86_64_PC32 to DSO symbols in PIE — tricky because it's valid for PLT calls but invalid for data references. Not sure how to distinguish the two cases.
  • R_X86_64_64 to local symbols in PIE — lld errors but GNU ld emits R_X86_64_RELATIVE dynamic relocation instead. Not sure which behavior Wild should match.

Help needed

@davidlattimore @lapla-cogito

  1. How to distinguish valid vs invalid R_X86_64_PC32 in PIE context
  2. Whether R_X86_64_64 to local symbols should error or emit dynamic reloc

Partial fix for #2114

Wild was silently succeeding when R_X86_64_32 or R_X86_64_32S relocations
were used against DSO symbols in PIE or shared object output. Both GNU ld
and lld correctly error with 'recompile with -fPIC'.

This is a partial fix for wild-linker#2114. R_X86_64_PC32 to DSO symbols and
R_X86_64_64 to local symbols in PIE still need investigation.

Fixes part of wild-linker#2114
@deepakshirkem deepakshirkem force-pushed the fix/2114-invalid-reloc-pie-shared branch from 21b3801 to d5713cd Compare June 22, 2026 20:40
@deepakshirkem deepakshirkem changed the title fix: Error on R_X86_64_32 to DSO symbols in PIE output (partial fix for #2114) fix: Error on R_X86_64_32 to DSO symbols in PIE output Jun 22, 2026
//#Shared:pie-invalid-reloc-dso.s
//#LinkArgs:-pie --no-gc-sections
//#ExpectError:R_X86_64_32
//#RunEnabled:false

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.

Note that ExpectError implies "RunEnabled:False"

@davidlattimore

Copy link
Copy Markdown
Member
  • How to distinguish valid vs invalid R_X86_64_PC32 in PIE context

Possibly whether the target of the relocation has ValueFlags::FUNCTION set? But I'd say it's worthwhile experimenting a bit to see in which cases the other linkers accept or error.

  • Whether R_X86_64_64 to local symbols should error or emit dynamic reloc

If lld errors here, then I'd say it'd be good to do the same. We can always relax it later to accept it like GNU ld if it turns out to be problematic. But it also depends a bit on how hard the implementation is. If it ends up significantly simpler to accept rather than error, then I'd be open to that.

@davidlattimore

Copy link
Copy Markdown
Member

It's fine, possibly even preferable to fix each case in a separate PR. So don't feel that you need to fix them all in this PR. Note that github isn't very good at reading intention when issues are referenced, so saying "partial fix for X" is just as likely to close X when the PR is merged. I usually just put "Issue X", since that definitely doesn't close the issue.

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