Index: lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h =================================================================== --- lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h +++ lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h @@ -83,6 +83,11 @@ this->_allocator) MipsRelocationTable(this->_ctx, name, order)); } + uint64_t getLookupSectionFlags(const OutputSection *os) const override { + uint64_t flags = TargetLayout::getLookupSectionFlags(os); + return flags & ~llvm::ELF::SHF_MIPS_NOSTRIP; + } + private: MipsGOTSection *_gotSection; MipsPLTSection *_pltSection; Index: lib/ReaderWriter/ELF/TargetLayout.h =================================================================== --- lib/ReaderWriter/ELF/TargetLayout.h +++ lib/ReaderWriter/ELF/TargetLayout.h @@ -300,6 +300,8 @@ new (_allocator) RelocationTable(_ctx, name, order)); } + virtual uint64_t getLookupSectionFlags(const OutputSection *os) const; + protected: llvm::BumpPtrAllocator _allocator; SectionMapT _sectionMap; Index: lib/ReaderWriter/ELF/TargetLayout.cpp =================================================================== --- lib/ReaderWriter/ELF/TargetLayout.cpp +++ lib/ReaderWriter/ELF/TargetLayout.cpp @@ -327,6 +327,22 @@ } } +template +uint64_t +TargetLayout::getLookupSectionFlags(const OutputSection *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 void TargetLayout::assignSectionsToSegments() { ScopedTask task(getDefaultDomain(), "assignSectionsToSegments"); ELFLinkingContext::OutputMagic outputMagic = _ctx.getOutputMagic(); @@ -362,16 +378,7 @@ 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 *segment; // We need a separate segment for sections that don't have Index: test/elf/Mips/mips-options-02.test =================================================================== --- test/elf/Mips/mips-options-02.test +++ 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 --- Index: test/elf/Mips/mips-options-03.test =================================================================== --- test/elf/Mips/mips-options-03.test +++ 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 Index: test/elf/Mips/mips-options-04.test =================================================================== --- test/elf/Mips/mips-options-04.test +++ 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 --- Index: test/elf/Mips/mips-options-05.test =================================================================== --- test/elf/Mips/mips-options-05.test +++ 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 --- Index: test/elf/Mips/mips-options-gp0.test =================================================================== --- test/elf/Mips/mips-options-gp0.test +++ 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: