Skip to content

Commit

Permalink
Use the linkage and visibility produced by tcx.collect_and_partition_…
Browse files Browse the repository at this point in the history
…mono_itemscc rust-lang#209
  • Loading branch information
bjorn3 committed Dec 23, 2018
1 parent 0b4ede3 commit 3d05ff9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
pub fn trans_mono_item<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
cx: &mut crate::CodegenCx<'a, 'clif, 'tcx, B>,
mono_item: MonoItem<'tcx>,
linkage: Linkage,
) {
let tcx = cx.tcx;
match mono_item {
Expand Down Expand Up @@ -42,7 +43,7 @@ pub fn trans_mono_item<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
}
});

trans_fn(cx, inst);
trans_fn(cx, inst, linkage);
}
MonoItem::Static(def_id) => {
crate::constant::codegen_static(&mut cx.ccx, def_id);
Expand All @@ -56,6 +57,7 @@ pub fn trans_mono_item<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
cx: &mut crate::CodegenCx<'a, 'clif, 'tcx, B>,
instance: Instance<'tcx>,
linkage: Linkage,
) {
let tcx = cx.tcx;

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

// Step 3. Make FunctionBuilder
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,17 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
) {
let mut cx = CodegenCx::new(tcx, module);
time("codegen mono items", move || {
for (mono_item, (_linkage, _vis)) in mono_items {
for (mono_item, (linkage, vis)) in mono_items {
unimpl::try_unimpl(tcx, log, || {
base::trans_mono_item(&mut cx, mono_item);
let linkage = match (linkage, vis) {
(RLinkage::External, Visibility::Default) => Linkage::Export,
(RLinkage::Internal, Visibility::Default) => Linkage::Local,
// FIXME this should get external linkage, but hidden visibility,
// not internal linkage and default visibility
| (RLinkage::External, Visibility::Hidden) => Linkage::Local,
_ => panic!("{:?} = {:?} {:?}", mono_item, linkage, vis),
};
base::trans_mono_item(&mut cx, mono_item, linkage);
});
}

Expand Down

0 comments on commit 3d05ff9

Please sign in to comment.