[LinkerScript] Fix orphan section placement with scripts#1438
Open
quic-areg wants to merge 1 commit into
Open
Conversation
2d39c18 to
667890c
Compare
Shankar Easwaran (quic-seaswara)
left a comment
Contributor
There was a problem hiding this comment.
Can we change and assign SHO_INIT rank to the init section instead ?
Shankar Easwaran (quic-seaswara)
approved these changes
Jul 10, 2026
Steven Ramirez Rosa (Steven6798)
approved these changes
Jul 13, 2026
Parth (parth-07)
approved these changes
Jul 13, 2026
Orphan insertion scan stopped at the first section with a greater
rank than the orphan, placing the orphan before that section. This groups
sections with like permissions together when the script is sorted by
rank, but when a script declares a lower ranked section first, the scan can
insert a higher ranked orphan too early:
script:
SECTIONS {
.init : { KEEP(*(.data.init.enter)) } /* WA (picolibc) */
.text : { *(.text) } /* AX */
}
Note: AX/.text has a lower rank than WA/.init.
A third (orphan) section orphan_code (AX) is placed before .init, the
first section with a higher rank, but .init is expected to come first.
lld/bfd instead group the orphan with its like ranked neighbor (.text)
rather than taking eld's single pass insertion shortcut, so the orphan
lands after .text and .init keeps its place.
Scan the whole list and insert after the last section with rank <= the
orphan's. For scripts sorted by rank, this is equivalent. The no linker
script path is unchanged.
Also update Hexagon TrampolineMissingSymbol: the fix moved its orphaned
.init next to .txt.foo, removing the long call. Add an explicit .init
rule to restore the call distance and check that the expected trampoline
is emitted.
Fixes qualcomm#1408
Signed-off-by: quic-areg <aregmi@qti.qualcomm.com>
667890c to
e820f96
Compare
|
LGTM. This PR fixes the issue I am seeing. See #1194 (comment). |
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.
Orphan insertion scan stopped at the first section with a greater rank than the orphan, placing the orphan before that section. This groups sections with like permissions together when the script is sorted by rank, but when a
script declares a lower ranked section first, the scan can insert a higher ranked orphan too early:
Note: AX/.text has a lower rank than WA/.init.
A third (orphan) section
orphan_code(AX) is placed before.init, the first section with a higher rank, but.initis expected to come first. lld/bfd instead group the orphan with its like ranked neighbor (.text) ratherthan taking eld's single pass insertion shortcut, so the orphan lands after
.textand.initkeeps its place.Scan the whole list and insert after the last section with rank
<=the orphan's. For scripts sorted by rank, this is equivalent. The no linker script path is unchanged.Also update Hexagon TrampolineMissingSymbol: the fix moved its orphaned
.initnext to.txt.foo, removing the long call. Add an explicit.initrule to restore the call distance and check that the expected trampoline isemitted.
Fixes #1408