[lld] r256089 - [ELF] Allow target to configure ELF header flags in the output file
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 18 21:51:49 PST 2015
Author: atanasyan
Date: Fri Dec 18 23:51:49 2015
New Revision: 256089
URL: http://llvm.org/viewvc/llvm-project?rev=256089&view=rev
Log:
[ELF] Allow target to configure ELF header flags in the output file
The patch configure ELF header flags for MIPS target. For now the flags
are hard coded. In fact they depends on ELF flags of input object files
and selected emulation.
Differential Revision: http://reviews.llvm.org/D15575
Added:
lld/trunk/test/ELF/mips-elf-flags.s
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/basic-mips.s
lld/trunk/test/ELF/emulation.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=256089&r1=256088&r2=256089&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Dec 18 23:51:49 2015
@@ -1012,6 +1012,17 @@ template <class ELFT> int Writer<ELFT>::
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 <class ELFT> void Writer<ELFT>::writeHeader() {
uint8_t *Buf = Buffer->getBufferStart();
memcpy(Buf, "\177ELF", 4);
@@ -1033,6 +1044,7 @@ template <class ELFT> void Writer<ELFT>:
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();
Modified: lld/trunk/test/ELF/basic-mips.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-mips.s?rev=256089&r1=256088&r2=256089&view=diff
==============================================================================
--- lld/trunk/test/ELF/basic-mips.s (original)
+++ lld/trunk/test/ELF/basic-mips.s Fri Dec 18 23:51:49 2015
@@ -28,7 +28,10 @@ __start:
# 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
Modified: lld/trunk/test/ELF/emulation.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emulation.s?rev=256089&r1=256088&r2=256089&view=diff
==============================================================================
--- lld/trunk/test/ELF/emulation.s (original)
+++ lld/trunk/test/ELF/emulation.s Fri Dec 18 23:51:49 2015
@@ -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
Added: lld/trunk/test/ELF/mips-elf-flags.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-elf-flags.s?rev=256089&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-elf-flags.s (added)
+++ lld/trunk/test/ELF/mips-elf-flags.s Fri Dec 18 23:51:49 2015
@@ -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: ]
More information about the llvm-commits
mailing list