Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -1012,6 +1012,17 @@ return I; } +static uint32_t getELFFlags() { + if (Config->EMachine != EM_MIPS) + return 0; + // FIXME: In fact ELF flags depends on ELF flags of input object files + // and selected emulation. For now just use hadr coded values. + uint32_t V = EF_MIPS_ABI_O32 | EF_MIPS_CPIC | EF_MIPS_ARCH_32R2; + if (Config->Shared) + V |= EF_MIPS_PIC; + return V; +} + template void Writer::writeHeader() { uint8_t *Buf = Buffer->getBufferStart(); memcpy(Buf, "\177ELF", 4); @@ -1033,6 +1044,7 @@ EHdr->e_entry = getEntryAddr(); EHdr->e_phoff = sizeof(Elf_Ehdr); EHdr->e_shoff = SectionHeaderOff; + EHdr->e_flags = getELFFlags(); EHdr->e_ehsize = sizeof(Elf_Ehdr); EHdr->e_phentsize = sizeof(Elf_Phdr); EHdr->e_phnum = Phdrs.size(); Index: lld/trunk/test/ELF/basic-mips.s =================================================================== --- lld/trunk/test/ELF/basic-mips.s +++ lld/trunk/test/ELF/basic-mips.s @@ -28,7 +28,10 @@ # CHECK-NEXT: Entry: 0x20000 # CHECK-NEXT: ProgramHeaderOffset: 0x34 # CHECK-NEXT: SectionHeaderOffset: 0x20084 -# CHECK-NEXT: Flags [ (0x0) +# CHECK-NEXT: Flags [ +# CHECK-NEXT: EF_MIPS_ABI_O32 +# CHECK-NEXT: EF_MIPS_ARCH_32R2 +# CHECK-NEXT: EF_MIPS_CPIC # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 52 # CHECK-NEXT: ProgramHeaderEntrySize: 32 Index: lld/trunk/test/ELF/emulation.s =================================================================== --- lld/trunk/test/ELF/emulation.s +++ lld/trunk/test/ELF/emulation.s @@ -112,7 +112,10 @@ # MIPS-NEXT: Entry: # MIPS-NEXT: ProgramHeaderOffset: 0x34 # MIPS-NEXT: SectionHeaderOffset: -# MIPS-NEXT: Flags [ (0x0) +# MIPS-NEXT: Flags [ +# MIPS-NEXT: EF_MIPS_ABI_O32 +# MIPS-NEXT: EF_MIPS_ARCH_32R2 +# MIPS-NEXT: EF_MIPS_CPIC # MIPS-NEXT: ] # RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-linux %s -o %tmipsel @@ -138,7 +141,10 @@ # MIPSEL-NEXT: Entry: # MIPSEL-NEXT: ProgramHeaderOffset: 0x34 # MIPSEL-NEXT: SectionHeaderOffset: -# MIPSEL-NEXT: Flags [ (0x0) +# MIPSEL-NEXT: Flags [ +# MIPSEL-NEXT: EF_MIPS_ABI_O32 +# MIPSEL-NEXT: EF_MIPS_ARCH_32R2 +# MIPSEL-NEXT: EF_MIPS_CPIC # MIPSEL-NEXT: ] # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %taarch64 Index: lld/trunk/test/ELF/mips-elf-flags.s =================================================================== --- lld/trunk/test/ELF/mips-elf-flags.s +++ lld/trunk/test/ELF/mips-elf-flags.s @@ -0,0 +1,27 @@ +# Check generation of MIPS specific ELF header flags. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -shared -o %t.so +# RUN: llvm-readobj -h %t.so | FileCheck -check-prefix=SO %s +# RUN: ld.lld %t.o -o %t.exe +# RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=EXE %s + +# REQUIRES: mips + + .text + .globl __start +__start: + nop + +# SO: Flags [ +# SO-NEXT: EF_MIPS_ABI_O32 +# SO-NEXT: EF_MIPS_ARCH_32R2 +# SO-NEXT: EF_MIPS_CPIC +# SO-NEXT: EF_MIPS_PIC +# SO-NEXT: ] + +# EXE: Flags [ +# EXE-NEXT: EF_MIPS_ABI_O32 +# EXE-NEXT: EF_MIPS_ARCH_32R2 +# EXE-NEXT: EF_MIPS_CPIC +# EXE-NEXT: ]