Skip to content

Commit 775f26b

Browse files
author
Alex B
committed
[llvm-macho] move category merging after dead-stripping
1 parent 4a01d76 commit 775f26b

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lld/MachO/Driver.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,20 +1973,20 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
19731973
}
19741974

19751975
gatherInputSections();
1976+
if (config->callGraphProfileSort)
1977+
priorityBuilder.extractCallGraphProfile();
1978+
1979+
if (config->deadStrip)
1980+
markLive();
19761981

1977-
// Run category checking & merging before anything else, it operates
1978-
// directly on inputSections.
1982+
// Categories are not subject to dead-strip. The __objc_catlist section is
1983+
// marked as NO_DEAD_STRIP and that propagates into all category data.
19791984
if (args.hasArg(OPT_check_category_conflicts))
19801985
objc::checkCategories();
19811986

19821987
if (args.hasArg(OPT_merge_objc_categories))
19831988
objc::mergeCategories();
19841989

1985-
if (config->callGraphProfileSort)
1986-
priorityBuilder.extractCallGraphProfile();
1987-
1988-
if (config->deadStrip)
1989-
markLive();
19901990
// ICF assumes that all literals have been folded already, so we must run
19911991
// foldIdenticalLiterals before foldIdenticalSections.
19921992
foldIdenticalLiterals();

lld/MachO/ObjC.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ bool ObjcCategoryMerger::emitAndLinkProtocolList(Defined *parentSym,
846846
*infoCategoryWriter.catPtrListInfo.inputSection, bodyData,
847847
infoCategoryWriter.catPtrListInfo.align);
848848
listSec->parent = infoCategoryWriter.catPtrListInfo.outputSection;
849+
listSec->live = true;
849850
allInputSections.push_back(listSec);
850851

851852
listSec->parent = infoCategoryWriter.catPtrListInfo.outputSection;
@@ -861,6 +862,7 @@ bool ObjcCategoryMerger::emitAndLinkProtocolList(Defined *parentSym,
861862
/*includeInSymtab=*/true, /*isReferencedDynamically=*/false,
862863
/*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false);
863864

865+
ptrListSym->used = true;
864866
getGenObjFile()->symbols.push_back(ptrListSym);
865867

866868
if (!createSymbolReference(parentSym, ptrListSym, linkAtOffset,
@@ -910,6 +912,7 @@ bool ObjcCategoryMerger::emitAndLinkPointerList(Defined *parentSym,
910912
*infoCategoryWriter.catPtrListInfo.inputSection, bodyData,
911913
infoCategoryWriter.catPtrListInfo.align);
912914
listSec->parent = infoCategoryWriter.catPtrListInfo.outputSection;
915+
listSec->live = true;
913916
allInputSections.push_back(listSec);
914917

915918
listSec->parent = infoCategoryWriter.catPtrListInfo.outputSection;
@@ -925,6 +928,7 @@ bool ObjcCategoryMerger::emitAndLinkPointerList(Defined *parentSym,
925928
/*includeInSymtab=*/true, /*isReferencedDynamically=*/false,
926929
/*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false);
927930

931+
ptrListSym->used = true;
928932
getGenObjFile()->symbols.push_back(ptrListSym);
929933

930934
if (!createSymbolReference(parentSym, ptrListSym, linkAtOffset,
@@ -955,6 +959,7 @@ bool ObjcCategoryMerger::emitCatListEntrySec(std::string &forCateogryName,
955959
make<ConcatInputSection>(*infoCategoryWriter.catListInfo.inputSection,
956960
bodyData, infoCategoryWriter.catListInfo.align);
957961
newCatList->parent = infoCategoryWriter.catListInfo.outputSection;
962+
newCatList->live = true;
958963
allInputSections.push_back(newCatList);
959964

960965
newCatList->parent = infoCategoryWriter.catListInfo.outputSection;
@@ -971,6 +976,7 @@ bool ObjcCategoryMerger::emitCatListEntrySec(std::string &forCateogryName,
971976
/*isReferencedDynamically=*/false, /*noDeadStrip=*/false,
972977
/*isWeakDefCanBeHidden=*/false);
973978

979+
catListSym->used = true;
974980
getGenObjFile()->symbols.push_back(catListSym);
975981
return true;
976982
}
@@ -993,6 +999,7 @@ bool ObjcCategoryMerger::emitCategoryBody(std::string &name, Defined *nameSym,
993999
make<ConcatInputSection>(*infoCategoryWriter.catBodyInfo.inputSection,
9941000
bodyData, infoCategoryWriter.catBodyInfo.align);
9951001
newBodySec->parent = infoCategoryWriter.catBodyInfo.outputSection;
1002+
newBodySec->live = true;
9961003
allInputSections.push_back(newBodySec);
9971004

9981005
newBodySec->parent = infoCategoryWriter.catBodyInfo.outputSection;
@@ -1007,6 +1014,7 @@ bool ObjcCategoryMerger::emitCategoryBody(std::string &name, Defined *nameSym,
10071014
/*isReferencedDynamically=*/false, /*noDeadStrip=*/false,
10081015
/*isWeakDefCanBeHidden=*/false);
10091016

1017+
catBodySym->used = true;
10101018
getGenObjFile()->symbols.push_back(catBodySym);
10111019

10121020
if (!createSymbolReference(catBodySym, nameSym, catLayout.nameOffset,
@@ -1046,6 +1054,7 @@ bool ObjcCategoryMerger::emitCategoryName(std::string &name,
10461054
/*includeInSymtab=*/false, /*isReferencedDynamically=*/false,
10471055
/*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false);
10481056

1057+
catNamdeSym->used = true;
10491058
getGenObjFile()->symbols.push_back(catNamdeSym);
10501059
return true;
10511060
}
@@ -1184,7 +1193,7 @@ bool ObjcCategoryMerger::collectAndValidateCategoriesData() {
11841193
(a.offCatListIsec < b.offCatListIsec);
11851194
};
11861195

1187-
std::stable_sort(entry.second.begin(), entry.second.end(), cmpFn);
1196+
llvm::sort(entry.second, cmpFn);
11881197
}
11891198
}
11901199

@@ -1209,6 +1218,7 @@ bool ObjcCategoryMerger::generateCatListForNonErasedCategories(
12091218
make<ConcatInputSection>(*infoCategoryWriter.catListInfo.inputSection,
12101219
bodyData, infoCategoryWriter.catListInfo.align);
12111220
listSec->parent = infoCategoryWriter.catListInfo.outputSection;
1221+
listSec->live = true;
12121222
allInputSections.push_back(listSec);
12131223

12141224
Defined *mergedCatListSym = make<Defined>(
@@ -1218,6 +1228,7 @@ bool ObjcCategoryMerger::generateCatListForNonErasedCategories(
12181228
/*includeInSymtab=*/false, /*isReferencedDynamically=*/false,
12191229
/*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false);
12201230

1231+
mergedCatListSym->used = true;
12211232
getGenObjFile()->symbols.push_back(mergedCatListSym);
12221233

12231234
uint32_t outSecOffset = 0;

0 commit comments

Comments
 (0)