Skip to content

Commit 5e1440a

Browse files
committedDec 1, 2024
Auto merge of #133703 - matthiaskrgr:rollup-fwlw0mc, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #132974 (Properly pass linker arguments that contain commas) - #133403 (Make `adjust_fulfillment_errors` work with `HostEffectPredicate` and `const_conditions`) - #133482 (Only error raw lifetime followed by `\'` in edition 2021+) - #133595 (Do not emit `missing_doc_code_examples` rustdoc lint on module and a few other items) - #133669 (Move some functions out of const_swap feature gate) - #133674 (Fix chaining `carrying_add`s) - #133691 (Check let source before suggesting annotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1555074 + 78dad1e commit 5e1440a

File tree

69 files changed

+704
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+704
-333
lines changed
 

‎compiler/rustc_codegen_ssa/src/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ fn link_sanitizer_runtime(
13861386
let filename = format!("rustc{channel}_rt.{name}");
13871387
let path = find_sanitizer_runtime(sess, &filename);
13881388
let rpath = path.to_str().expect("non-utf8 component in path");
1389-
linker.cc_args(&["-Wl,-rpath", "-Xlinker", rpath]);
1389+
linker.link_args(&["-rpath", rpath]);
13901390
linker.link_dylib_by_name(&filename, false, true);
13911391
} else if sess.target.is_like_msvc && flavor == LinkerFlavor::Msvc(Lld::No) && name == "asan" {
13921392
// MSVC provides the `/INFERASANLIBS` argument to automatically find the
@@ -2210,7 +2210,7 @@ fn add_rpath_args(
22102210
is_like_osx: sess.target.is_like_osx,
22112211
linker_is_gnu: sess.target.linker_flavor.is_gnu(),
22122212
};
2213-
cmd.cc_args(&rpath::get_rpath_flags(&rpath_config));
2213+
cmd.link_args(&rpath::get_rpath_linker_args(&rpath_config));
22142214
}
22152215
}
22162216

‎compiler/rustc_codegen_ssa/src/back/linker.rs

+36-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ use super::command::Command;
2424
use super::symbol_export;
2525
use crate::errors;
2626

27+
#[cfg(test)]
28+
mod tests;
29+
2730
/// Disables non-English messages from localized linkers.
2831
/// Such messages may cause issues with text encoding on Windows (#35785)
2932
/// and prevent inspection of linker output in case of errors, which we occasionally do.
@@ -178,23 +181,42 @@ fn verbatim_args<L: Linker + ?Sized>(
178181
}
179182
l
180183
}
184+
/// Add underlying linker arguments to C compiler command, by wrapping them in
185+
/// `-Wl` or `-Xlinker`.
186+
fn convert_link_args_to_cc_args(cmd: &mut Command, args: impl IntoIterator<Item: AsRef<OsStr>>) {
187+
let mut combined_arg = OsString::from("-Wl");
188+
for arg in args {
189+
// If the argument itself contains a comma, we need to emit it
190+
// as `-Xlinker`, otherwise we can use `-Wl`.
191+
if arg.as_ref().as_encoded_bytes().contains(&b',') {
192+
// Emit current `-Wl` argument, if any has been built.
193+
if combined_arg != OsStr::new("-Wl") {
194+
cmd.arg(combined_arg);
195+
// Begin next `-Wl` argument.
196+
combined_arg = OsString::from("-Wl");
197+
}
198+
199+
// Emit `-Xlinker` argument.
200+
cmd.arg("-Xlinker");
201+
cmd.arg(arg);
202+
} else {
203+
// Append to `-Wl` argument.
204+
combined_arg.push(",");
205+
combined_arg.push(arg);
206+
}
207+
}
208+
// Emit final `-Wl` argument.
209+
if combined_arg != OsStr::new("-Wl") {
210+
cmd.arg(combined_arg);
211+
}
212+
}
181213
/// Arguments for the underlying linker.
182214
/// Add options to pass them through cc wrapper if `Linker` is a cc wrapper.
183-
fn link_args<L: Linker + ?Sized>(
184-
l: &mut L,
185-
args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>,
186-
) -> &mut L {
187-
let args = args.into_iter();
215+
fn link_args<L: Linker + ?Sized>(l: &mut L, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut L {
188216
if !l.is_cc() {
189217
verbatim_args(l, args);
190-
} else if args.len() != 0 {
191-
// FIXME: Support arguments with commas, see `rpaths_to_flags` for the example.
192-
let mut combined_arg = OsString::from("-Wl");
193-
for arg in args {
194-
combined_arg.push(",");
195-
combined_arg.push(arg);
196-
}
197-
l.cmd().arg(combined_arg);
218+
} else {
219+
convert_link_args_to_cc_args(l.cmd(), args);
198220
}
199221
l
200222
}
@@ -224,7 +246,7 @@ macro_rules! generate_arg_methods {
224246
verbatim_args(self, iter::once(arg))
225247
}
226248
#[allow(unused)]
227-
pub(crate) fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>) -> &mut Self {
249+
pub(crate) fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
228250
link_args(self, args)
229251
}
230252
#[allow(unused)]

0 commit comments

Comments
 (0)