[lld] r238688 - [Mips] Do not put the .reginfo section into the separate segment
Simon Atanasyan
simon at atanasyan.com
Sun May 31 13:37:13 PDT 2015
Author: atanasyan
Date: Sun May 31 15:37:13 2015
New Revision: 238688
URL: http://llvm.org/viewvc/llvm-project?rev=238688&view=rev
Log:
[Mips] Do not put the .reginfo section into the separate segment
The .reginfo should not belong to the separate segment if there is
a .MIPS.abiflags section.
Added:
lld/trunk/test/elf/Mips/abi-flags-10.test
lld/trunk/test/elf/Mips/abi-flags-11.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h
lld/trunk/test/elf/Mips/reginfo-02.test
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h?rev=238688&r1=238687&r2=238688&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h Sun May 31 15:37:13 2015
@@ -43,6 +43,8 @@ public:
MipsAbiInfoHandler() = default;
+ bool hasMipsAbiSection() const { return _hasAbiSection; }
+
uint32_t getFlags() const;
llvm::Optional<Elf_Mips_RegInfo> getRegistersMask() const;
llvm::Optional<Elf_Mips_ABIFlags> getAbiFlags() const;
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp?rev=238688&r1=238687&r2=238688&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp Sun May 31 15:37:13 2015
@@ -17,7 +17,7 @@ namespace elf {
template <class ELFT>
MipsTargetHandler<ELFT>::MipsTargetHandler(MipsLinkingContext &ctx)
- : _ctx(ctx), _targetLayout(new MipsTargetLayout<ELFT>(ctx)),
+ : _ctx(ctx), _targetLayout(new MipsTargetLayout<ELFT>(ctx, _abiInfoHandler)),
_relocationHandler(
createMipsRelocationHandler<ELFT>(ctx, *_targetLayout)) {}
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h?rev=238688&r1=238687&r2=238688&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h Sun May 31 15:37:13 2015
@@ -31,9 +31,9 @@ public:
private:
MipsLinkingContext &_ctx;
+ MipsAbiInfoHandler<ELFT> _abiInfoHandler;
std::unique_ptr<MipsTargetLayout<ELFT>> _targetLayout;
std::unique_ptr<TargetRelocationHandler> _relocationHandler;
- MipsAbiInfoHandler<ELFT> _abiInfoHandler;
};
template <class ELFT> class MipsSymbolTable : public SymbolTable<ELFT> {
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=238688&r1=238687&r2=238688&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.cpp Sun May 31 15:37:13 2015
@@ -14,8 +14,9 @@ namespace lld {
namespace elf {
template <class ELFT>
-MipsTargetLayout<ELFT>::MipsTargetLayout(MipsLinkingContext &ctx)
- : TargetLayout<ELFT>(ctx),
+MipsTargetLayout<ELFT>::MipsTargetLayout(MipsLinkingContext &ctx,
+ MipsAbiInfoHandler<ELFT> &abi)
+ : TargetLayout<ELFT>(ctx), _abiInfo(abi),
_gotSection(new (this->_allocator) MipsGOTSection<ELFT>(ctx)),
_pltSection(new (this->_allocator) MipsPLTSection<ELFT>(ctx)) {}
@@ -35,7 +36,8 @@ typename TargetLayout<ELFT>::SegmentType
MipsTargetLayout<ELFT>::getSegmentType(Section<ELFT> *section) const {
switch (section->order()) {
case ORDER_MIPS_REGINFO:
- return llvm::ELF::PT_MIPS_REGINFO;
+ return _abiInfo.hasMipsAbiSection() ? llvm::ELF::PT_LOAD
+ : llvm::ELF::PT_MIPS_REGINFO;
case ORDER_MIPS_OPTIONS:
return llvm::ELF::PT_LOAD;
case ORDER_MIPS_ABI_FLAGS:
@@ -81,11 +83,13 @@ uint64_t MipsTargetLayout<ELFT>::getLook
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;
- });
+ // Move PT_MIPS_ABIFLAGS or PT_MIPS_REGINFO right after PT_INTERP.
+ auto abiIt =
+ std::find_if(this->_segments.begin(), this->_segments.end(),
+ [](const Segment<ELFT> *s) {
+ auto typ = s->segmentType();
+ return typ == PT_MIPS_ABIFLAGS || typ == PT_MIPS_REGINFO;
+ });
if (abiIt == this->_segments.end())
return;
Segment<ELFT> *abiSeg = *abiIt;
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=238688&r1=238687&r2=238688&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetLayout.h Sun May 31 15:37:13 2015
@@ -9,6 +9,7 @@
#ifndef LLD_READER_WRITER_ELF_MIPS_MIPS_TARGET_LAYOUT_H
#define LLD_READER_WRITER_ELF_MIPS_MIPS_TARGET_LAYOUT_H
+#include "MipsAbiInfoHandler.h"
#include "MipsSectionChunks.h"
#include "TargetLayout.h"
@@ -26,7 +27,7 @@ public:
ORDER_MIPS_OPTIONS,
};
- MipsTargetLayout(MipsLinkingContext &ctx);
+ MipsTargetLayout(MipsLinkingContext &ctx, MipsAbiInfoHandler<ELFT> &abi);
const MipsGOTSection<ELFT> &getGOTSection() const { return *_gotSection; }
const MipsPLTSection<ELFT> &getPLTSection() const { return *_pltSection; }
@@ -57,6 +58,7 @@ protected:
void sortSegments() override;
private:
+ MipsAbiInfoHandler<ELFT> &_abiInfo;
MipsGOTSection<ELFT> *_gotSection;
MipsPLTSection<ELFT> *_pltSection;
uint64_t _gpAddr = 0;
Added: lld/trunk/test/elf/Mips/abi-flags-10.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/abi-flags-10.test?rev=238688&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/abi-flags-10.test (added)
+++ lld/trunk/test/elf/Mips/abi-flags-10.test Sun May 31 15:37:13 2015
@@ -0,0 +1,60 @@
+# Check that SHT_MIPS_REGINFO section does not get a separate segment
+# if there is a SHT_MIPS_ABIFLAGS section.
+
+# 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: ProgramHeaders [
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR
+# CHECK: }
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_INTERP
+# CHECK: }
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_MIPS_ABIFLAGS
+# CHECK: }
+# CHECK-NOT: Type: PT_MIPS_REGINFO
+
+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: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "F0000000E0000000D0000000C0000000B000000000100000"
+
+- 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
Added: lld/trunk/test/elf/Mips/abi-flags-11.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/abi-flags-11.test?rev=238688&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/abi-flags-11.test (added)
+++ lld/trunk/test/elf/Mips/abi-flags-11.test Sun May 31 15:37:13 2015
@@ -0,0 +1,59 @@
+# Check position of PT_MIPS_REGINFO 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_REGINFO
+# 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: 4
+# 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: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "F0000000E0000000D0000000C0000000B000000000100000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
Modified: lld/trunk/test/elf/Mips/reginfo-02.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/reginfo-02.test?rev=238688&r1=238687&r2=238688&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/reginfo-02.test (original)
+++ lld/trunk/test/elf/Mips/reginfo-02.test Sun May 31 15:37:13 2015
@@ -8,9 +8,9 @@
# SEC: Index: 1
# SEC-NEXT: Name: .reginfo (1)
-# SEC-NEXT: Type: SHT_MIPS_REGINFO (0x70000006)
-# SEC-NEXT: Flags [ (0x2)
-# SEC-NEXT: SHF_ALLOC (0x2)
+# SEC-NEXT: Type: SHT_MIPS_REGINFO
+# SEC-NEXT: Flags [
+# SEC-NEXT: SHF_ALLOC
# SEC-NEXT: ]
# SEC-NEXT: Address: {{[0-9A-F]+}}
# SEC-NEXT: Offset: {{[0-9A-F]+}}
@@ -20,18 +20,19 @@
# SEC-NEXT: AddressAlignment: 4
# SEC-NEXT: EntrySize: 24
-# SEC: ProgramHeader {
-# SEC: Type: PT_MIPS_REGINFO (0x70000000)
-# SEC-NEXT: Offset: 0x{{[0-9A-F]+}}
-# SEC-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
-# SEC-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
-# SEC-NEXT: FileSize: 24
-# SEC-NEXT: MemSize: 24
-# SEC-NEXT: Flags [ (0x4)
-# SEC-NEXT: PF_R (0x4)
-# SEC-NEXT: ]
-# SEC-NEXT: Alignment: 4
-# SEC-NEXT: }
+# SEC: ProgramHeaders [
+# SEC-NEXT: ProgramHeader {
+# SEC-NEXT: Type: PT_MIPS_REGINFO
+# SEC-NEXT: Offset: 0x{{[0-9A-F]+}}
+# SEC-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# SEC-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# SEC-NEXT: FileSize: 24
+# SEC-NEXT: MemSize: 24
+# SEC-NEXT: Flags [
+# SEC-NEXT: PF_R
+# SEC-NEXT: ]
+# SEC-NEXT: Alignment: 4
+# SEC-NEXT: }
# RAW: Contents of section .reginfo:
# RAW-NEXT: {{[0-9a-f]+}} f0000001 e0000002 d0000003 c0000004
More information about the llvm-commits
mailing list