[lld] r235487 - [ELF] Allow TargetLayout descendants to control assignment sections to segments

Simon Atanasyan simon at atanasyan.com
Wed Apr 22 00:57:35 PDT 2015


Author: atanasyan
Date: Wed Apr 22 02:57:35 2015
New Revision: 235487

URL: http://llvm.org/viewvc/llvm-project?rev=235487&view=rev
Log:
[ELF] Allow TargetLayout descendants to control assignment sections to segments

The TargetLayout class puts two sections into the same segment if they
have equal segment types and the same section flags (SHF_xxx). To be
able to merge some sort of sections into the same segment we drop some
flags before comparison. For example to merge string sections into Data
segment we drop SHF_STRINGS and SHF_MERGE flags.

The patch allows TargetLayout descendants to drop some target specific
section flags. MIPS target needs that to merge .MIPS.options section
which has SHF_MIPS_NOSTRIP flag into the LOAD segment.

http://reviews.llvm.org/D9160

Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h
    lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp
    lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h
    lld/trunk/test/elf/Mips/mips-options-02.test
    lld/trunk/test/elf/Mips/mips-options-03.test
    lld/trunk/test/elf/Mips/mips-options-04.test
    lld/trunk/test/elf/Mips/mips-options-05.test
    lld/trunk/test/elf/Mips/mips-options-gp0.test

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h?rev=235487&r1=235486&r2=235487&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h Wed Apr 22 02:57:35 2015
@@ -83,6 +83,11 @@ protected:
         this->_allocator) MipsRelocationTable<ELFT>(this->_ctx, name, order));
   }
 
+  uint64_t getLookupSectionFlags(const OutputSection<ELFT> *os) const override {
+    uint64_t flags = TargetLayout<ELFT>::getLookupSectionFlags(os);
+    return flags & ~llvm::ELF::SHF_MIPS_NOSTRIP;
+  }
+
 private:
   MipsGOTSection<ELFT> *_gotSection;
   MipsPLTSection<ELFT> *_pltSection;

Modified: lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp?rev=235487&r1=235486&r2=235487&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp Wed Apr 22 02:57:35 2015
@@ -327,6 +327,21 @@ template <class ELFT> void TargetLayout<
   }
 }
 
+template <class ELFT>
+uint64_t
+TargetLayout<ELFT>::getLookupSectionFlags(const OutputSection<ELFT> *os) const {
+  uint64_t flags = os->flags();
+  if (!(flags & llvm::ELF::SHF_WRITE) && _ctx.mergeRODataToTextSegment())
+    flags &= ~llvm::ELF::SHF_EXECINSTR;
+
+  // Merge string sections into Data segment itself
+  flags &= ~(llvm::ELF::SHF_STRINGS | llvm::ELF::SHF_MERGE);
+
+  // Merge the TLS section into the DATA segment itself
+  flags &= ~(llvm::ELF::SHF_TLS);
+  return flags;
+}
+
 template <class ELFT> void TargetLayout<ELFT>::assignSectionsToSegments() {
   ScopedTask task(getDefaultDomain(), "assignSectionsToSegments");
   ELFLinkingContext::OutputMagic outputMagic = _ctx.getOutputMagic();
@@ -362,16 +377,7 @@ template <class ELFT> void TargetLayout<
       section->setSegmentType(segmentType);
       StringRef segmentName = section->segmentKindToStr();
 
-      uint64_t lookupSectionFlag = osi->flags();
-      if ((!(lookupSectionFlag & llvm::ELF::SHF_WRITE)) &&
-          (_ctx.mergeRODataToTextSegment()))
-        lookupSectionFlag &= ~llvm::ELF::SHF_EXECINSTR;
-
-      // Merge string sections into Data segment itself
-      lookupSectionFlag &= ~(llvm::ELF::SHF_STRINGS | llvm::ELF::SHF_MERGE);
-
-      // Merge the TLS section into the DATA segment itself
-      lookupSectionFlag &= ~(llvm::ELF::SHF_TLS);
+      uint64_t lookupSectionFlag = getLookupSectionFlags(osi);
 
       Segment<ELFT> *segment;
       // We need a separate segment for sections that don't have

Modified: lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h?rev=235487&r1=235486&r2=235487&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h Wed Apr 22 02:57:35 2015
@@ -300,6 +300,8 @@ protected:
         new (_allocator) RelocationTable<ELFT>(_ctx, name, order));
   }
 
