[lld] r325094 - Use a stricter return type in buildSectionOrder. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 17:42:26 PST 2018


Author: rafael
Date: Tue Feb 13 17:42:26 2018
New Revision: 325094

URL: http://llvm.org/viewvc/llvm-project?rev=325094&view=rev
Log:
Use a stricter return type in buildSectionOrder. NFC.

We sort inside output sections, so all the sections we see should be
InputSectionBase.

I noticed the patch adding callgraph based section ordering used this
type and changing this separately makes the merge easier.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=325094&r1=325093&r2=325094&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Feb 13 17:42:26 2018
@@ -1017,8 +1017,8 @@ findOrphanPos(std::vector<BaseCommand *>
 }
 
 // Builds section order for handling --symbol-ordering-file.
-static DenseMap<SectionBase *, int> buildSectionOrder() {
-  DenseMap<SectionBase *, int> SectionOrder;
+static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
+  DenseMap<const InputSectionBase *, int> SectionOrder;
   if (Config->SymbolOrderingFile.empty())
     return SectionOrder;
 
@@ -1033,18 +1033,19 @@ static DenseMap<SectionBase *, int> buil
   // Build a map from sections to their priorities.
   for (InputFile *File : ObjectFiles) {
     for (Symbol *Sym : File->getSymbols()) {
-      auto *D = dyn_cast<Defined>(Sym);
-      if (!D || !D->Section)
-        continue;
-      int &Priority = SectionOrder[D->Section];
-      Priority = std::min(Priority, SymbolOrder.lookup(D->getName()));
+      if (auto *D = dyn_cast<Defined>(Sym)) {
+        if (auto *Sec = dyn_cast_or_null<InputSectionBase>(D->Section)) {
+          int &Priority = SectionOrder[Sec];
+          Priority = std::min(Priority, SymbolOrder.lookup(D->getName()));
+        }
+      }
     }
   }
   return SectionOrder;
 }
 
 static void sortSection(OutputSection *Sec,
-                        const DenseMap<SectionBase *, int> &Order) {
+                        const DenseMap<const InputSectionBase *, int> &Order) {
   if (!Sec->Live)
     return;
   StringRef Name = Sec->Name;
@@ -1078,7 +1079,7 @@ static void sortSection(OutputSection *S
 // sorting for special input sections. This also handles --symbol-ordering-file.
 template <class ELFT> void Writer<ELFT>::sortInputSections() {
   // Build the order once since it is expensive.
-  DenseMap<SectionBase *, int> Order = buildSectionOrder();
+  DenseMap<const InputSectionBase *, int> Order = buildSectionOrder();
   for (BaseCommand *Base : Script->SectionCommands)
     if (auto *Sec = dyn_cast<OutputSection>(Base))
       sortSection(Sec, Order);




More information about the llvm-commits mailing list