Skip to content

Use MSVC-style escaping when passing a response/@ file to lld on windows #122596

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

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 0 additions & 6 deletions compiler/rustc_codegen_ssa/src/back/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ impl Command {
Program::Lld(ref p, flavor) => {
let mut c = process::Command::new(p);
c.arg("-flavor").arg(flavor.as_str());
if let LldFlavor::Wasm = flavor {
// LLVM expects host-specific formatting for @file
// arguments, but we always generate posix formatted files
// at this time. Indicate as such.
c.arg("--rsp-quoting=posix");
}
c
}
};
Expand Down
17 changes: 11 additions & 6 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ fn link_natively<'a>(
let mut i = 0;
loop {
i += 1;
prog = sess.time("run_linker", || exec_linker(sess, &cmd, out_filename, tmpdir));
prog = sess.time("run_linker", || exec_linker(sess, &cmd, out_filename, flavor, tmpdir));
let Ok(ref output) = prog else {
break;
};
Expand Down Expand Up @@ -1576,6 +1576,7 @@ fn exec_linker(
sess: &Session,
cmd: &Command,
out_filename: &Path,
flavor: LinkerFlavor,
tmpdir: &Path,
) -> io::Result<Output> {
// When attempting to spawn the linker we run a risk of blowing out the
Expand All @@ -1584,9 +1585,9 @@ fn exec_linker(
//
// Here we attempt to handle errors from the OS saying "your list of
// arguments is too big" by reinvoking the linker again with an `@`-file
// that contains all the arguments. The theory is that this is then
// accepted on all linkers and the linker will read all its options out of
// there instead of looking at the command line.
// that contains all the arguments (aka 'response' files).
// The theory is that this is then accepted on all linkers and the linker
// will read all its options out of there instead of looking at the command line.
if !cmd.very_likely_to_exceed_some_spawn_limit() {
match cmd.command().stdout(Stdio::piped()).stderr(Stdio::piped()).spawn() {
Ok(child) => {
Expand All @@ -1606,8 +1607,12 @@ fn exec_linker(
let mut args = String::new();
for arg in cmd2.take_args() {
args.push_str(
&Escape { arg: arg.to_str().unwrap(), is_like_msvc: sess.target.is_like_msvc }
.to_string(),
&Escape {
arg: arg.to_str().unwrap(),
// LLD also uses MSVC-like parsing for @-files by default when running on windows hosts
is_like_msvc: sess.target.is_like_msvc || (cfg!(windows) && flavor.uses_lld()),
}
.to_string(),
);
args.push('\n');
}
Expand Down