[ELF] Fix layout of output sections.
authorShankar Easwaran <shankare@codeaurora.org>
Sun, 30 Nov 2014 22:36:29 +0000 (22:36 +0000)
committerShankar Easwaran <shankare@codeaurora.org>
Sun, 30 Nov 2014 22:36:29 +0000 (22:36 +0000)
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.

llvm-svn: 222982

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

index 9a30f41..b89e7e4 100644 (file)
@@ -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>::getSection(
       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));
index bded11a..b8bf012 100644 (file)
@@ -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: