Skip to content

fix: Support '=' and '$SYSROOT' in linker scripts and inputs - #2720

Merged
davidlattimore merged 2 commits into
wild-linker:mainfrom
Blazearth:fix/sysroot-prefix-handling
Oct 17, 2026
Merged

davidlattimore merged 2 commits into
wild-linker:mainfrom
Blazearth:fix/sysroot-prefix-handling

Conversation

@Blazearth

Copy link
Copy Markdown
Contributor

Resolves #2719 by properly handling GNU ld sysroot prefixes (= and $SYSROOT) across linker scripts, command-line inputs, and search paths.
Check maybe_forced_sysroot before checking if the linker script is inside the sysroot in maybe_apply_sysroot, fixing resolution for in-sysroot scripts specifying = or $SYSROOT.
Support the default empty sysroot when --sysroot is not configured by stripping the prefix without altering absolute/relative path structure.

@Blazearth
Blazearth force-pushed the fix/sysroot-prefix-handling branch from c99a051 to 3d3501f Compare October 12, 2026 17:14
Comment thread deny.toml Outdated
[advisories]
ignore = [
"RUSTSEC-2024-0436", # paste is no longer maintained
"RUSTSEC-2024-0449", # unsafe-libyaml is no longer maintained

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.

We've just merged a change to address this, so this line is no longer needed.

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.

removed it .

Comment thread libwild/src/save_dir.rs

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.

Can you check if we're able to correctly create a save-dir when a path like $SYSROOT/tmp/input.o is passed to the linker, but no --sysroot is supplied? Specifically, does the save-dir load $D/tmp/input.o (i.e. a saved file inside the save-dir) or does it try to load /tmp/input.o from outside the save-dir (i.e. break the encapsulation of the save-dir).

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.

Sure! previously, save_dir only expanded forced sysroot prefixes for -L directories, not positional input arguments. When $SYSROOT/tmp/input.o was passed without --sysroot, write_args was emitting the literal $SYSROOT/tmp/input.o into the response file / run-with script, which caused the replay to load /tmp/input.o from outside the save directory and broke encapsulation.
I've added forced-sysroot handling for positional inputs in save_dir.rs::write_args, so it now resolves the path and emits $D/tmp/input.o.

@Blazearth
Blazearth force-pushed the fix/sysroot-prefix-handling branch from 3d3501f to b9fbc32 Compare October 13, 2026 06:38
@@ -0,0 +1,2 @@
/* GNU ld script */
GROUP ( =/lib/libvalue.a )

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.

Does the save-dir code correctly handle paths like this in linker scripts? How about when --sysroot isn't set?

@Blazearth Blazearth Oct 15, 2026 •

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.

Thanks for pointing this out. I've pushed an update with save-dir integration tests covering both = and $SYSROOT prefixes, with and without --sysroot.
I also replaced global string substitution with position-based edits to avoid overlapping path replacements.

…-dir tests

Use position-based edits in save-dir to avoid replacement overlap bugs, and add integration tests for '=' and '$SYSROOT' scripts without --sysroot.
@Blazearth
Blazearth force-pushed the fix/sysroot-prefix-handling branch from 7b91a99 to e959c48 Compare October 15, 2026 12:15
@davidlattimore
davidlattimore added this pull request to the merge queue Oct 17, 2026
Merged via the queue into wild-linker:main with commit 19ced10 Oct 17, 2026
26 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.

Missing support for sysroot prefix in linker scripts

2 participants