Skip to content

Commit f55797c

Browse files
committed
fix
1 parent 6515270 commit f55797c

File tree

8 files changed

+39
-36
lines changed

8 files changed

+39
-36
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,10 @@ impl<'a> Linker for GccLinker<'a> {
439439
}
440440
}
441441
self.hint_dynamic();
442-
self.cmd.arg(format!("-l{}{}", if verbatim { ":" } else { "" }, lib));
442+
self.cmd.arg(format!(
443+
"-l{}{lib}",
444+
if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" },
445+
));
443446
if !as_needed {
444447
if self.sess.target.is_like_osx {
445448
// See above FIXME comment
@@ -450,7 +453,10 @@ impl<'a> Linker for GccLinker<'a> {
450453
}
451454
fn link_staticlib(&mut self, lib: &str, verbatim: bool) {
452455
self.hint_static();
453-
self.cmd.arg(format!("-l{}{}", if verbatim { ":" } else { "" }, lib));
456+
self.cmd.arg(format!(
457+
"-l{}{lib}",
458+
if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" },
459+
));
454460
}
455461
fn link_rlib(&mut self, lib: &Path) {
456462
self.hint_static();
@@ -504,10 +510,10 @@ impl<'a> Linker for GccLinker<'a> {
504510
self.hint_static();
505511
let target = &self.sess.target;
506512
if !target.is_like_osx {
507-
self.linker_arg("--whole-archive").cmd.arg(format!(
508-
"-l{}{}",
509-
if verbatim { ":" } else { "" },
510-
lib
513+
self.linker_arg("--whole-archive");
514+
self.cmd.arg(format!(
515+
"-l{}{lib}",
516+
if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" },
511517
));
512518
self.linker_arg("--no-whole-archive");
513519
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ignore-cross-compile
2+
# ignore-macos
3+
4+
include ../../run-make-fulldeps/tools.mk
5+
6+
all:
7+
# Verbatim allows specify precise name.
8+
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_some_strange_name.ext
9+
$(RUSTC) main.rs -Zunstable-options -l static:+verbatim=local_some_strange_name.ext
10+
11+
# With verbatim any other name cannot be used (local).
12+
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/liblocal_native_dep.a
13+
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.a
14+
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.lib
15+
$(RUSTC) main.rs -Zunstable-options -l static:+verbatim=local_native_dep 2>&1 | $(CGREP) "local_native_dep"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate rust_dep;
2-
31
extern "C" {
42
fn local_native_f() -> i32;
53
}
@@ -8,5 +6,4 @@ pub fn main() {
86
unsafe {
97
assert!(local_native_f() == 0);
108
};
11-
rust_dep::rust_dep()
129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include ../../run-make-fulldeps/tools.mk
2+
3+
all:
4+
# Verbatim allows specify precise name.
5+
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_some_strange_name.ext
6+
$(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_some_strange_name.ext --crate-type rlib
7+
8+
# With verbatim any other name cannot be used (upstream).
9+
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/libupstream_native_dep.a
10+
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.a
11+
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.lib
12+
$(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_native_dep --crate-type rlib 2>&1 | $(CGREP) "upstream_native_dep"

src/test/run-make/native-link-modifier-verbatim/Makefile

-27
This file was deleted.

0 commit comments

Comments
 (0)