@@ -38,20 +38,21 @@ lld::elf::runBalancedPartitioning(Ctx &ctx, llvm::StringRef profilePath,
3838 SmallVector<std::unique_ptr<BPSectionBase>> sections;
3939 DenseSet<const InputSectionBase *> seenSections;
4040
41+ auto addSection = [&](Symbol &sym) {
42+ if (sym.getSize () == 0 )
43+ return ;
44+ if (auto *d = dyn_cast<Defined>(&sym))
45+ if (auto *sec = dyn_cast_or_null<InputSectionBase>(d->section ))
46+ if (seenSections.insert (sec).second )
47+ sections.emplace_back (std::make_unique<BPSectionELF>(sec));
48+ };
49+
4150 for (Symbol *sym : ctx.symtab ->getSymbols ())
42- if (sym->getSize () > 0 )
43- if (auto *d = dyn_cast<Defined>(sym))
44- if (auto *sec = dyn_cast_or_null<InputSectionBase>(d->section ))
45- if (seenSections.insert (sec).second )
46- sections.emplace_back (std::make_unique<BPSectionELF>(sec));
51+ addSection (*sym);
4752
4853 for (ELFFileBase *file : ctx.objectFiles )
4954 for (Symbol *sym : file->getLocalSymbols ())
50- if (sym->getSize () > 0 )
51- if (auto *d = dyn_cast<Defined>(sym))
52- if (auto *sec = dyn_cast_or_null<InputSectionBase>(d->section ))
53- if (seenSections.insert (sec).second )
54- sections.emplace_back (std::make_unique<BPSectionELF>(sec));
55+ addSection (*sym);
5556
5657 auto reorderedSections = BPSectionBase::reorderSectionsByBalancedPartitioning (
5758 profilePath, forFunctionCompression, forDataCompression,
0 commit comments