Repository navigation
fix(elf): keep copy relocations of read-only symbols inside RELRO - #155
Merged
Merged
Conversation
…ld#123) A copy relocation of a symbol that the shared object kept read-only was allocated in `.bss`, so a `const` imported by a non-PIE executable stayed writable for the life of the process. Both reference linkers put it inside PT_GNU_RELRO instead: GNU ld uses `.data.rel.ro`, lld uses `.bss.rel.ro`. reld now uses `.data.rel.ro`, matching GNU ld. Reproduced with a DSO exporting `const int ro_value` and `int rw_value` referenced from a `-no-pie` main: ld.bfd placed ro_value in `.data.rel.ro`, ld.lld in `.bss.rel.ro`, reld in `.bss`. Four sites chose the destination independently — the size-reservation pass, the address-assignment pass, and both symbol-table writers — so they now share `copy_relocation_section`. Fixing only the first two produced an output whose symbol address was in `.data.rel.ro` while its `st_shndx` still named `.bss`, which is how the new acceptance fixture caught it. Writable symbols keep their `.bss` home, so `rw_value`-style imports are unchanged. Evidence: new `elf/copy-relocation-relro` acceptance fixture asserts the section of both symbols and executes the result. Acceptance failure set is byte-identical to main (11 pre-existing environmental failures, +1 pass and +3 arch-ignored from this fixture); 12-seed differential run against ld.bfd is clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The RELRO copy-relocation fix makes mold's own copyrel-relro.sh pass, and the ratchet correctly failed the build with "is in skip list but now passes". That is independent third-party confirmation of the fix. The other four copyrel entries still fail, per the same CI run, so they stay; their shared comment no longer described reality, since read-only copies now land in `.data.rel.ro` and only writable ones stay in `.bss`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Collaborator
Author
|
CI caught something my local run could not: the mold corpus ratchet failed with That is independent third-party confirmation of the fix — mold's own RELRO copy-relocation test now passes against reld. Removed that entry from The same CI run shows the other four Acceptance in CI: 234 passed, 0 failed. |
This was referenced Sep 17, 2026
zackees
added a commit
that referenced
this pull request
Sep 17, 2026
…3) (#160) A caller-supplied ignore is ratcheted per fixture: the fixture that declares it must still observe it. The ~90 inherited `--reld-defaults` patterns had no such check, because each one suppresses differences across every fixture and no single fixture can say whether it is still needed. Nothing removed them, so a default outlived the divergence it described — `.data.rel.ro` is listed as a section reld does not support, which stopped being true in #155. The run now takes the union instead. Every report contributes the defaults it declared and the ignores it observed, and at the end of a full acceptance run the harness prints the defaults no fixture observed. Those are removal candidates for reld#13, which is how the inherited list shrinks. It prints rather than fails, because which defaults get exercised depends on which fixtures the host can run. `RELD_RATCHET_DEFAULT_IGNORES=1` turns the report into a failure, for a run that covers the matrix. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #123 (Phase 2, the
copyrel_readonly_is_relrochecklist line). Part of the #153 burn-down.The bug
A copy relocation of a symbol that the shared object kept read-only was allocated in
.bss, so aconstimported by a non-PIE executable stayed writable for the life of the process. Both reference linkers keep it insidePT_GNU_RELROso the loader can re-protect it after relocation.Reproduced with a DSO exporting
const int ro_valueandint rw_value, referenced from a-no-piemain:ro_valuelands inPT_GNU_RELROld.bfd2.46.data.rel.rold.lld21.1.8.bss.rel.ro.bss.data.rel.roIt is a silent hardening regression, not a link failure, which is why nothing caught it.
The fix
reld uses
.data.rel.ro, matching GNU ld. Writable symbols keep their.bsshome.Four places picked the destination independently: the size-reservation pass, the address-assignment pass, and both the dynsym and symtab writers. They now share one
copy_relocation_sectionhelper. That matters — fixing only the first two produced an output whose symbol address was in.data.rel.rowhile itsst_shndxstill named.bss, and the new fixture is what caught that inconsistency.Evidence
elf/copy-relocation-relroasserts the section of both the read-only and writable symbol, and executes the linked binary so the copy relocations are proven to still work at runtime.main. Both runs fail the same 11 tests, all environmental on this host (no staticlibm/libc, missinglibstdc++.so.6); my branch adds +1 pass and +3 arch-ignored, which is exactly the new fixture.reld-difftestagainstld.bfd: 0 differential failures.cargo fmt --check,clippy --workspace --all-targets -D warnings, reld-core lib tests (209), acceptance-policy, external-runner, and the host-platform Dylint are all green.🤖 Generated with Claude Code