Skip to content

Commit 7c98b82

Browse files
committed
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.
1 parent e3df96c commit 7c98b82

File tree

1 file changed

+11
-6
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+11
-6
lines changed

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 on windows
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)