[lld] r308066 - Avoid using OutputSections::Sections.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 14 15:26:16 PDT 2017


Author: rafael
Date: Fri Jul 14 15:26:16 2017
New Revision: 308066

URL: http://llvm.org/viewvc/llvm-project?rev=308066&view=rev
Log:
Avoid using OutputSections::Sections.

This code runs after clearOutputSections.

Modified:
    lld/trunk/ELF/Relocations.cpp

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=308066&r1=308065&r2=308066&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Fri Jul 14 15:26:16 2017
@@ -1000,15 +1000,19 @@ void ThunkCreator::mergeThunks() {
   }
 }
 
+static uint32_t findEndOfFirstNonExec(OutputSectionCommand &Cmd) {
+  for (BaseCommand *Base : Cmd.Commands)
+    if (auto *ISD = dyn_cast<InputSectionDescription>(Base))
+      for (auto *IS : ISD->Sections)
+        if ((IS->Flags & SHF_EXECINSTR) == 0)
+          return IS->OutSecOff + IS->getSize();
+  return 0;
+}
+
 ThunkSection *ThunkCreator::getOSThunkSec(OutputSectionCommand *Cmd,
                                           std::vector<InputSection *> *ISR) {
   if (CurTS == nullptr) {
-    uint32_t Off = 0;
-    for (auto *IS : Cmd->Sec->Sections) {
-      Off = IS->OutSecOff + IS->getSize();
-      if ((IS->Flags & SHF_EXECINSTR) == 0)
-        break;
-    }
+    uint32_t Off = findEndOfFirstNonExec(*Cmd);
     CurTS = addThunkSection(Cmd->Sec, ISR, Off);
   }
   return CurTS;




More information about the llvm-commits mailing list