Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4e824a780
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| rela_plt_section.body << rps | ||
| next |
There was a problem hiding this comment.
Preserve call-site relocation for undefined PLT32 symbols
When handling undefined R_X86_64_PLT32 relocations, this branch appends a .rela.plt record and immediately nexts, so the original text relocation path is skipped and no call-site patching happens here. For executable/PIE outputs that call external symbols (like sample/C/plt-call.c), .rela.text is later removed, leaving the call displacement at its placeholder value and producing a runtime jump to the wrong address.
Useful? React with 👍 / 👎.
| sym = symtab_section.body[rel.sym] | ||
| dynsymndx = dynsym_section.body.index { |ds| ds.name_offset == dynstr_section.body.offset_of(sym.name_string) } |
There was a problem hiding this comment.
Remap .rela.plt symbol indexes after sorting .symtab
This lookup treats rel.sym as a stable .symtab index, but .rela.plt entries are created before symtab_section.body.sort_by! and are never reindexed afterward (only rel_sections get remapped). In multi-object links, sorting shifts symbol positions, so .rela.plt can resolve against the wrong symbol here or fail with cannot find symbol ... in .dynsym even though the undefined symbol exists.
Useful? React with 👍 / 👎.
5a9f29d to
7cc790c
Compare
Summary
This PR refactors linker write flow and adds PIE dynamic-link scaffolding around PLT relocations.
Writerphases (section write, relocation patching, dynamic patching, program-header patching, section-header finalization)..plt,.got.plt, and.rela.pltscaffolding and wire them through Builder/Writer..rela.pltrelocation info/offsets against final.dynsym/.got.pltlayout.Main changes
Linker/ELF internals
lib/caotral/linker/writer.rb.plt/.got.pltsection writes + header updates..rela.pltsymbol remap to dynamic symbol indexes before write.sh_link/sh_info/sh_entsizehandling for relocation sections adjusted for dynamic relocations.lib/caotral/linker/builder.rb.rela.plt,.got.plt,.dynsym/.dynstrintegration).lib/caotral/binary/elf/section/rel.rblib/caotral/binary/elf/section/dynamic.rbTest/fixtures
sample/C/plt-call.csample/C/gotpcrel-call.ctest/caotral/linker/plt-call_test.rb(PLT/rela.plt and dynamic-tag consistency)test/caotral/linker/gotpc-call_test.rb(unsupported GOTPCREL path)Validation run
ruby test/caotral/linker/multi-link_test.rbruby test/caotral/linker/pie-object_test.rbruby test/caotral/linker/plt-call_test.rbruby test/caotral/linker/gotpc-call_test.rbFollow-up