+  virtual uint64_t getLookupSectionFlags(const OutputSection<ELFT> *os) const;
+
 protected:
   llvm::BumpPtrAllocator _allocator;
   SectionMapT _sectionMap;

Modified: lld/trunk/test/elf/Mips/mips-options-02.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/mips-options-02.test?rev=235487&r1=235486&r2=235487&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/mips-options-02.test (original)
+++ lld/trunk/test/elf/Mips/mips-options-02.test Wed Apr 22 02:57:35 2015
@@ -5,6 +5,7 @@
 # RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t1.o %t2.o
 # RUN: llvm-readobj -s -dynamic-table %t.so | FileCheck -check-prefix=SEC %s
 # RUN: llvm-objdump -s -t %t.so | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -program-headers %t.so | FileCheck -check-prefix=PHDR %s
 
 # SEC:      Index: 1
 # SEC-NEXT: Name: .MIPS.options (1)
@@ -25,12 +26,20 @@
 # SEC:   0x{{[0-9A-F]+}} MIPS_OPTIONS 0x[[OPT_ADDR]]
 
 # RAW:      Contents of section .MIPS.options:
-# RAW-NEXT:  1000 01280000 00000000 f0000001 00000000
-# RAW-NEXT:  1010 e0000002 d0000003 b0000004 c0000005
-# RAW-NEXT:  1020 f09f0000 00000000
+# RAW-NEXT:  {{[0-9a-f]+}} 01280000 00000000 f0000001 00000000
+# RAW-NEXT:  {{[0-9a-f]+}} e0000002 d0000003 b0000004 c0000005
+# RAW-NEXT:  {{[0-9a-f]+}} f08f0000 00000000
 
 # RAW: SYMBOL TABLE:
-# RAW: 0000000000009ff0 g *ABS* 00000000 _gp
+# RAW: 0000000000008ff0 g *ABS* 00000000 _gp
+
+# Check that %t.so contains only two PT_LOAD segments
+# PHDR:    ProgramHeaders
+# PHDR:      Type: PT_LOAD
+# PHDR:      Type: PT_LOAD
+# PHDR-NOT:  Type: PT_LOAD
+# PHDR:      Type: PT_DYNAMIC
+# PHDR:      Type: PT_NOTE
 
 # t1.o
 ---

Modified: lld/trunk/test/elf/Mips/mips-options-03.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/mips-options-03.test?rev=235487&r1=235486&r2=235487&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/mips-options-03.test (original)
+++ lld/trunk/test/elf/Mips/mips-options-03.test Wed Apr 22 02:57:35 2015
@@ -5,12 +5,12 @@
 # RUN: llvm-objdump -s -t %t.so | FileCheck %s
 
 # CHECK:      Contents of section .MIPS.options:
-# CHECK-NEXT:  1000 01280000 00000000 00000000 00000000
-# CHECK-NEXT:  1010 00000000 00000000 00000000 00000000
-# CHECK-NEXT:  1020 f09f0000 00000000
+# CHECK-NEXT:  {{[0-9a-f]+}} 01280000 00000000 00000000 00000000
+# CHECK-NEXT:  {{[0-9a-f]+}} 00000000 00000000 00000000 00000000
+# CHECK-NEXT:  {{[0-9a-f]+}} f08f0000 00000000
 
 # CHECK: SYMBOL TABLE:
-# CHECK: 00009ff0 g *ABS* 00000000 _gp
+# CHECK: 00008ff0 g *ABS* 00000000 _gp
 
 FileHeader:
   Class:   ELFCLASS64

