@@ -561,6 +561,8 @@ class LowerTypeTestsModule {
561
561
return FunctionAnnotations.contains (V);
562
562
}
563
563
564
+ void maybeReplaceComdat (Function *F, StringRef OriginalName);
565
+
564
566
public:
565
567
LowerTypeTestsModule (Module &M, ModuleAnalysisManager &AM,
566
568
ModuleSummaryIndex *ExportSummary,
@@ -1082,6 +1084,23 @@ void LowerTypeTestsModule::importTypeTest(CallInst *CI) {
1082
1084
}
1083
1085
}
1084
1086
1087
+ void LowerTypeTestsModule::maybeReplaceComdat (Function *F,
1088
+ StringRef OriginalName) {
1089
+ // For COFF we should also rename the comdat if this function also
1090
+ // happens to be the key function. Even if the comdat name changes, this
1091
+ // should still be fine since comdat and symbol resolution happens
1092
+ // before LTO, so all symbols which would prevail have been selected.
1093
+ if (F->hasComdat () && ObjectFormat == Triple::COFF &&
1094
+ F->getComdat ()->getName () == OriginalName) {
1095
+ Comdat *OldComdat = F->getComdat ();
1096
+ Comdat *NewComdat = M.getOrInsertComdat (F->getName ());
1097
+ for (GlobalObject &GO : M.global_objects ()) {
1098
+ if (GO.getComdat () == OldComdat)
1099
+ GO.setComdat (NewComdat);
1100
+ }
1101
+ }
1102
+ }
1103
+
1085
1104
// ThinLTO backend: the function F has a jump table entry; update this module
1086
1105
// accordingly. isJumpTableCanonical describes the type of the jump table entry.
1087
1106
void LowerTypeTestsModule::importFunction (
@@ -1115,6 +1134,7 @@ void LowerTypeTestsModule::importFunction(
1115
1134
FDecl->setVisibility (GlobalValue::HiddenVisibility);
1116
1135
} else {
1117
1136
F->setName (Name + " .cfi" );
1137
+ maybeReplaceComdat (F, Name);
1118
1138
F->setLinkage (GlobalValue::ExternalLinkage);
1119
1139
FDecl = Function::Create (F->getFunctionType (), GlobalValue::ExternalLinkage,
1120
1140
F->getAddressSpace (), Name, &M);
@@ -1734,19 +1754,7 @@ void LowerTypeTestsModule::buildBitSetsFromFunctionsNative(
1734
1754
FAlias->takeName (F);
1735
1755
if (FAlias->hasName ()) {
1736
1756
F->setName (FAlias->getName () + " .cfi" );
1737
- // For COFF we should also rename the comdat if this function also
1738
- // happens to be the key function. Even if the comdat name changes, this
1739
- // should still be fine since comdat and symbol resolution happens
1740
- // before LTO, so all symbols which would prevail have been selected.
1741
- if (F->hasComdat () && ObjectFormat == Triple::COFF &&
1742
- F->getComdat ()->getName () == FAlias->getName ()) {
1743
- Comdat *OldComdat = F->getComdat ();
1744
- Comdat *NewComdat = M.getOrInsertComdat (F->getName ());
1745
- for (GlobalObject &GO : M.global_objects ()) {
1746
- if (GO.getComdat () == OldComdat)
1747
- GO.setComdat (NewComdat);
1748
- }
1749
- }
1757
+ maybeReplaceComdat (F, FAlias->getName ());
1750
1758
}
1751
1759
replaceCfiUses (F, FAlias, IsJumpTableCanonical);
1752
1760
if (!F->hasLocalLinkage ())
0 commit comments