@@ -503,14 +503,9 @@ void ObjFile::handleComdatSelection(
503
503
SectionChunk *leaderChunk = nullptr ;
504
504
COMDATType leaderSelection = IMAGE_COMDAT_SELECT_ANY;
505
505
506
- if (leader->data ) {
507
- leaderChunk = leader->getChunk ();
508
- leaderSelection = leaderChunk->selection ;
509
- } else {
510
- // FIXME: comdats from LTO files don't know their selection; treat them
511
- // as "any".
512
- selection = leaderSelection;
513
- }
506
+ assert (leader->data && " Comdat leader without SectionChunk?" );
507
+ leaderChunk = leader->getChunk ();
508
+ leaderSelection = leaderChunk->selection ;
514
509
515
510
if ((selection == IMAGE_COMDAT_SELECT_ANY &&
516
511
leaderSelection == IMAGE_COMDAT_SELECT_LARGEST) ||
@@ -1051,10 +1046,22 @@ class FakeSection {
1051
1046
coff_section section;
1052
1047
};
1053
1048
1049
+ // Convenience class for initializing a SectionChunk with specific flags.
1050
+ class FakeSectionChunk {
1051
+ public:
1052
+ FakeSectionChunk (const coff_section *section) : chunk(nullptr , section) {
1053
+ // FIXME: comdats from LTO files don't know their selection; treat them
1054
+ // as "any".
1055
+ chunk.selection = IMAGE_COMDAT_SELECT_ANY;
1056
+ }
1057
+
1058
+ SectionChunk chunk;
1059
+ };
1060
+
1054
1061
FakeSection ltoTextSection (IMAGE_SCN_MEM_EXECUTE);
1055
1062
FakeSection ltoDataSection (IMAGE_SCN_CNT_INITIALIZED_DATA);
1056
- SectionChunk ltoTextSectionChunk (nullptr , <oTextSection.section);
1057
- SectionChunk ltoDataSectionChunk (nullptr , <oDataSection.section);
1063
+ FakeSectionChunk ltoTextSectionChunk (<oTextSection.section);
1064
+ FakeSectionChunk ltoDataSectionChunk (<oDataSection.section);
1058
1065
} // namespace
1059
1066
1060
1067
void BitcodeFile::parse () {
@@ -1069,9 +1076,9 @@ void BitcodeFile::parse() {
1069
1076
Symbol *sym;
1070
1077
SectionChunk *fakeSC = nullptr ;
1071
1078
if (objSym.isExecutable ())
1072
- fakeSC = <oTextSectionChunk;
1079
+ fakeSC = <oTextSectionChunk. chunk ;
1073
1080
else
1074
- fakeSC = <oDataSectionChunk;
1081
+ fakeSC = <oDataSectionChunk. chunk ;
1075
1082
if (objSym.isUndefined ()) {
1076
1083
sym = symtab->addUndefined (symName, this , false );
1077
1084
} else if (objSym.isCommon ()) {
@@ -1083,12 +1090,15 @@ void BitcodeFile::parse() {
1083
1090
Symbol *alias = symtab->addUndefined (saver.save (fallback));
1084
1091
checkAndSetWeakAlias (symtab, this , sym, alias);
1085
1092
} else if (comdatIndex != -1 ) {
1086
- if (symName == obj->getComdatTable ()[comdatIndex])
1093
+ if (symName == obj->getComdatTable ()[comdatIndex]) {
1087
1094
sym = comdat[comdatIndex].first ;
1088
- else if (comdat[comdatIndex].second )
1095
+ if (cast<DefinedRegular>(sym)->data == nullptr )
1096
+ cast<DefinedRegular>(sym)->data = &fakeSC->repl ;
1097
+ } else if (comdat[comdatIndex].second ) {
1089
1098
sym = symtab->addRegular (this , symName, nullptr , fakeSC);
1090
- else
1099
+ } else {
1091
1100
sym = symtab->addUndefined (symName, this , false );
1101
+ }
1092
1102
} else {
1093
1103
sym = symtab->addRegular (this , symName, nullptr , fakeSC);
1094
1104
}
0 commit comments