From: Shankar Easwaran Date: Sun, 30 Nov 2014 22:36:29 +0000 (+0000) Subject: [ELF] Fix layout of output sections. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a0184368d63d04000ae7e19f5640f442c31423e4;p=platform%2Fupstream%2Fllvm.git [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. llvm-svn: 222982 --- diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h index 9a30f41..b89e7e4 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -547,7 +547,11 @@ template AtomSection *DefaultLayout::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 *DefaultLayout::getSection( getSectionOrder(sectionName, contentType, permissions); AtomSection *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)); diff --git a/lld/test/elf/Mips/ctors-order.test b/lld/test/elf/Mips/ctors-order.test index bded11a..b8bf012 100644 --- a/lld/test/elf/Mips/ctors-order.test +++ b/lld/test/elf/Mips/ctors-order.test @@ -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: