3030#include " swift/AST/IRGenOptions.h"
3131#include " swift/Basic/Assertions.h"
3232#include " swift/IRGen/GenericRequirement.h"
33+ #include " swift/IRGen/Linking.h"
3334#include " swift/SIL/SILModule.h"
3435
3536using namespace swift ;
@@ -489,6 +490,22 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction(
489490 paramTys.push_back (ptrTy);
490491 collector.addPolymorphicParameterTypes (paramTys);
491492
493+ IRLinkage *linkage = nullptr ;
494+ IRLinkage privateLinkage = {
495+ llvm::GlobalValue::PrivateLinkage,
496+ llvm::GlobalValue::DefaultVisibility,
497+ llvm::GlobalValue::DefaultStorageClass,
498+ };
499+ auto &TL =
500+ getSILModule ().Types .getTypeLowering (T, TypeExpansionContext::minimal ());
501+ // Opaque result types might lead to different expansions in different files.
502+ // The default hidden linkonce_odr might lead to linking an implementation
503+ // from another file that head a different expansion/different
504+ // signature/different implementation.
505+ if (TL.getRecursiveProperties ().isTypeExpansionSensitive ()) {
506+ linkage = &privateLinkage;
507+ }
508+
492509 return getOrCreateHelperFunction (funcName, ptrTy, paramTys,
493510 [&](IRGenFunction &IGF) {
494511 auto params = IGF.collectParameters ();
@@ -500,7 +517,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction(
500517 },
501518 true /* setIsNoInline*/ ,
502519 false /* forPrologue*/ ,
503- collector.IGF .isPerformanceConstraint );
520+ collector.IGF .isPerformanceConstraint ,
521+ linkage);
504522}
505523
506524void TypeInfo::callOutlinedDestroy (IRGenFunction &IGF,
@@ -544,6 +562,22 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedDestroyFunction(
544562 auto funcName = mangler.mangleOutlinedDestroyFunction (manglingBits.first ,
545563 manglingBits.second , collector.IGF .isPerformanceConstraint );
546564
565+ IRLinkage *linkage = nullptr ;
566+ IRLinkage privateLinkage = {
567+ llvm::GlobalValue::PrivateLinkage,
568+ llvm::GlobalValue::DefaultVisibility,
569+ llvm::GlobalValue::DefaultStorageClass,
570+ };
571+ auto &TL =
572+ getSILModule ().Types .getTypeLowering (T, TypeExpansionContext::minimal ());
573+ // Opaque result types might lead to different expansions in different files.
574+ // The default hidden linkonce_odr might lead to linking an implementation
575+ // from another file that head a different expansion/different
576+ // signature/different implementation.
577+ if (TL.getRecursiveProperties ().isTypeExpansionSensitive ()) {
578+ linkage = &privateLinkage;
579+ }
580+
547581 auto ptrTy = ti.getStorageType ()->getPointerTo ();
548582 llvm::SmallVector<llvm::Type *, 4 > paramTys;
549583 paramTys.push_back (ptrTy);
@@ -565,7 +599,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedDestroyFunction(
565599 },
566600 true /* setIsNoInline*/ ,
567601 false /* forPrologue*/ ,
568- collector.IGF .isPerformanceConstraint );
602+ collector.IGF .isPerformanceConstraint ,
603+ linkage);
569604}
570605
571606llvm::Constant *IRGenModule::getOrCreateRetainFunction (const TypeInfo &ti,
0 commit comments