summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h5
-rw-r--r--lld/lib/ReaderWriter/ELF/TargetLayout.cpp26
-rw-r--r--lld/lib/ReaderWriter/ELF/TargetLayout.h2
-rw-r--r--lld/test/elf/Mips/mips-options-02.test17
-rw-r--r--lld/test/elf/Mips/mips-options-03.test8
-rw-r--r--lld/test/elf/Mips/mips-options-04.test8
-rw-r--r--lld/test/elf/Mips/mips-options-05.test8
-rw-r--r--lld/test/elf/Mips/mips-options-gp0.test8
8 files changed, 52 insertions, 30 deletions
diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h
index 3fc8ba7a51d..36e74c246bc 100644
--- a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h
+++ b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h
@@ -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;
diff --git a/lld/lib/ReaderWriter/ELF/TargetLayout.cpp b/lld/lib/ReaderWriter/ELF/TargetLayout.cpp
index 001b53a97ec..bd2cf8fef8b 100644
--- a/lld/lib/ReaderWriter/ELF/TargetLayout.cpp
+++ b/lld/lib/ReaderWriter/ELF/TargetLayout.cpp
@@ -327,6 +327,21 @@ template <class ELFT> void TargetLayout<ELFT>::createOutputSections() {
}
}
+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<ELFT>::assignSectionsToSegments() {
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
diff --git a/lld/lib/ReaderWriter/ELF/TargetLayout.h b/lld/lib/ReaderWriter/ELF/TargetLayout.h
index ae7f6633376..3642a757fcf 100644
--- a/lld/lib/ReaderWriter/ELF/TargetLayout.h
+++ b/lld/lib/ReaderWriter/ELF/TargetLayout.h
@@ -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;
diff --git a/lld/test/elf/Mips/mips-options-02.test b/lld/test/elf/Mips/mips-options-02.test
index 2173ba5de79..8aa6e6e9169 100644
--- a/lld/test/elf/Mips/mips-options-02.test
+++ b/lld/test/elf/Mips/mips-options-02.test
@@ -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
---
diff --git a/lld/test/elf/Mips/mips-options-03.test b/lld/test/elf/Mips/mips-options-03.test
index 44a14a233d7..b4a0d265c8f 100644
--- a/lld/test/elf/Mips/mips-options-03.test
+++ b/lld/test/elf/Mips/mips-options-03.test
@@ -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
diff --git a/lld/test/elf/Mips/mips-options-04.test b/lld/test/elf/Mips/mips-options-04.test
index 7b80ad03144..db166186623 100644
--- a/lld/test/elf/Mips/mips-options-04.test
+++ b/lld/test/elf/Mips/mips-options-04.test
@@ -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
---
diff --git a/lld/test/elf/Mips/mips-options-05.test b/lld/test/elf/Mips/mips-options-05.test
index 0e9e7e95eb2..318d33910b9 100644
--- a/lld/test/elf/Mips/mips-options-05.test
+++ b/lld/test/elf/Mips/mips-options-05.test
@@ -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
---
diff --git a/lld/test/elf/Mips/mips-options-gp0.test b/lld/test/elf/Mips/mips-options-gp0.test
index 572c8e24866..c51239378f9 100644
--- a/lld/test/elf/Mips/mips-options-gp0.test
+++ b/lld/test/elf/Mips/mips-options-gp0.test
@@ -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:
OpenPOWER on IntegriCloud