[4/10] libs/libc/elf: Translate link-time addresses through one place. - #19941
Merged
Conversation
This was referenced Aug 23, 2026
|
casaroli
force-pushed
the
elf-addr-translate
branch
from
August 23, 2026 21:34
79ed0b4 to
afda079
Compare
xiaoxiang781216
previously approved these changes
Aug 24, 2026
xiaoxiang781216
marked this pull request as ready for review
August 24, 2026 02:12
casaroli
force-pushed
the
elf-addr-translate
branch
from
August 26, 2026 15:54
afda079 to
c1f458c
Compare
xiaoxiang781216
approved these changes
Aug 26, 2026
Contributor
|
ci was fixed, please rebase your change to the last master. @casaroli |
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>
CI feeds nxstyle the diff hunks with three lines of context, so style errors that are older than this change, in the lines around the hunks, fail the check job. They are a switch body indented two columns too deep, an initializer brace one level in, and two declarations with no blank line after them. Whitespace only, no change in behaviour. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
elf-addr-translate
branch
from
August 27, 2026 12:33
a99a8de to
35be954
Compare
xiaoxiang781216
approved these changes
Aug 27, 2026
anchao
approved these changes
Aug 27, 2026
acassis
approved these changes
Aug 27, 2026
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 the PRs that #19673 is being split into, so each can be reviewed on its own.
[1/10]#19938 is withdrawn: the bug it described is not real, because a relocatable module already runs its constructors fromcrt0.[2/10]#19939 is merged.[3/10]#19940 is independent of this one and they can merge in any order. The rest are the FDPIC work itself, one subsystem each, and each is a no-op withCONFIG_FDPICoff: loader core[5/10]#19942, ARM relocations, the callback entry points, theexec()path,DT_NEEDEDthroughdlopen(), then documentation and a board configuration.Impact
None intended. Pure refactor, no behaviour change, no configuration change.
Testing
Built for
mps3-an547:picostest, which isCONFIG_ELFwithCONFIG_PIC.There is no hardware for this series, so the runtime evidence is emulated.
mps2-an500:xipfsruns the whole execute-in-place loader under QEMU with no board, and that is where the module load path is exercised.