Allow overriding linker scripts in built-in targets #97749
Closed
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.
PR #72062 added the ability to include linker scripts with built-in targets. However, this only works for targets that never need to customize the ld script since it cannot be overridden. This commit checks user-supplied link args for ld scripts and omits the built-in script if another is found. Technically scripts may also be passed to ld without a flag (i.e. as if it were a .o), but detecting those requires opening and parsing the files specified in link args so I didn't check for those. I also considered changing
--script
with--defaultscript
(which can be overridden), but lld doesn't support this. I'm not sure who should review this, but the PSP target (cc @overdrivenpotato) is the only one currently using built-in scripts and this shouldn't affect those users' workflow.For context, there's been interest in adding a playstation 1 target which would benefit from this change. Currently the required ld script is provided by the psx crate's
build.rs
, but it would be nice to have a built-in target which just works without requiring any specific crate. The psx also needs customized ld scripts in some cases so the current built-in scripts are too inflexible.