Skip to content

Commit cd85120

Browse files
committed
trans: always register an item's symbol, even if duplicated.
1 parent adb0923 commit cd85120

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

src/librustc_trans/callee.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -582,15 +582,19 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
582582
debug!("get_fn: not casting pointer!");
583583

584584
attributes::from_fn_attrs(ccx, attrs, llfn);
585-
if let Some(id) = local_item {
585+
if local_item.is_some() {
586586
// FIXME(eddyb) Doubt all extern fn should allow unwinding.
587587
attributes::unwind(llfn, true);
588-
ccx.item_symbols().borrow_mut().insert(id, sym);
589588
}
590589

591590
llfn
592591
};
593592

593+
// Always insert into item_symbols, in case this item is exported.
594+
if let Some(id) = local_item {
595+
ccx.item_symbols().borrow_mut().insert(id, sym);
596+
}
597+
594598
ccx.instances().borrow_mut().insert(instance, llfn);
595599

596600
immediate_rvalue(llfn, fn_ptr_ty)

src/test/auxiliary/foreign_lib.rs

+27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![crate_name="foreign_lib"]
12+
1213
#![feature(libc)]
1314

1415
pub mod rustrt {
@@ -19,3 +20,29 @@ pub mod rustrt {
1920
pub fn rust_get_test_int() -> libc::intptr_t;
2021
}
2122
}
23+
24+
pub mod rustrt2 {
25+
extern crate libc;
26+
27+
extern {
28+
pub fn rust_get_test_int() -> libc::intptr_t;
29+
}
30+
}
31+
32+
pub mod rustrt3 {
33+
// Different type, but same ABI (on all supported platforms).
34+
// Ensures that we don't ICE or trigger LLVM asserts when
35+
// importing the same symbol under different types.
36+
// See https://github.com/rust-lang/rust/issues/32740.
37+
extern {
38+
pub fn rust_get_test_int() -> *const u8;
39+
}
40+
}
41+
42+
pub fn local_uses() {
43+
unsafe {
44+
let x = rustrt::rust_get_test_int();
45+
assert_eq!(x, rustrt2::rust_get_test_int());
46+
assert_eq!(x as *const _, rustrt3::rust_get_test_int());
47+
}
48+
}

src/test/run-pass/foreign-dupe.rs

+7-30
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// calling pin_thread and that's having weird side-effects.
11+
// aux-build:foreign_lib.rs
1212

13-
#![feature(libc)]
13+
// Check that we can still call duplicated extern (imported) functions
14+
// which were declared in another crate. See issues #32740 and #32783.
1415

15-
mod rustrt1 {
16-
extern crate libc;
1716

18-
#[link(name = "rust_test_helpers")]
19-
extern {
20-
pub fn rust_get_test_int() -> libc::intptr_t;
21-
}
22-
}
23-
24-
mod rustrt2 {
25-
extern crate libc;
26-
27-
extern {
28-
pub fn rust_get_test_int() -> libc::intptr_t;
29-
}
30-
}
31-
32-
mod rustrt3 {
33-
// Different type, but same ABI (on all supported platforms).
34-
// Ensures that we don't ICE or trigger LLVM asserts when
35-
// importing the same symbol under different types.
36-
// See https://github.com/rust-lang/rust/issues/32740.
37-
extern {
38-
pub fn rust_get_test_int() -> *const u8;
39-
}
40-
}
17+
extern crate foreign_lib;
4118

4219
pub fn main() {
4320
unsafe {
44-
let x = rustrt1::rust_get_test_int();
45-
assert_eq!(x, rustrt2::rust_get_test_int());
46-
assert_eq!(x as *const _, rustrt3::rust_get_test_int());
21+
let x = foreign_lib::rustrt::rust_get_test_int();
22+
assert_eq!(x, foreign_lib::rustrt2::rust_get_test_int());
23+
assert_eq!(x as *const _, foreign_lib::rustrt3::rust_get_test_int());
4724
}
4825
}

0 commit comments

Comments
 (0)