[lld] r239613 - [Mips] Setup EI_ABIVERSION flag
Simon Atanasyan
simon at atanasyan.com
Fri Jun 12 09:12:51 PDT 2015
Author: atanasyan
Date: Fri Jun 12 11:12:50 2015
New Revision: 239613
URL: http://llvm.org/viewvc/llvm-project?rev=239613&view=rev
Log:
[Mips] Setup EI_ABIVERSION flag
- Set EI_ABIVERSION to '1' in case of non-PIC executable.
- Set EI_ABIVERSION to '3' in case of using FP64/FP64A floating point ABI.
Added:
lld/trunk/test/elf/Mips/exe-fileheader-02.test
lld/trunk/test/elf/Mips/exe-fileheader-03.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.cpp
lld/trunk/test/elf/Mips/exe-fileheader-micro.test
lld/trunk/test/elf/Mips/opt-emulation.test
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp?rev=239613&r1=239612&r2=239613&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.cpp Fri Jun 12 11:12:50 2015
@@ -434,6 +434,17 @@ template <class ELFT> bool MipsAbiInfoHa
return _abiFlags->_isa == Arch32r6 || _abiFlags->_isa == Arch64r6;
}
+template <class ELFT> bool MipsAbiInfoHandler<ELFT>::isFp64() const {
+ assert(_abiFlags.hasValue());
+ return _abiFlags->_fpAbi == Val_GNU_MIPS_ABI_FP_64 ||
+ _abiFlags->_fpAbi == Val_GNU_MIPS_ABI_FP_64A;
+}
+
+template <class ELFT> bool MipsAbiInfoHandler<ELFT>::isCPicOnly() const {
+ assert(_abiFlags.hasValue());
+ return _abiFlags->_isCPic && !_abiFlags->_isPic;
+}
+
template <class ELFT> uint32_t MipsAbiInfoHandler<ELFT>::getFlags() const {
std::lock_guard<std::mutex> lock(_mutex);
uint32_t flags = 0;
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=239613&r1=239612&r2=239613&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsAbiInfoHandler.h Fri Jun 12 11:12:50 2015
@@ -46,6 +46,8 @@ public:
bool hasMipsAbiSection() const { return _hasAbiSection; }
bool isMicroMips() const;
bool isMipsR6() const;
+ bool isFp64() const;
+ bool isCPicOnly() const;
uint32_t getFlags() const;
llvm::Optional<Elf_Mips_RegInfo> getRegistersMask() const;
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.cpp?rev=239613&r1=239612&r2=239613&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.cpp Fri Jun 12 11:12:50 2015
@@ -36,11 +36,14 @@ void MipsELFWriter<ELFT>::setELFHeader(E
elfHeader.e_version(1);
elfHeader.e_ident(llvm::ELF::EI_VERSION, llvm::ELF::EV_CURRENT);
elfHeader.e_ident(llvm::ELF::EI_OSABI, llvm::ELF::ELFOSABI_NONE);
- if (_targetLayout.findOutputSection(".got.plt"))
- elfHeader.e_ident(llvm::ELF::EI_ABIVERSION, 1);
- else
- elfHeader.e_ident(llvm::ELF::EI_ABIVERSION, 0);
+ unsigned char abiVer = 0;
+ if (_ctx.getOutputELFType() == ET_EXEC && _abiInfo.isCPicOnly())
+ abiVer = 1;
+ if (_abiInfo.isFp64())
+ abiVer = 3;
+
+ elfHeader.e_ident(llvm::ELF::EI_ABIVERSION, abiVer);
elfHeader.e_flags(_abiInfo.getFlags());
}
Added: lld/trunk/test/elf/Mips/exe-fileheader-02.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/exe-fileheader-02.test?rev=239613&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/exe-fileheader-02.test (added)
+++ lld/trunk/test/elf/Mips/exe-fileheader-02.test Fri Jun 12 11:12:50 2015
@@ -0,0 +1,62 @@
+# Check that LLD set ABIVersion to '1' if it generates executable
+# file without EF_MIPS_PIC in the ELF header.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mipsel
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 32-bit (0x1)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 1
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x50001005)
+# CHECK: EF_MIPS_ABI_O32 (0x1000)
+# CHECK: EF_MIPS_ARCH_32 (0x50000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: ]
+# CHECK: HeaderSize: 52
+# CHECK: ProgramHeaderEntrySize: 32
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 40
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+...
Added: lld/trunk/test/elf/Mips/exe-fileheader-03.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/exe-fileheader-03.test?rev=239613&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/exe-fileheader-03.test (added)
+++ lld/trunk/test/elf/Mips/exe-fileheader-03.test Fri Jun 12 11:12:50 2015
@@ -0,0 +1,72 @@
+# Check that LLD set ABIVersion to '3' if it generates executable
+# file with FP_64 / FP_64A floating point abi flags.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mipsel
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 32-bit (0x1)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 3
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x50001005)
+# CHECK: EF_MIPS_ABI_O32 (0x1000)
+# CHECK: EF_MIPS_ARCH_32 (0x50000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: ]
+# CHECK: HeaderSize: 52
+# CHECK: ProgramHeaderEntrySize: 32
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 40
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ ISAExtension: EXT_NONE
+ FpABI: FP_64
+ GPRSize: REG_32
+ CPR1Size: REG_64
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+...
Modified: lld/trunk/test/elf/Mips/exe-fileheader-micro.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/exe-fileheader-micro.test?rev=239613&r1=239612&r2=239613&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/exe-fileheader-micro.test (original)
+++ lld/trunk/test/elf/Mips/exe-fileheader-micro.test Fri Jun 12 11:12:50 2015
@@ -17,7 +17,7 @@
# CHECK-NEXT: DataEncoding: LittleEndian (0x1)
# CHECK-NEXT: FileVersion: 1
# CHECK-NEXT: OS/ABI: SystemV (0x0)
-# CHECK-NEXT: ABIVersion: 0
+# CHECK-NEXT: ABIVersion: 1
# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
# CHECK-NEXT: }
# CHECK-NEXT: Type: Executable (0x2)
Modified: lld/trunk/test/elf/Mips/opt-emulation.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/opt-emulation.test?rev=239613&r1=239612&r2=239613&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/opt-emulation.test (original)
+++ lld/trunk/test/elf/Mips/opt-emulation.test Fri Jun 12 11:12:50 2015
@@ -8,7 +8,7 @@
# LE-O32: DataEncoding: LittleEndian (0x1)
# LE-O32: FileVersion: 1
# LE-O32: OS/ABI: SystemV (0x0)
-# LE-O32: ABIVersion: 0
+# LE-O32: ABIVersion: 1
# LE-O32: Machine: EM_MIPS (0x8)
# LE-O32: Version: 1
# LE-O32: Flags [ (0x70001005)
More information about the llvm-commits
mailing list