Skip to content

Commit b149b9d

Browse files
trans: Set COMDAT section for weak symbols so that Windows can handle them.
1 parent 4c27a3c commit b149b9d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/librustc_trans/closure.rs

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
212212

213213
let llfn = get_or_create_closure_declaration(ccx, closure_def_id, closure_substs);
214214
llvm::SetLinkage(llfn, llvm::WeakODRLinkage);
215+
llvm::SetUniqueComdat(ccx.llmod(), llfn);
215216

216217
// Get the type of this closure. Use the current `param_substs` as
217218
// the closure substitutions. This makes sense because the closure

src/librustc_trans/trans_item.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,13 @@ impl<'a, 'tcx> TransItem<'tcx> {
190190
}) => {
191191
let lldecl = declare::declare_fn(ccx, symbol_name, mono_ty);
192192
llvm::SetLinkage(lldecl, linkage);
193-
attributes::from_fn_attrs(ccx, attrs, lldecl);
194193
base::set_link_section(ccx, lldecl, attrs);
194+
if linkage == llvm::LinkOnceODRLinkage ||
195+
linkage == llvm::WeakODRLinkage {
196+
llvm::SetUniqueComdat(ccx.llmod(), lldecl);
197+
}
195198

199+
attributes::from_fn_attrs(ccx, attrs, lldecl);
196200
ccx.instances().borrow_mut().insert(instance, lldecl);
197201
}
198202
_ => bug!("Invalid item for TransItem::Fn: `{:?}`", map_node)
@@ -223,6 +227,10 @@ impl<'a, 'tcx> TransItem<'tcx> {
223227
assert!(declare::get_defined_value(ccx, symbol_name).is_none());
224228
let llfn = declare::declare_cfn(ccx, symbol_name, llfnty);
225229
llvm::SetLinkage(llfn, linkage);
230+
if linkage == llvm::LinkOnceODRLinkage ||
231+
linkage == llvm::WeakODRLinkage {
232+
llvm::SetUniqueComdat(ccx.llmod(), llfn);
233+
}
226234
attributes::set_frame_pointer_elimination(ccx, llfn);
227235
ccx.drop_glues().borrow_mut().insert(dg, (llfn, fn_ty));
228236
}

0 commit comments

Comments
 (0)