[lld] r262175 - ELF: Remove OutSection class and use a map instead.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 27 21:09:12 PST 2016


Author: ruiu
Date: Sat Feb 27 23:09:11 2016
New Revision: 262175

URL: http://llvm.org/viewvc/llvm-project?rev=262175&view=rev
Log:
ELF: Remove OutSection class and use a map instead.

It is easier to handle section filler data separately rather than
merging with section names.

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/LinkerScript.h

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=262175&r1=262174&r2=262175&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sat Feb 27 23:09:11 2016
@@ -55,21 +55,20 @@ template <class ELFT> bool LinkerScript:
 }
 
 ArrayRef<uint8_t> LinkerScript::getFiller(StringRef Name) {
-  for (OutSection &C : OutSections)
-    if (C.Name == Name)
-      return C.Filler;
-  return {};
+  auto I = Filler.find(Name);
+  if (I == Filler.end())
+    return {};
+  return I->second;
 }
 
 // A compartor to sort output sections. Returns -1 or 1 if both
 // A and B are mentioned in linker scripts. Otherwise, returns 0
 // to use the default rule which is implemented in Writer.cpp.
 int LinkerScript::compareSections(StringRef A, StringRef B) {
-  auto Begin = OutSections.begin();
-  auto End = OutSections.end();
-  auto I = std::find_if(Begin, End, [&](OutSection &C) { return C.Name == A; });
-  auto J = std::find_if(Begin, End, [&](OutSection &C) { return C.Name == B; });
-  if (I == End || J == End)
+  auto E = SectionOrder.end();
+  auto I = std::find(SectionOrder.begin(), E, A);
+  auto J = std::find(SectionOrder.begin(), E, B);
+  if (I == E || J == E)
     return 0;
   return I < J ? -1 : 1;
 }
@@ -429,18 +428,18 @@ std::vector<uint8_t> ScriptParser::parse
 }
 
 void ScriptParser::readOutputSectionDescription() {
-  OutSection OutSec;
-  OutSec.Name = next();
+  StringRef OutSec = next();
+  Script->SectionOrder.push_back(OutSec);
   expect(":");
   expect("{");
   while (!Error && !skip("}")) {
     StringRef Tok = next();
     if (Tok == "*") {
-      readSectionPatterns(OutSec.Name, false);
+      readSectionPatterns(OutSec, false);
     } else if (Tok == "KEEP") {
       expect("(");
       next(); // Skip *
-      readSectionPatterns(OutSec.Name, true);
+      readSectionPatterns(OutSec, true);
       expect(")");
     } else {
       setError("Unknown command " + Tok);
@@ -452,11 +451,10 @@ void ScriptParser::readOutputSectionDesc
       setError("Filler should be a HEX value");
       return;
     }
-    Tok = Tok.substr(3); // Skip '=0x'
-    OutSec.Filler = parseHex(Tok);
+    Tok = Tok.substr(3);
+    Script->Filler[OutSec] = parseHex(Tok);
     next();
   }
-  Script->OutSections.push_back(OutSec);
 }
 
 static bool isUnderSysroot(StringRef Path) {

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=262175&r1=262174&r2=262175&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Sat Feb 27 23:09:11 2016
@@ -40,11 +40,6 @@ private:
   StringRef SectionPattern;
 };
 
-struct OutSection {
-  StringRef Name;
-  std::vector<uint8_t> Filler;
-};
-
 // This is a runner of the linker script.
 class LinkerScript {
   friend class ScriptParser;
@@ -66,9 +61,11 @@ private:
   // SECTIONS commands.
   std::vector<SectionRule> Sections;
 
-  // Output sections information.
-  // They are sorted by the order of the container.
-  std::vector<OutSection> OutSections;
+  // Output sections are sorted by this order.
+  std::vector<StringRef> SectionOrder;
+
+  // Section fill attribute for each section.
+  llvm::StringMap<std::vector<uint8_t>> Filler;
 
   llvm::BumpPtrAllocator Alloc;
 };




More information about the llvm-commits mailing list