Skip to content

[X86] Support i386 absolute relocations - #2027

Open
Bhoumik Patidar (BhoumikPatidar) wants to merge 1 commit into
qualcomm:mainfrom
BhoumikPatidar:x86_32_absolute_relocations
Open

Bhoumik Patidar (BhoumikPatidar) wants to merge 1 commit into
qualcomm:mainfrom
BhoumikPatidar:x86_32_absolute_relocations

Conversation

@BhoumikPatidar

@BhoumikPatidar Bhoumik Patidar (BhoumikPatidar) commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Add the relocation layer for i386 links: R_386_NONE, R_386_8, R_386_16, and R_386_32.

Unlike x86-64, i386 uses Elf32_Rel rather than Elf64_Rela. The addend is stored in the field being relocated, so it must be read and sign-extended from that field width before evaluating S + A. Normalize the result to the 32-bit ELF address space before checking narrow fields and writing the result back. This preserves valid full-width 32-bit bit patterns, including addresses with bit 31 set, while rejecting values that cannot be encoded in 8- or 16-bit fields.

Resolves #2028
Progress on #1961

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can look into how ARM parses "llvm/BinaryFormat/ELFRelocs/ARM.def" to create the list of relocations? This helps our relocation list to never get stale.

@quic-seaswara

Copy link
Copy Markdown
Contributor

Can look into how ARM parses "llvm/BinaryFormat/ELFRelocs/ARM.def" to create the list of relocations? This helps our relocation list to never get stale.

Great comment. Thanks for bringing this up!

Add the relocation layer for i386 links: R_386_NONE, R_386_8, R_386_16, and R_386_32.

Unlike x86-64, i386 uses Elf32_Rel rather than Elf64_Rela. The addend is stored in the field
being relocated, so it must be read and sign-extended from that field width before evaluating S + A.
Normalize the result to the 32-bit ELF address space before checking narrow fields and writing the result
back. This preserves valid full-width 32-bit bit patterns, including addresses with bit 31 set,
while rejecting values that cannot be encoded in 8- or 16-bit fields.

Signed-off-by: Bhoumik Patidar <bpatidar@qti.qualcomm.com>
@BhoumikPatidar

Copy link
Copy Markdown
Contributor Author

Can look into how ARM parses "llvm/BinaryFormat/ELFRelocs/ARM.def" to create the list of relocations? This helps our relocation list to never get stale.

Thanks for highlighting this. I have updated the code to use i386.def to populate the reloc names and IDs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support i386 absolute relocations

3 participants