Repository navigation
elf: fix R_386_PC8 relocation patching on x86-32 - #6841
TharunBabu-05 wants to merge 1 commit into
Conversation
The x86-32 patcher subtracted the place address `P` only when `rel_type == R_386_PC16`, a copy-paste slip from the `R_386_16`/`R_386_PC16` case right above it. As a result `R_386_PC8` relocations were patched to `S + A` instead of the PC-relative `S + A - P`, so the single byte written was wrong. `R_386_8` (which must stay `S + A`) is unaffected. The x86-64 patcher already handles `R_X86_64_PC8` correctly. Add a test to `db/formats/elf/elf-rel-x86` using a small object with an `R_386_PC8` reloc (and an `R_386_8` control): the patched byte is `0x02` with the fix and `0x37` without it. Co-authored-by agent: Claude Code/claude-opus-4-8
02a4cd8 to
341e030
Compare
|
Your checklist for this pull request
Detailed description In This is part of the x86 relocation gaps tracked in #5259. AI disclosure: Claude Code (Anthropic Claude) was used to find the bug and Test plan Added a case to
Verified on CI: with the fix Closing issues |
|
Please rewrite the PR description by hand and give a reference to the ABI specs where that is documented. |
Your checklist for this pull request
RZ_APIfunction and struct this PR changes. (NoRZ_APIchanges — the editedpatch_reloc_x86_32isstatic.)Detailed description
In
patch_reloc_x86_32()(librz/bin/format/elf/elf_relocs_patching.c), theR_386_8/R_386_PC8case subtracted the place addressPonly whenrel_type == R_386_PC16— a copy-paste slip from theR_386_16/R_386_PC16case directly above it. So an
R_386_PC8relocation was patched toS + Ainstead of the PC-relative
S + A - P, writing the wrong byte.R_386_8(which must stay
S + A) was unaffected. The x86-64 patcher already handlesR_X86_64_PC8correctly.This is part of the x86 relocation gaps tracked in #5259.
AI disclosure: Claude Code (Anthropic Claude) was used to find the bug and
draft the fix and test; I reviewed and verified everything. The commit carries
the
Co-authored-by agent:trailer perAGENTS.md.Test plan
Added a case to
test/db/formats/elf/elf-rel-x86using a small object with anR_386_PC8relocation (and anR_386_8control), added inrizinorg/rizin-testbins#6841 as
elf/x86_relocs_pc8.o. It reads thepatched bytes:
R_386_PC8site@ 0x08000035→0x02(=0x08000037 - 0x08000035)R_386_8site@ 0x08000036→0x37(unchanged)Verified on CI: with the fix
rz-test db/formats/elf/elf-rel-x86→2 OK;with the fix reverted →
1 XX(expected02, actual37), confirming thetest catches the regression.
Closing issues