[lld] r222982 - [ELF] Fix layout of output sections.

Shankar Easwaran shankare at codeaurora.org
Sun Nov 30 14:36:29 PST 2014


Author: shankare
Date: Sun Nov 30 16:36:29 2014
New Revision: 222982

URL: http://llvm.org/viewvc/llvm-project?rev=222982&view=rev
Log:
[ELF] Fix layout of output sections.

The AtomSections were improperly merging sections from various input files. This
patch fixes the problem, with an updated test that was provided by Simon.

Thanks to Simon Atanasyan for catching this issue.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
    lld/trunk/test/elf/Mips/ctors-order.test

Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=222982&r1=222981&r2=222982&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Sun Nov 30 16:36:29 2014
@@ -547,7 +547,11 @@ template <class ELFT>
 AtomSection<ELFT> *DefaultLayout<ELFT>::getSection(
     StringRef sectionName, int32_t contentType,
     DefinedAtom::ContentPermissions permissions) {
-  const SectionKey sectionKey(sectionName, permissions);
+  // FIXME: We really need the file path here in the SectionKey, when that
+  // is available, replace the sectionKey that has outputSectionName to the
+  // inputSectionName.
+  StringRef outputSectionName = getOutputSectionName(sectionName);
+  const SectionKey sectionKey(outputSectionName, permissions);
   auto sec = _sectionMap.find(sectionKey);
   if (sec != _sectionMap.end())
     return sec->second;
@@ -555,7 +559,7 @@ AtomSection<ELFT> *DefaultLayout<ELFT>::
       getSectionOrder(sectionName, contentType, permissions);
   AtomSection<ELFT> *newSec =
       createSection(sectionName, contentType, permissions, sectionOrder);
-  newSec->setOutputSectionName(getOutputSectionName(sectionName));
+  newSec->setOutputSectionName(outputSectionName);
   newSec->setOrder(sectionOrder);
   _sections.push_back(newSec);
   _sectionMap.insert(std::make_pair(sectionKey, newSec));

Modified: lld/trunk/test/elf/Mips/ctors-order.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/ctors-order.test?rev=222982&r1=222981&r2=222982&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/ctors-order.test (original)
+++ lld/trunk/test/elf/Mips/ctors-order.test Sun Nov 30 16:36:29 2014
@@ -5,6 +5,9 @@
 # RUN: yaml2obj -format=elf -docnum 3 %s > %t-obj.o
 # RUN: lld -flavor gnu -target mipsel -shared --output-filetype=yaml \
 # RUN:     %t-crtbeginS.o %t-obj.o %t-crtendS.o | FileCheck %s
+# RUN: lld -flavor gnu -target mipsel -shared -o %t.so \
+# RUN:     %t-crtbeginS.o %t-obj.o %t-crtendS.o
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=RAW %s
 
 # CHECK:      defined-atoms:
 # CHECK-NEXT:   - ref-name:        L000
@@ -52,6 +55,8 @@
 # CHECK-NEXT:     section-choice:  custom-required
 # CHECK-NEXT:     section-name:    .ctors
 
+# RAW:      Contents of section .ctors:
+# RAW-NEXT: 2000 ffffffff 11111111 22222222 00000000
 # crtbeginS.o
 ---
 FileHeader:





More information about the llvm-commits mailing list