forked from OSchip/llvm-project
[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. llvm-svn: 199555
This commit is contained in:
parent
0e57a77072
commit
2f1d6366e7
|
@ -127,6 +127,27 @@ uint64_t MipsTargetHandler::getGPDispSymAddr() const {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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>)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue