From 4395c2e35405ae5eb07f8cbff145439c66f47e2a Mon Sep 17 00:00:00 2001 From: Ayrton Date: Sat, 4 Jun 2022 20:59:25 -0400 Subject: [PATCH] Allow overriding linker scripts embedded in the target --- compiler/rustc_codegen_ssa/src/back/link.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index fc30679be03cb..0c1111535516e 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1597,6 +1597,16 @@ fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) /// Add a link script embedded in the target, if applicable. fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_type: CrateType) { + fn is_script_arg(arg: &str) -> bool { + arg.starts_with("--script") + || arg.starts_with("-T") + || arg.starts_with("--default-script") + || arg.starts_with("-dT") + } + // Omit the embedded linker script if a user supplied one + if sess.opts.cg.link_args.iter().any(|arg| is_script_arg(arg)) { + return; + } match (crate_type, &sess.target.link_script) { (CrateType::Cdylib | CrateType::Executable, Some(script)) => { if !sess.target.linker_is_gnu {