[lld] r276172 - [ELF][MIPS] Pick arch flag from the first input file.
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 20 13:15:24 PDT 2016
Author: atanasyan
Date: Wed Jul 20 15:15:24 2016
New Revision: 276172
URL: http://llvm.org/viewvc/llvm-project?rev=276172&view=rev
Log:
[ELF][MIPS] Pick arch flag from the first input file.
LLD still does not produce a correct combination of MIPS ELF flags if
input files have different sets of ELF flags (i.e. EF_MIPS_ARCH_32 and
EF_MIPS_ARCH_32R2). But now we do not stick to "R2" ABI version and can
emit EF_MIPS_ARCH_32R6 for example.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/basic-mips.s
lld/trunk/test/ELF/emulation.s
lld/trunk/test/ELF/mips-elf-flags.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=276172&r1=276171&r2=276172&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Jul 20 15:15:24 2016
@@ -1166,16 +1166,22 @@ template <class ELFT> void Writer<ELFT>:
}
}
-static uint32_t getMipsEFlags(bool Is64Bits) {
- // FIXME: In fact ELF flags depends on ELF flags of input object files
- // and selected emulation. For now just use hard coded values.
+template <class ELFT>
+static uint32_t getMipsEFlags(bool Is64Bits,
+ const ELFFileBase<ELFT> &FirstElf) {
+ // FIXME: ELF flags depends on ELF flags of all input object files and
+ // selected emulation. For now pick the arch flag from the fisrt input file
+ // and use hard coded values for other flags.
+ uint32_t FirstElfFlags = FirstElf.getObj().getHeader()->e_flags;
+ uint32_t ElfFlags = FirstElfFlags & EF_MIPS_ARCH;
if (Is64Bits)
- return EF_MIPS_CPIC | EF_MIPS_PIC | EF_MIPS_ARCH_64R2;
-
- uint32_t V = EF_MIPS_CPIC | EF_MIPS_ABI_O32 | EF_MIPS_ARCH_32R2;
- if (Config->Shared)
- V |= EF_MIPS_PIC;
- return V;
+ ElfFlags |= EF_MIPS_CPIC | EF_MIPS_PIC;
+ else {
+ ElfFlags |= EF_MIPS_CPIC | EF_MIPS_ABI_O32;
+ if (Config->Shared)
+ ElfFlags |= EF_MIPS_PIC;
+ }
+ return ElfFlags;
}
template <class ELFT> static typename ELFT::uint getEntryAddr() {
@@ -1252,7 +1258,7 @@ template <class ELFT> void Writer<ELFT>:
EHdr->e_shstrndx = Out<ELFT>::ShStrTab->SectionIndex;
if (Config->EMachine == EM_MIPS)
- EHdr->e_flags = getMipsEFlags(ELFT::Is64Bits);
+ EHdr->e_flags = getMipsEFlags(ELFT::Is64Bits, FirstObj);
if (!Config->Relocatable) {
EHdr->e_phoff = sizeof(Elf_Ehdr);
Modified: lld/trunk/test/ELF/basic-mips.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-mips.s?rev=276172&r1=276171&r2=276172&view=diff
==============================================================================
--- lld/trunk/test/ELF/basic-mips.s (original)
+++ lld/trunk/test/ELF/basic-mips.s Wed Jul 20 15:15:24 2016
@@ -30,7 +30,7 @@ __start:
# CHECK-NEXT: SectionHeaderOffset: 0x30088
# CHECK-NEXT: Flags [
# CHECK-NEXT: EF_MIPS_ABI_O32
-# CHECK-NEXT: EF_MIPS_ARCH_32R2
+# CHECK-NEXT: EF_MIPS_ARCH_32
# CHECK-NEXT: EF_MIPS_CPIC
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 52
Modified: lld/trunk/test/ELF/emulation.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emulation.s?rev=276172&r1=276171&r2=276172&view=diff
==============================================================================
--- lld/trunk/test/ELF/emulation.s (original)
+++ lld/trunk/test/ELF/emulation.s Wed Jul 20 15:15:24 2016
@@ -176,7 +176,7 @@
# MIPS-NEXT: SectionHeaderOffset:
# MIPS-NEXT: Flags [
# MIPS-NEXT: EF_MIPS_ABI_O32
-# MIPS-NEXT: EF_MIPS_ARCH_32R2
+# MIPS-NEXT: EF_MIPS_ARCH_32
# MIPS-NEXT: EF_MIPS_CPIC
# MIPS-NEXT: ]
@@ -205,7 +205,7 @@
# MIPSEL-NEXT: SectionHeaderOffset:
# MIPSEL-NEXT: Flags [
# MIPSEL-NEXT: EF_MIPS_ABI_O32
-# MIPSEL-NEXT: EF_MIPS_ARCH_32R2
+# MIPSEL-NEXT: EF_MIPS_ARCH_32
# MIPSEL-NEXT: EF_MIPS_CPIC
# MIPSEL-NEXT: ]
@@ -231,7 +231,7 @@
# MIPS64-NEXT: ProgramHeaderOffset: 0x40
# MIPS64-NEXT: SectionHeaderOffset:
# MIPS64-NEXT: Flags [
-# MIPS64-NEXT: EF_MIPS_ARCH_64R2
+# MIPS64-NEXT: EF_MIPS_ARCH_64
# MIPS64-NEXT: EF_MIPS_CPIC
# MIPS64-NEXT: EF_MIPS_PIC
# MIPS64-NEXT: ]
@@ -258,7 +258,7 @@
# MIPS64EL-NEXT: ProgramHeaderOffset: 0x40
# MIPS64EL-NEXT: SectionHeaderOffset:
# MIPS64EL-NEXT: Flags [
-# MIPS64EL-NEXT: EF_MIPS_ARCH_64R2
+# MIPS64EL-NEXT: EF_MIPS_ARCH_64
# MIPS64EL-NEXT: EF_MIPS_CPIC
# MIPS64EL-NEXT: EF_MIPS_PIC
# MIPS64EL-NEXT: ]
Modified: lld/trunk/test/ELF/mips-elf-flags.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-elf-flags.s?rev=276172&r1=276171&r2=276172&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-elf-flags.s (original)
+++ lld/trunk/test/ELF/mips-elf-flags.s Wed Jul 20 15:15:24 2016
@@ -5,6 +5,14 @@
# 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
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN: -mcpu=mips32r2 %s -o %t-r2.o
+# RUN: ld.lld %t-r2.o -o %t-r2.exe
+# RUN: llvm-readobj -h %t-r2.exe | FileCheck -check-prefix=EXE-R2 %s
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN: -mcpu=mips32r6 %s -o %t-r6.o
+# RUN: ld.lld %t-r6.o -o %t-r6.exe
+# RUN: llvm-readobj -h %t-r6.exe | FileCheck -check-prefix=EXE-R6 %s
# REQUIRES: mips
@@ -15,13 +23,25 @@ __start:
# SO: Flags [
# SO-NEXT: EF_MIPS_ABI_O32
-# SO-NEXT: EF_MIPS_ARCH_32R2
+# SO-NEXT: EF_MIPS_ARCH_32
# 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_ARCH_32
# EXE-NEXT: EF_MIPS_CPIC
# EXE-NEXT: ]
+
+# EXE-R2: Flags [
+# EXE-R2-NEXT: EF_MIPS_ABI_O32
+# EXE-R2-NEXT: EF_MIPS_ARCH_32R2
+# EXE-R2-NEXT: EF_MIPS_CPIC
+# EXE-R2-NEXT: ]
+
+# EXE-R6: Flags [
+# EXE-R6-NEXT: EF_MIPS_ABI_O32
+# EXE-R6-NEXT: EF_MIPS_ARCH_32R6
+# EXE-R6-NEXT: EF_MIPS_CPIC
+# EXE-R6-NEXT: ]
More information about the llvm-commits
mailing list