Skip to content

Commit

Permalink
trans: Set COMDAT section for weak symbols so that Windows can handle…
Browse files Browse the repository at this point in the history
… them.
  • Loading branch information
michaelwoerister committed Jul 8, 2016
1 parent 4c27a3c commit b149b9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/librustc_trans/closure.rs
Expand Up @@ -212,6 +212,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,

let llfn = get_or_create_closure_declaration(ccx, closure_def_id, closure_substs);
llvm::SetLinkage(llfn, llvm::WeakODRLinkage);
llvm::SetUniqueComdat(ccx.llmod(), llfn);

// Get the type of this closure. Use the current `param_substs` as
// the closure substitutions. This makes sense because the closure
Expand Down
10 changes: 9 additions & 1 deletion src/librustc_trans/trans_item.rs
Expand Up @@ -190,9 +190,13 @@ impl<'a, 'tcx> TransItem<'tcx> {
}) => {
let lldecl = declare::declare_fn(ccx, symbol_name, mono_ty);
llvm::SetLinkage(lldecl, linkage);
attributes::from_fn_attrs(ccx, attrs, lldecl);
base::set_link_section(ccx, lldecl, attrs);
if linkage == llvm::LinkOnceODRLinkage ||
linkage == llvm::WeakODRLinkage {
llvm::SetUniqueComdat(ccx.llmod(), lldecl);
}

attributes::from_fn_attrs(ccx, attrs, lldecl);
ccx.instances().borrow_mut().insert(instance, lldecl);
}
_ => bug!("Invalid item for TransItem::Fn: `{:?}`", map_node)
Expand Down Expand Up @@ -223,6 +227,10 @@ impl<'a, 'tcx> TransItem<'tcx> {
assert!(declare::get_defined_value(ccx, symbol_name).is_none());
let llfn = declare::declare_cfn(ccx, symbol_name, llfnty);
llvm::SetLinkage(llfn, linkage);
if linkage == llvm::LinkOnceODRLinkage ||
linkage == llvm::WeakODRLinkage {
llvm::SetUniqueComdat(ccx.llmod(), llfn);
}
attributes::set_frame_pointer_elimination(ccx, llfn);
ccx.drop_glues().borrow_mut().insert(dg, (llfn, fn_ty));
}
Expand Down

0 comments on commit b149b9d

Please sign in to comment.