Skip to content

Commit 7d01878

Browse files
committed
Auto merge of #122596 - rcxdude:master, r=petrochenkov
Use MSVC-style escaping when passing a response/@ file to lld on windows LLD parses @ files like the command arguments on the platform it's on, so on windows it needs to follow the MSVC style to work correctly. Otherwise builds can fail if the linker command gets too long and the build path contains spaces.
2 parents 2627e9f + 6b0a706 commit 7d01878

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

compiler/rustc_codegen_ssa/src/back/command.rs

-6
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ impl Command {
100100
Program::Lld(ref p, flavor) => {
101101
let mut c = process::Command::new(p);
102102
c.arg("-flavor").arg(flavor.as_str());
103-
if let LldFlavor::Wasm = flavor {
104-
// LLVM expects host-specific formatting for @file
105-
// arguments, but we always generate posix formatted files
106-
// at this time. Indicate as such.
107-
c.arg("--rsp-quoting=posix");
108-
}
109103
c
110104
}
111105
};

compiler/rustc_codegen_ssa/src/back/link.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ fn link_natively<'a>(
785785
let mut i = 0;
786786
loop {
787787
i += 1;
788-
prog = sess.time("run_linker", || exec_linker(sess, &cmd, out_filename, tmpdir));
788+
prog = sess.time("run_linker", || exec_linker(sess, &cmd, out_filename, flavor, tmpdir));
789789
let Ok(ref output) = prog else {
790790
break;
791791
};
@@ -1576,6 +1576,7 @@ fn exec_linker(
15761576
sess: &Session,
15771577
cmd: &Command,
15781578
out_filename: &Path,
1579+
flavor: LinkerFlavor,
15791580
tmpdir: &Path,
15801581
) -> io::Result<Output> {
15811582
// When attempting to spawn the linker we run a risk of blowing out the
@@ -1584,9 +1585,9 @@ fn exec_linker(
15841585
//
15851586
// Here we attempt to handle errors from the OS saying "your list of
15861587
// arguments is too big" by reinvoking the linker again with an `@`-file
1587-
// that contains all the arguments. The theory is that this is then
1588-
// accepted on all linkers and the linker will read all its options out of
1589-
// there instead of looking at the command line.
1588+
// that contains all the arguments (aka 'response' files).
1589+
// The theory is that this is then accepted on all linkers and the linker
1590+
// will read all its options out of there instead of looking at the command line.
15901591
if !cmd.very_likely_to_exceed_some_spawn_limit() {
15911592
match cmd.command().stdout(Stdio::piped()).stderr(Stdio::piped()).spawn() {
15921593
Ok(child) => {
@@ -1606,8 +1607,12 @@ fn exec_linker(
16061607
let mut args = String::new();
16071608
for arg in cmd2.take_args() {
16081609
args.push_str(
1609-
&Escape { arg: arg.to_str().unwrap(), is_like_msvc: sess.target.is_like_msvc }
1610-
.to_string(),
1610+
&Escape {
1611+
arg: arg.to_str().unwrap(),
1612+
// LLD also uses MSVC-like parsing for @-files by default when running on windows hosts
1613+
is_like_msvc: sess.target.is_like_msvc || (cfg!(windows) && flavor.uses_lld()),
1614+
}
1615+
.to_string(),
16111616
);
16121617
args.push('\n');
16131618
}

0 commit comments

Comments
 (0)