Skip to content

compiler: Use -T instead of --script for linker scripts #142445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,9 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty
sess.dcx().emit_fatal(errors::LinkScriptWriteFailure { path, error });
}

cmd.link_arg("--script").link_arg(path);
// "--script" feels nice and explicit, but -T is supported by gcc **and clang**.
// Amusingly, lld supports --script just fine, it's only clang that doesn't.
cmd.link_arg("-T").link_arg(path);
Copy link
Contributor

Choose a reason for hiding this comment

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

link_arg("-T") will emit -Wl,-T on command line, so it will go directly to linker and clang won't see it, so the explanation doesn't seem right.

Copy link
Member Author

Choose a reason for hiding this comment

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

wait, then why is it broken for them?

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

It must be something about building specifically for a custom target. Thanks for catching this, I'll take a closer look. This patch's code change might still be correct but it might be for a weird reason.

Copy link
Member

@Noratrieb Noratrieb Jun 13, 2025

Choose a reason for hiding this comment

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

gcc does not support --script either. I suspect the people in #127183 configured their target incorrectly such that cc was invoked with ld-style arguments

}
_ => {}
}
Expand Down
Loading