[lld] r238687 - [Mips] Sort segments so PT_MIPS_ABIFLAGS goes right after the PT_INTERP
Simon Atanasyan
simon at atanasyan.com
Sun May 31 13:36:59 PDT 2015
Author: atanasyan
Date: Sun May 31 15:36:58 2015
New Revision: 238687
URL: http://llvm.org/viewvc/llvm-project?rev=238687&view=rev
Log:
[Mips] Sort segments so PT_MIPS_ABIFLAGS goes right after the PT_INTERP
Added:
lld/trunk/test/elf/Mips/abi-flags-09.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h
lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h
lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp
lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h
lld/trunk/test/elf/Mips/abi-flags-02.test
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.cpp?rev=238687&r1=238686&r2=238687&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.cpp Sun May 31 15:36:58 2015
@@ -78,6 +78,26 @@ uint64_t MipsTargetLayout<ELFT>::getLook
return flags & ~llvm::ELF::SHF_MIPS_NOSTRIP;
}
+template <class ELFT> void MipsTargetLayout<ELFT>::sortSegments() {
+ using namespace llvm::ELF;
+ TargetLayout<ELFT>::sortSegments();
+ // Move PT_MIPS_ABIFLAGS right after PT_INTERP.
+ auto abiIt = std::find_if(this->_segments.begin(), this->_segments.end(),
+ [](const Segment<ELFT> *s) {
+ return s->segmentType() == PT_MIPS_ABIFLAGS;
+ });
+ if (abiIt == this->_segments.end())
+ return;
+ Segment<ELFT> *abiSeg = *abiIt;
+ this->_segments.erase(abiIt);
+ auto outIt = std::find_if(this->_segments.begin(), this->_segments.end(),
+ [](const Segment<ELFT> *s) {
+ auto typ = s->segmentType();
+ return typ != PT_PHDR && typ != PT_INTERP;
+ });
+ this->_segments.insert(outIt, abiSeg);
+}
+
template class MipsTargetLayout<ELF32LE>;
template class MipsTargetLayout<ELF64LE>;
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=238687&r1=238686&r2=238687&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h Sun May 31 15:36:58 2015
@@ -54,6 +54,7 @@ protected:
unique_bump_ptr<RelocationTable<ELFT>>
createRelocationTable(StringRef name, int32_t order) override;
uint64_t getLookupSectionFlags(const OutputSection<ELFT> *os) const override;
+ void sortSegments() override;
private:
MipsGOTSection<ELFT> *_gotSection;
Modified: lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h?rev=238687&r1=238686&r2=238687&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h Sun May 31 15:36:58 2015
@@ -157,7 +157,7 @@ public:
int32_t sectionCount() const { return _sections.size(); }
/// \brief, this function returns the type of segment (PT_*)
- typename TargetLayout<ELFT>::SegmentType segmentType() {
+ typename TargetLayout<ELFT>::SegmentType segmentType() const {
return _segmentType;
}
Modified: lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp?rev=238687&r1=238686&r2=238687&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetLayout.cpp Sun May 31 15:36:58 2015
@@ -439,11 +439,15 @@ template <class ELFT> void TargetLayout<
}
}
+template <class ELFT> void TargetLayout<ELFT>::sortSegments() {
+ std::sort(_segments.begin(), _segments.end(), Segment<ELFT>::compareSegments);
+}
+
template <class ELFT> void TargetLayout<ELFT>::assignVirtualAddress() {
if (_segments.empty())
return;
- std::sort(_segments.begin(), _segments.end(), Segment<ELFT>::compareSegments);
+ sortSegments();
uint64_t baseAddress = _ctx.getBaseAddress();
Modified: lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h?rev=238687&r1=238686&r2=238687&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h Sun May 31 15:36:58 2015
@@ -302,6 +302,9 @@ protected:
virtual uint64_t getLookupSectionFlags(const OutputSection<ELFT> *os) const;
+ /// \brief Sort segements stored in the _segments
+ virtual void sortSegments();
+
protected:
llvm::BumpPtrAllocator _allocator;
SectionMapT _sectionMap;
Modified: lld/trunk/test/elf/Mips/abi-flags-02.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/abi-flags-02.test?rev=238687&r1=238686&r2=238687&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/abi-flags-02.test (original)
+++ lld/trunk/test/elf/Mips/abi-flags-02.test Sun May 31 15:36:58 2015
@@ -26,8 +26,8 @@
# CHECK-NEXT: }
# CHECK: ProgramHeaders [
-# CHECK: ProgramHeader {
-# CHECK: Type: PT_MIPS_ABIFLAGS (0x70000003)
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_MIPS_ABIFLAGS (0x70000003)
# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
Added: lld/trunk/test/elf/Mips/abi-flags-09.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/abi-flags-09.test?rev=238687&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/abi-flags-09.test (added)
+++ lld/trunk/test/elf/Mips/abi-flags-09.test Sun May 31 15:36:58 2015
@@ -0,0 +1,67 @@
+# Check position of PT_MIPS_ABIFLAGS segment.
+# It should go right after the PT_INTERP segment.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s
+
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_INTERP
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: FileSize: 13
+# CHECK-NEXT: MemSize: 13
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: PF_R
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 1
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_MIPS_ABIFLAGS
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: FileSize: 24
+# CHECK-NEXT: MemSize: 24
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: PF_R
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ ISAExtension: EXT_NONE
+ ASEs: [ MICROMIPS ]
+ FpABI: FP_XX
+ GPRSize: REG_32
+ CPR1Size: REG_32
+ CPR2Size: REG_NONE
+ Flags1: [ ]
+ Flags2: 0x0
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
More information about the llvm-commits
mailing list