[lld] r199555 - [Mips] Emit ELF header for MIPS target. ELF flags set is mostly hardcoded.
Simon Atanasyan
simon at atanasyan.com
Sat Jan 18 08:59:11 PST 2014
Author: atanasyan
Date: Sat Jan 18 10:59:11 2014
New Revision: 199555
URL: http://llvm.org/viewvc/llvm-project?rev=199555&view=rev
Log:
[Mips] Emit ELF header for MIPS target. ELF flags set is mostly hardcoded.
Later we need to improve that solution and build a correct set of flags
by merging ELF flags from all input objects.
Added:
lld/trunk/test/elf/Mips/exe-fileheader.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
lld/trunk/test/elf/Mips/dynlib-fileheader.test
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=199555&r1=199554&r2=199555&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp Sat Jan 18 10:59:11 2014
@@ -127,6 +127,27 @@ uint64_t MipsTargetHandler::getGPDispSym
return _gpDispSymAtom ? _gpDispSymAtom->_virtualAddr : 0;
}
+bool MipsTargetHandler::doesOverrideELFHeader() { return true; }
+
+void MipsTargetHandler::setELFHeader(ELFHeader<Mips32ElELFType> *elfHeader) {
+ 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);
+
+ // FIXME (simon): Read elf flags from all inputs, check compatibility,
+ // merge them and write result here.
+ uint32_t flags = llvm::ELF::EF_MIPS_NOREORDER | llvm::ELF::EF_MIPS_ABI_O32 |
+ llvm::ELF::EF_MIPS_CPIC | llvm::ELF::EF_MIPS_ARCH_32R2;
+ if (_context.getOutputELFType() == llvm::ELF::ET_DYN)
+ flags |= EF_MIPS_PIC;
+ elfHeader->e_flags(flags);
+}
+
MipsTargetLayout<Mips32ElELFType> &MipsTargetHandler::targetLayout() {
return _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=199555&r1=199554&r2=199555&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h Sat Jan 18 10:59:11 2014
@@ -54,6 +54,8 @@ public:
uint64_t getGPDispSymAddr() const;
+ virtual bool doesOverrideELFHeader();
+ virtual void setELFHeader(ELFHeader<Mips32ElELFType> *elfHeader);
virtual MipsTargetLayout<Mips32ElELFType> &targetLayout();
virtual const MipsTargetRelocationHandler &getRelocationHandler() const;
virtual LLD_UNIQUE_BUMP_PTR(DynamicTable<Mips32ElELFType>)
Modified: lld/trunk/test/elf/Mips/dynlib-fileheader.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/dynlib-fileheader.test?rev=199555&r1=199554&r2=199555&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/dynlib-fileheader.test (original)
+++ lld/trunk/test/elf/Mips/dynlib-fileheader.test Sat Jan 18 10:59:11 2014
@@ -22,7 +22,13 @@ CHECK: Version: 1
CHECK: Entry: 0x170
CHECK: ProgramHeaderOffset: 0x34
CHECK: SectionHeaderOffset: 0x21D8
-CHECK: Flags [ (0x0)
+CHECK: Flags [ (0x70001007)
+CHECK: 0x1
+CHECK: 0x2
+CHECK: 0x1000
+CHECK: 0x10000000
+CHECK: 0x20000000
+CHECK: 0x40000000
CHECK: ]
CHECK: HeaderSize: 52
CHECK: ProgramHeaderEntrySize: 32
Added: lld/trunk/test/elf/Mips/exe-fileheader.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/exe-fileheader.test?rev=199555&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/exe-fileheader.test (added)
+++ lld/trunk/test/elf/Mips/exe-fileheader.test Sat Jan 18 10:59:11 2014
@@ -0,0 +1,54 @@
+# Check ELF Header for non-pic executable file.
+
+# Build shared library
+# RUN: llvm-mc -triple=mipsel -filetype=obj -relocation-model=pic \
+# RUN: -o=%t-obj %p/Inputs/ext.s
+# RUN: lld -flavor gnu -target mipsel -shared -o %t-so %t-obj
+
+# Build executable
+# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s
+# RUN: lld -flavor gnu -target mipsel -e glob -o %t-exe %t-obj %t-so
+# 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: 0x4001B0
+# CHECK: ProgramHeaderOffset: 0x34
+# CHECK: SectionHeaderOffset: 0x2268
+# CHECK: Flags [ (0x70001005)
+# CHECK: 0x1
+# CHECK: 0x4
+# CHECK: 0x1000
+# CHECK: 0x10000000
+# CHECK: 0x20000000
+# CHECK: 0x40000000
+# CHECK: ]
+# CHECK: HeaderSize: 52
+# CHECK: ProgramHeaderEntrySize: 32
+# CHECK: ProgramHeaderCount: 6
+# CHECK: SectionHeaderEntrySize: 40
+# CHECK: SectionHeaderCount: 16
+# CHECK: StringTableSectionIndex: 13
+# CHECK: }
+
+ .abicalls
+ .global glob
+ .ent glob
+glob:
+ jal ext1
+ .end glob
More information about the llvm-commits
mailing list