diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index e505543b27ca7..e0bd7a33f7373 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -439,7 +439,10 @@ impl<'a> Linker for GccLinker<'a> { } } self.hint_dynamic(); - self.cmd.arg(format!("-l{}{}", if verbatim { ":" } else { "" }, lib)); + self.cmd.arg(format!( + "-l{}{lib}", + if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" }, + )); if !as_needed { if self.sess.target.is_like_osx { // See above FIXME comment @@ -450,7 +453,10 @@ impl<'a> Linker for GccLinker<'a> { } fn link_staticlib(&mut self, lib: &str, verbatim: bool) { self.hint_static(); - self.cmd.arg(format!("-l{}{}", if verbatim { ":" } else { "" }, lib)); + self.cmd.arg(format!( + "-l{}{lib}", + if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" }, + )); } fn link_rlib(&mut self, lib: &Path) { self.hint_static(); @@ -504,10 +510,10 @@ impl<'a> Linker for GccLinker<'a> { self.hint_static(); let target = &self.sess.target; if !target.is_like_osx { - self.linker_arg("--whole-archive").cmd.arg(format!( - "-l{}{}", - if verbatim { ":" } else { "" }, - lib + self.linker_arg("--whole-archive"); + self.cmd.arg(format!( + "-l{}{lib}", + if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" }, )); self.linker_arg("--no-whole-archive"); } else { diff --git a/src/test/run-make/native-link-modifier-verbatim-linker/Makefile b/src/test/run-make/native-link-modifier-verbatim-linker/Makefile new file mode 100644 index 0000000000000..e56e1e94ec5b1 --- /dev/null +++ b/src/test/run-make/native-link-modifier-verbatim-linker/Makefile @@ -0,0 +1,15 @@ +# ignore-cross-compile +# ignore-macos + +include ../../run-make-fulldeps/tools.mk + +all: + # Verbatim allows specify precise name. + $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_some_strange_name.ext + $(RUSTC) main.rs -Zunstable-options -l static:+verbatim=local_some_strange_name.ext + + # With verbatim any other name cannot be used (local). + $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/liblocal_native_dep.a + $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.a + $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.lib + $(RUSTC) main.rs -Zunstable-options -l static:+verbatim=local_native_dep 2>&1 | $(CGREP) "local_native_dep" diff --git a/src/test/run-make/native-link-modifier-verbatim/local_native_dep.rs b/src/test/run-make/native-link-modifier-verbatim-linker/local_native_dep.rs similarity index 100% rename from src/test/run-make/native-link-modifier-verbatim/local_native_dep.rs rename to src/test/run-make/native-link-modifier-verbatim-linker/local_native_dep.rs diff --git a/src/test/run-make/native-link-modifier-verbatim/main.rs b/src/test/run-make/native-link-modifier-verbatim-linker/main.rs similarity index 72% rename from src/test/run-make/native-link-modifier-verbatim/main.rs rename to src/test/run-make/native-link-modifier-verbatim-linker/main.rs index 47b44a289eda5..71b73a489c767 100644 --- a/src/test/run-make/native-link-modifier-verbatim/main.rs +++ b/src/test/run-make/native-link-modifier-verbatim-linker/main.rs @@ -1,5 +1,3 @@ -extern crate rust_dep; - extern "C" { fn local_native_f() -> i32; } @@ -8,5 +6,4 @@ pub fn main() { unsafe { assert!(local_native_f() == 0); }; - rust_dep::rust_dep() } diff --git a/src/test/run-make/native-link-modifier-verbatim-rustc/Makefile b/src/test/run-make/native-link-modifier-verbatim-rustc/Makefile new file mode 100644 index 0000000000000..1093b1cd3694d --- /dev/null +++ b/src/test/run-make/native-link-modifier-verbatim-rustc/Makefile @@ -0,0 +1,12 @@ +include ../../run-make-fulldeps/tools.mk + +all: + # Verbatim allows specify precise name. + $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_some_strange_name.ext + $(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_some_strange_name.ext --crate-type rlib + + # With verbatim any other name cannot be used (upstream). + $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/libupstream_native_dep.a + $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.a + $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.lib + $(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_native_dep --crate-type rlib 2>&1 | $(CGREP) "upstream_native_dep" diff --git a/src/test/run-make/native-link-modifier-verbatim/rust_dep.rs b/src/test/run-make/native-link-modifier-verbatim-rustc/rust_dep.rs similarity index 100% rename from src/test/run-make/native-link-modifier-verbatim/rust_dep.rs rename to src/test/run-make/native-link-modifier-verbatim-rustc/rust_dep.rs diff --git a/src/test/run-make/native-link-modifier-verbatim/upstream_native_dep.rs b/src/test/run-make/native-link-modifier-verbatim-rustc/upstream_native_dep.rs similarity index 100% rename from src/test/run-make/native-link-modifier-verbatim/upstream_native_dep.rs rename to src/test/run-make/native-link-modifier-verbatim-rustc/upstream_native_dep.rs diff --git a/src/test/run-make/native-link-modifier-verbatim/Makefile b/src/test/run-make/native-link-modifier-verbatim/Makefile deleted file mode 100644 index b67b022c659cb..0000000000000 --- a/src/test/run-make/native-link-modifier-verbatim/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# ignore-cross-compile -# ignore-macos - -include ../../run-make-fulldeps/tools.mk - -all: - # Verbatim allows specify precise name. - $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_some_strange_name.ext - $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_some_strange_name.ext - $(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_some_strange_name.ext --crate-type rlib - $(RUSTC) main.rs --extern rust_dep=$(TMPDIR)/librust_dep.rlib -Zunstable-options -l static:+verbatim=local_some_strange_name.ext - rm $(TMPDIR)/*some_strange_name.ext - - # With verbatim any other name cannot be used (local). - $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/liblocal_native_dep.a - $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.a - $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep - $(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_native_dep --crate-type rlib - $(RUSTC) main.rs --extern rust_dep=$(TMPDIR)/librust_dep.rlib -Zunstable-options -l static:+verbatim=local_native_dep 2>&1 | $(CGREP) "local_native_dep" - rm $(TMPDIR)/*native_dep* - - # With verbatim any other name cannot be used (upstream). - $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep - $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/libupstream_native_dep.a - $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.a - $(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_native_dep --crate-type rlib 2>&1 | $(CGREP) "upstream_native_dep" - rm $(TMPDIR)/*native_dep*