Modified: lld/trunk/test/elf/Mips/mips-options-04.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/mips-options-04.test?rev=235487&r1=235486&r2=235487&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/mips-options-04.test (original)
+++ lld/trunk/test/elf/Mips/mips-options-04.test Wed Apr 22 02:57:35 2015
@@ -8,12 +8,12 @@
 # RUN: llvm-objdump -s -t %t.exe | FileCheck %s
 
 # CHECK:      Contents of section .MIPS.options:
-# CHECK-NEXT:  120001000 01280000 00000000 44444444 00000000
-# CHECK-NEXT:  120001010 44444444 44444444 44444444 44444444
-# CHECK-NEXT:  120001020 f09f0020 01000000
+# CHECK-NEXT:  {{[0-9a-f]+}} 01280000 00000000 44444444 00000000
+# CHECK-NEXT:  {{[0-9a-f]+}} 44444444 44444444 44444444 44444444
+# CHECK-NEXT:  {{[0-9a-f]+}} f08f0020 01000000
 
 # CHECK: SYMBOL TABLE:
-# CHECK: 20009ff0 g *ABS* 00000000 _gp
+# CHECK: 20008ff0 g *ABS* 00000000 _gp
 
 # t.so.o
 ---

Modified: lld/trunk/test/elf/Mips/mips-options-05.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/mips-options-05.test?rev=235487&r1=235486&r2=235487&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/mips-options-05.test (original)
+++ lld/trunk/test/elf/Mips/mips-options-05.test Wed Apr 22 02:57:35 2015
@@ -10,12 +10,12 @@
 # RUN: llvm-objdump -s -t %t.exe | FileCheck %s
 
 # CHECK:      Contents of section .MIPS.options:
-# CHECK-NEXT:  120001000 01280000 00000000 66666666 00000000
-# CHECK-NEXT:  120001010 66666666 66666666 66666666 66666666
-# CHECK-NEXT:  120001020 f09f0020 01000000
+# CHECK-NEXT:  {{[0-9a-f]+}} 01280000 00000000 66666666 00000000
+# CHECK-NEXT:  {{[0-9a-f]+}} 66666666 66666666 66666666 66666666
+# CHECK-NEXT:  {{[0-9a-f]+}} f08f0020 01000000
 
 # CHECK: SYMBOL TABLE:
-# CHECK: 20009ff0 g *ABS* 00000000 _gp
+# CHECK: 20008ff0 g *ABS* 00000000 _gp
 
 # t1.o
 ---

Modified: lld/trunk/test/elf/Mips/mips-options-gp0.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/mips-options-gp0.test?rev=235487&r1=235486&r2=235487&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/mips-options-gp0.test (original)
+++ lld/trunk/test/elf/Mips/mips-options-gp0.test Wed Apr 22 02:57:35 2015
@@ -6,7 +6,7 @@
 # RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=SEC %s
 
 # SYM:      Name: L1
-# SYM-NEXT: Value: 0x1A4
+# SYM-NEXT: Value: 0x194
 # SYM-NEXT: Size: 4
 # SYM-NEXT: Binding: Local (0x0)
 # SYM-NEXT: Type: Function (0x2)
@@ -14,16 +14,16 @@
 # SYM-NEXT: Section: .text (0x5)
 
 # SYM:      Name: _gp
-# SYM-NEXT: Value: 0x9FF0
+# SYM-NEXT: Value: 0x8FF0
 # SYM-NEXT: Size: 0
 # SYM-NEXT: Binding: Global (0x1)
 # SYM-NEXT: Type: Object (0x1)
 # SYM-NEXT: Other: 0
 # SYM-NEXT: Section: Absolute (0xFFF1)
 
-# 0xffff71b4 == 0x0 (addend) + 0x01A4 (L1) + 0x1000 (GP0) - 0x9ff0 (_gp)
+# 0xffff81a4 == 0x0 (addend) + 0x0194 (L1) + 0x1000 (GP0) - 0x8ff0 (_gp)
 # SEC:      Contents of section .rodata:
-# SEC-NEXT:  01ac b471ffff 00000000 00000000 00000000
+# SEC-NEXT:  {{[0-9a-f]+}} a481ffff 00000000 00000000 00000000
 
 !ELF
 FileHeader:





More information about the llvm-commits mailing list