Skip to content

Commit 3d05ff9

Browse files
committed
Use the linkage and visibility produced by tcx.collect_and_partition_mono_itemscc rust-lang#209
1 parent 0b4ede3 commit 3d05ff9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/base.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
1212
pub fn trans_mono_item<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
1313
cx: &mut crate::CodegenCx<'a, 'clif, 'tcx, B>,
1414
mono_item: MonoItem<'tcx>,
15+
linkage: Linkage,
1516
) {
1617
let tcx = cx.tcx;
1718
match mono_item {
@@ -42,7 +43,7 @@ pub fn trans_mono_item<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
4243
}
4344
});
4445

45-
trans_fn(cx, inst);
46+
trans_fn(cx, inst, linkage);
4647
}
4748
MonoItem::Static(def_id) => {
4849
crate::constant::codegen_static(&mut cx.ccx, def_id);
@@ -56,6 +57,7 @@ pub fn trans_mono_item<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
5657
fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
5758
cx: &mut crate::CodegenCx<'a, 'clif, 'tcx, B>,
5859
instance: Instance<'tcx>,
60+
linkage: Linkage,
5961
) {
6062
let tcx = cx.tcx;
6163

@@ -65,7 +67,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
6567
// Step 2. Declare function
6668
let (name, sig) = get_function_name_and_sig(tcx, instance);
6769
let func_id = cx.module
68-
.declare_function(&name, Linkage::Export, &sig)
70+
.declare_function(&name, linkage, &sig)
6971
.unwrap();
7072

7173
// Step 3. Make FunctionBuilder

src/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,17 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
393393
) {
394394
let mut cx = CodegenCx::new(tcx, module);
395395
time("codegen mono items", move || {
396-
for (mono_item, (_linkage, _vis)) in mono_items {
396+
for (mono_item, (linkage, vis)) in mono_items {
397397
unimpl::try_unimpl(tcx, log, || {
398-
base::trans_mono_item(&mut cx, mono_item);
398+
let linkage = match (linkage, vis) {
399+
(RLinkage::External, Visibility::Default) => Linkage::Export,
400+
(RLinkage::Internal, Visibility::Default) => Linkage::Local,
401+
// FIXME this should get external linkage, but hidden visibility,
402+
// not internal linkage and default visibility
403+
| (RLinkage::External, Visibility::Hidden) => Linkage::Local,
404+
_ => panic!("{:?} = {:?} {:?}", mono_item, linkage, vis),
405+
};
406+
base::trans_mono_item(&mut cx, mono_item, linkage);
399407
});
400408
}
401409

0 commit comments

Comments
 (0)