@@ -118,32 +118,31 @@ struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
118118DenseMap<const InputSection *, int > lld::macho::runBalancedPartitioning (
119119 StringRef profilePath, bool forFunctionCompression, bool forDataCompression,
120120 bool compressionSortStartupFunctions, bool verbose) {
121+ // Collect candidate sections and associated symbols.
121122 SmallVector<InputSection *> sections;
122- DenseMap<StringRef , DenseSet<unsigned >> symbolToSectionIdxs ;
123+ DenseMap<CachedHashStringRef , DenseSet<unsigned >> rootSymbolToSectionIdxs ;
123124 for (const auto *file : inputFiles) {
124125 for (auto *sec : file->sections ) {
125126 for (auto &subsec : sec->subsections ) {
126127 auto *isec = subsec.isec ;
127128 if (!isec || isec->data .empty ())
128129 continue ;
129- for (auto *sym : BPOrdererMachO::getSymbols (*isec))
130- symbolToSectionIdxs[sym->getName ()].insert (sections.size ());
130+ size_t idx = sections.size ();
131131 sections.emplace_back (isec);
132+ for (auto *sym : BPOrdererMachO::getSymbols (*isec)) {
133+ auto rootName = getRootSymbol (sym->getName ());
134+ rootSymbolToSectionIdxs[CachedHashStringRef (rootName)].insert (idx);
135+ if (auto linkageName =
136+ BPOrdererMachO::getResolvedLinkageName (rootName))
137+ rootSymbolToSectionIdxs[CachedHashStringRef (*linkageName)].insert (
138+ idx);
139+ }
132140 }
133141 }
134142 }
135143
136- DenseMap<CachedHashStringRef, DenseSet<unsigned >> rootSymbolToSectionIdxs;
137- for (auto &[name, sectionIdxs] : symbolToSectionIdxs) {
138- auto rootName = getRootSymbol (name);
139- rootSymbolToSectionIdxs[CachedHashStringRef (rootName)].insert (
140- sectionIdxs.begin (), sectionIdxs.end ());
141- if (auto linkageName = BPOrdererMachO::getResolvedLinkageName (rootName))
142- rootSymbolToSectionIdxs[CachedHashStringRef (*linkageName)].insert (
143- sectionIdxs.begin (), sectionIdxs.end ());
144- }
145- return BPOrdererMachO::reorderSections (
146- profilePath, forFunctionCompression, forDataCompression,
147- compressionSortStartupFunctions, verbose, sections,
148- rootSymbolToSectionIdxs);
144+ return BPOrdererMachO::computeOrder (profilePath, forFunctionCompression,
145+ forDataCompression,
146+ compressionSortStartupFunctions, verbose,
147+ sections, rootSymbolToSectionIdxs);
149148}
0 commit comments