[llvm-branch-commits] [lld] r368270 - Merging r368041:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 8 01:57:23 PDT 2019


Author: hans
Date: Thu Aug  8 01:57:23 2019
New Revision: 368270

URL: http://llvm.org/viewvc/llvm-project?rev=368270&view=rev
Log:
Merging r368041:
------------------------------------------------------------------------
r368041 | psmith | 2019-08-06 16:13:38 +0200 (Tue, 06 Aug 2019) | 16 lines

[ELF][ARM] Fix /DISCARD/ of section with .ARM.exidx section

The combineEhSections runs, by design, before processSectionCommands so
that input exception sections like .ARM.exidx and .eh_frame are not assigned
to OutputSections. Unfortunately if /DISCARD/ removes InputSections that
have associated .ARM.exidx sections without discarding the .ARM.exidx
synthetic section then we will end up crashing when trying to sort the
InputSections in ascending address order.

We fix this by filtering out the sections that have been discarded prior
to processing the InputSections in finalizeContents().

fixes pr42890

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

------------------------------------------------------------------------

Added:
    lld/branches/release_90/test/ELF/arm-exidx-partial-discard.s
      - copied unchanged from r368041, lld/trunk/test/ELF/arm-exidx-partial-discard.s
Modified:
    lld/branches/release_90/   (props changed)
    lld/branches/release_90/ELF/SyntheticSections.cpp

Propchange: lld/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug  8 01:57:23 2019
@@ -1 +1 @@
-/lld/trunk:366445,366500,366504,366780,366784,367836-367837,368078
+/lld/trunk:366445,366500,366504,366780,366784,367836-367837,368041,368078

Modified: lld/branches/release_90/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/ELF/SyntheticSections.cpp?rev=368270&r1=368269&r2=368270&view=diff
==============================================================================
--- lld/branches/release_90/ELF/SyntheticSections.cpp (original)
+++ lld/branches/release_90/ELF/SyntheticSections.cpp Thu Aug  8 01:57:23 2019
@@ -3177,11 +3177,23 @@ static bool isDuplicateArmExidxSec(Input
 
 // The .ARM.exidx table must be sorted in ascending order of the address of the
 // functions the table describes. Optionally duplicate adjacent table entries
-// can be removed. At the end of the function the ExecutableSections must be
+// can be removed. At the end of the function the executableSections must be
 // sorted in ascending order of address, Sentinel is set to the InputSection
 // with the highest address and any InputSections that have mergeable
 // .ARM.exidx table entries are removed from it.
 void ARMExidxSyntheticSection::finalizeContents() {
+  if (script->hasSectionsCommand) {
+    // The executableSections and exidxSections that we use to derive the
+    // final contents of this SyntheticSection are populated before the
+    // linker script assigns InputSections to OutputSections. The linker script
+    // SECTIONS command may have a /DISCARD/ entry that removes executable
+    // InputSections and their dependent .ARM.exidx section that we recorded
+    // earlier.
+    auto isDiscarded = [](const InputSection *isec) { return !isec->isLive(); };
+    llvm::erase_if(executableSections, isDiscarded);
+    llvm::erase_if(exidxSections, isDiscarded);
+  }
+
   // Sort the executable sections that may or may not have associated
   // .ARM.exidx sections by order of ascending address. This requires the
   // relative positions of InputSections to be known.




More information about the llvm-branch-commits mailing list