Skip to content

Conversation

ayrtonm
Copy link
Contributor

@ayrtonm ayrtonm commented Jun 5, 2022

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.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 5, 2022
@rust-highfive
Copy link
Contributor

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 5, 2022
|| arg.starts_with("-dT")
}
// Omit the embedded linker script if a user supplied one
if sess.opts.cg.link_args.iter().any(|arg| is_script_arg(arg)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

rustc should not try interpreting raw linker arguments.

Maybe rustc can use --default-script for the target-specified script to be overridable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably use --default-script, but lld doesn't support it yet so that would break the workflow for the psp target so I'll close this PR for now.

@davidtwco
Copy link
Member

r? @petrochenkov

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 6, 2022
@JohnCSimon
Copy link
Member

Ping from triage:
@ayrtonm - can you address the comments from the reviewers?

@ayrtonm ayrtonm closed this Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants