@@ -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