Skip to content

feat: add -Ttext/-Tdata/-Tbss segment layout for SEGMENT_START support#1877

Merged
davidlattimore merged 1 commit into
wild-linker:mainfrom
Blazearth:feat-ttext-segment-layout
May 1, 2026
Merged

feat: add -Ttext/-Tdata/-Tbss segment layout for SEGMENT_START support#1877
davidlattimore merged 1 commit into
wild-linker:mainfrom
Blazearth:feat-ttext-segment-layout

Conversation

@Blazearth

Copy link
Copy Markdown
Contributor

This PR adds support for -Ttext, -Tdata, and -Tbss, wiring them into the layout phase so they affect the actual placement of .text, .data, and .bss. The section addresses are updated according to the provided -T* values
This builds on PR #1851, which introduced SEGMENT_START support using default values only.
This need to be merged first before PR #1851

@Blazearth Blazearth force-pushed the feat-ttext-segment-layout branch from 8c2620b to affed13 Compare April 30, 2026 16:24
@Blazearth Blazearth force-pushed the feat-ttext-segment-layout branch from affed13 to 0d9c3a1 Compare April 30, 2026 16:52
/// the layout phase reads `section_info.location`.
pub(crate) fn apply_section_start_overrides(&mut self, args: &P::Args) {
for (section_id, name) in [
(TEXT, SectionName(b".text")),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should -Ttext effect the address of the .text section or of the start of the executable segment? For your test, these are the same things, but if we have other executable sections such as .init, .plt etc, these will be before .text.

An alternative way of changing locations would be to alter build_output_order_and_program_segments. You'd likely need to pass Args to the function, but then you could add the OrderEvent::SetLocation directly before the first executable section. That would make it work in a way that would be more similar to how linker scripts work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the GNU ld's actual behaviour to confirm and interestingly ! it puts the section specifically at the given addr rather than the whole segment.
I tested With a binary that has .init and -Ttext=0x700000:

LOAD  0x401000  R E   ← .init lives here, separate segment
LOAD  0x700000  R E   ← .text starts here

_start is at 0x700000, _init is at 0x401000 — they end up in separate LOAD segments. GNU ld's -Ttext sets the address of the .text section specifically, not the start of the RX segment.
So injecting SetLocation before the first executable section (before .init/PLT_GOT) would actually implement -Ttext-segment which is a different flag.
In GNU ld to set the base address of the whole executable segment, it uses a completely different flag: -Ttext-segment=addr.
The current approach of setting section_info.location on .text matches GNU ld/lld behavior exactly.

In GNU ld ,the gap between .init at 0x401000 and .text at 0x700000 is handled naturally — they go into separate LOAD segments, so there's no wasted file space, only a gap in virtual address space. Wild does the same.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Thanks for checking this!

/// the layout phase reads `section_info.location`.
pub(crate) fn apply_section_start_overrides(&mut self, args: &P::Args) {
for (section_id, name) in [
(TEXT, SectionName(b".text")),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Thanks for checking this!

@davidlattimore davidlattimore merged commit 3714a2f into wild-linker:main May 1, 2026
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants