[lld] r304206 - [ELF] Add .ARM.exidx sentinel section to an OutputSectionDescription

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Tue May 30 04:51:03 PDT 2017


Author: psmith
Date: Tue May 30 06:51:02 2017
New Revision: 304206

URL: http://llvm.org/viewvc/llvm-project?rev=304206&view=rev
Log:
[ELF] Add .ARM.exidx sentinel section to an OutputSectionDescription
    
When there is a linker script with .ARM.exidx in the SECTIONS
command we must add the .ARM.exidx sentinel section to the
InputSectionDescriptions as well as to OutputSection::Sections.

Differential Revision: https://reviews.llvm.org/D33496


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=304206&r1=304205&r2=304206&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue May 30 06:51:02 2017
@@ -1206,8 +1206,6 @@ template <class ELFT> void Writer<ELFT>:
   if (ErrorCount)
     return;
 
-  // So far we have added sections from input object files.
-  // This function adds linker-created Out::* sections.
   addPredefinedSections();
   removeUnusedSyntheticSections(OutputSections);
 
@@ -1275,8 +1273,20 @@ template <class ELFT> void Writer<ELFT>:
   // ARM ABI requires .ARM.exidx to be terminated by some piece of data.
   // We have the terminater synthetic section class. Add that at the end.
   auto *OS = dyn_cast_or_null<OutputSection>(findSection(".ARM.exidx"));
-  if (OS && !OS->Sections.empty() && !Config->Relocatable)
-    OS->addSection(make<ARMExidxSentinelSection>());
+  if (!OS || OS->Sections.empty() || Config->Relocatable)
+    return;
+
+  auto *Sentinel = make<ARMExidxSentinelSection>();
+  OS->addSection(Sentinel);
+  // If there are linker script commands existing at this point then add the
+  // sentinel to the last of these too.
+  if (OutputSectionCommand *C = Script->getCmd(OS)) {
+    auto ISD = std::find_if(C->Commands.rbegin(), C->Commands.rend(),
+                            [](const BaseCommand *Base) {
+                              return isa<InputSectionDescription>(Base);
+                            });
+    cast<InputSectionDescription>(*ISD)->Sections.push_back(Sentinel);
+  }
 }
 
 // The linker is expected to define SECNAME_start and SECNAME_end




More information about the llvm-commits mailing list