Rollup merge of #132974 - madsmtm:linker-arguments-with-commas, r=petrochenkov
Properly pass linker arguments that contain commas When linking with the system C compiler, we sometimes want to forward certain arguments unchanged to the linker. This can be done with `-Wl,arg1,arg2` or `-Xlinker arg1 -Xlinker arg2`. `-Wl` is used when possible, since it is more compact, but it does not support commas in the argument itself - in those cases, we need to use `-Xlinker`, and that is what this PR implements. This also fixes using sanitizers on macOS with `-Clinker-flavor=ld`, as those were previously manually using `-Wl`/`-Xlinker` (probably since the support wasn't present in the `link_args` function). Note that there has been [a previous PR for this](https://github.com/rust-lang/rust/pull/38798), but it only implemented this in certain cases when passing `-rpath`. r? compiler
This commit is contained in:
@@ -1386,7 +1386,7 @@ fn link_sanitizer_runtime(
|
||||
let filename = format!("rustc{channel}_rt.{name}");
|
||||
let path = find_sanitizer_runtime(sess, &filename);
|
||||
let rpath = path.to_str().expect("non-utf8 component in path");
|
||||
linker.cc_args(&["-Wl,-rpath", "-Xlinker", rpath]);
|
||||
linker.link_args(&["-rpath", rpath]);
|
||||
linker.link_dylib_by_name(&filename, false, true);
|
||||
} else if sess.target.is_like_msvc && flavor == LinkerFlavor::Msvc(Lld::No) && name == "asan" {
|
||||
// MSVC provides the `/INFERASANLIBS` argument to automatically find the
|
||||
@@ -2210,7 +2210,7 @@ fn add_rpath_args(
|
||||
is_like_osx: sess.target.is_like_osx,
|
||||
linker_is_gnu: sess.target.linker_flavor.is_gnu(),
|
||||
};
|
||||
cmd.cc_args(&rpath::get_rpath_flags(&rpath_config));
|
||||
cmd.link_args(&rpath::get_rpath_linker_args(&rpath_config));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user