[PATCH] D33496: [LLD][ELF] Move creation of .ARM.exidx sentinel before LinkerScript creation

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 24 07:22:06 PDT 2017


peter.smith created this revision.
Herald added subscribers: emaste, rengolin, aemerson.

This change moves the creation of the .ARM.exidx sentinel section forward so that it is assigned to an OutputSection/InputSectionDescription with the existing .ARM.exidx sections.

      

A consequence of moving the .ARM.exidx creation earlier is that we can no longer guarantee that it will be already last in the table so we must account for this in the comparison function.

I've split this out from https://reviews.llvm.org/D33239 as it is a logical intermediate step towards converting the SHF_LINK_ORDER processing to use InputSectionDescriptions.


https://reviews.llvm.org/D33496

Files:
  ELF/OutputSections.cpp
  ELF/Writer.cpp


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -213,6 +213,7 @@
   // Create linker-synthesized sections such as .got or .plt.
   // Such sections are of type input section.
   createSyntheticSections();
+  addPredefinedSections();
   combineMergableSections();
 
   if (!Config->Relocatable)
@@ -1186,9 +1187,6 @@
   if (ErrorCount)
     return;
 
-  // So far we have added sections from input object files.
-  // This function adds linker-created Out::* sections.
-  addPredefinedSections();
   removeUnusedSyntheticSections(OutputSections);
 
   sortSections();
@@ -1260,9 +1258,12 @@
 template <class ELFT> void Writer<ELFT>::addPredefinedSections() {
   // 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 (Config->EMachine == EM_ARM && !Config->Relocatable &&
+      std::find_if(InputSections.begin(), InputSections.end(),
+                   [](InputSectionBase *S) {
+                     return S->Name.startswith(".ARM.exidx");
+                   }) != InputSections.end())
+    InputSections.push_back(make<ARMExidxSentinelSection>());
 }
 
 // The linker is expected to define SECNAME_start and SECNAME_end
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -72,10 +72,12 @@
       SectionIndex(INT_MAX) {}
 
 static bool compareByFilePosition(InputSection *A, InputSection *B) {
-  // Synthetic doesn't have link order dependecy, stable_sort will keep it last
-  if (A->kind() == InputSectionBase::Synthetic ||
-      B->kind() == InputSectionBase::Synthetic)
+  // The .ARM.exidx sentinel is the only Synthetic we expect to see here,
+  // it needs to be sorted last.
+  if (A->kind() == InputSectionBase::Synthetic)
     return false;
+  else if (B->kind() == InputSectionBase::Synthetic)
+    return true;
   auto *LA = cast<InputSection>(A->getLinkOrderDep());
   auto *LB = cast<InputSection>(B->getLinkOrderDep());
   OutputSection *AOut = LA->OutSec;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33496.100083.patch
Type: text/x-patch
Size: 2350 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170524/9278bf5b/attachment.bin>


More information about the llvm-commits mailing list