[4/10] libs/libc/elf: Translate link-time addresses through one place. - #19941
Open
casaroli wants to merge 1 commit into
Open
[4/10] libs/libc/elf: Translate link-time addresses through one place.#19941casaroli wants to merge 1 commit into
casaroli wants to merge 1 commit into
Conversation
This was referenced Aug 23, 2026
|
The ET_DYN path computes run-time addresses from link-time ones in five places, each open-coding the arithmetic, and two of them disagree about how: libelf_relocatedyn() adds textalloc to a relocation's r_offset in one branch and subtracts datasec before adding datastart in the next, while the value translation a few lines further down picks between those two forms with an explicit test on datasec. Collect that into libelf_addr(), which makes the test once: an address below the data segment's link-time base belongs to text, anything at or above it to data. This changes nothing today. libelf_elfsize() sets segpad = datasec - (text_vaddr + textsize) and libelf_load() then places datastart = textalloc + textsize + segpad so datastart - datasec is textalloc, and the data branch reduces to textalloc + vaddr -- exactly what the text branch returns, and exactly what adding a single load bias did before. The two forms are the same arithmetic written twice. They stop being the same once text and data are placed independently, which is what an FDPIC object requires: its two PT_LOAD segments are relocated separately so that the read-only one can be mapped in place on the media while only the writable one is copied. Having the translation in one function is what makes that possible without auditing every open-coded expression again. Built for mps3-an547:picostest, which is CONFIG_ELF with CONFIG_PIC, and boots identically to the same configuration without this change. Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
elf-addr-translate
branch
from
August 23, 2026 21:34
79ed0b4 to
afda079
Compare
xiaoxiang781216
approved these changes
Aug 24, 2026
xiaoxiang781216
marked this pull request as ready for review
August 24, 2026 02:12
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.
Summary
The
ET_DYNpath computes run-time addresses from link-time ones in five places, each open-coding the arithmetic, and two of them disagree about how.libelf_relocatedyn()addstextallocto a relocation'sr_offsetin one branch and subtractsdatasecbefore addingdatastartin the next, while the value translation a few lines down picks between those two forms with an explicit test ondatasec.This collects that into
libelf_addr(), which makes the test once: an address below the data segment's link-time base belongs to text, anything at or above it to data.It changes nothing today.
datastart - datasecistextallocfor the way an object is placed now, so both forms reduce to the same arithmetic. They stop being the same once text and data are placed independently, which is what an FDPIC object requires, and having the translation in one function is what makes that possible without auditing every open-coded expression again.This is the fourth of ten PRs that #19673 is being split into, so each can be reviewed on its own. The first four have no FDPIC content at all and do not depend on each other, so they can merge in any order. The remaining six are the FDPIC work itself, one subsystem each, and each is a no-op with
CONFIG_FDPICoff: loader core, ARM relocations, the callback entry points, theexec()path,DT_NEEDEDthroughdlopen(), then documentation and a board configuration. The others are[1/10]#19938,[2/10]#19939 and[3/10]#19940.Impact
None intended. Pure refactor, no behaviour change, no configuration change.
Testing
Built for
mps3-an547:picostest, which isCONFIG_ELFwithCONFIG_PIC.tools/checkpatch.shpasses.Runtime evidence on real hardware follows tomorrow, on an RP2350.