<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 20, 2016 at 4:15 PM, Simon Atanasyan via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: atanasyan<br>
Date: Wed Jul 20 15:15:24 2016<br>
New Revision: 276172<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=276172&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=276172&view=rev</a><br>
Log:<br>
[ELF][MIPS] Pick arch flag from the first input file.<br>
<br>
LLD still does not produce a correct combination of MIPS ELF flags if<br>
input files have different sets of ELF flags (i.e. EF_MIPS_ARCH_32 and<br>
EF_MIPS_ARCH_32R2). But now we do not stick to "R2" ABI version and can<br>
emit EF_MIPS_ARCH_32R6 for example.<br>
<br>
Modified:<br>
lld/trunk/ELF/Writer.cpp<br>
lld/trunk/test/ELF/basic-mips.s<br>
lld/trunk/test/ELF/emulation.s<br>
lld/trunk/test/ELF/mips-elf-flags.s<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=276172&r1=276171&r2=276172&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=276172&r1=276171&r2=276172&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Wed Jul 20 15:15:24 2016<br>
@@ -1166,16 +1166,22 @@ template <class ELFT> void Writer<ELFT>:<br>
}<br>
}<br>
<br>
-static uint32_t getMipsEFlags(bool Is64Bits) {<br>
- // FIXME: In fact ELF flags depends on ELF flags of input object files<br>
- // and selected emulation. For now just use hard coded values.<br>
+template <class ELFT><br>
+static uint32_t getMipsEFlags(bool Is64Bits,<br>
+ const ELFFileBase<ELFT> &FirstElf) {</blockquote><div><br></div><div>You can omit Is64Bits parameter because you can use ELFT::Is64Bits in this function instead. Moreover, you can omit FirstElf because it can be accessed through Config->FirstrObj.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ // FIXME: ELF flags depends on ELF flags of all input object files and<br>
+ // selected emulation. For now pick the arch flag from the fisrt input file<br>
+ // and use hard coded values for other flags.<br>
+ uint32_t FirstElfFlags = FirstElf.getObj().getHeader()->e_flags;<br>
+ uint32_t ElfFlags = FirstElfFlags & EF_MIPS_ARCH;<br>
if (Is64Bits)<br>
- return EF_MIPS_CPIC | EF_MIPS_PIC | EF_MIPS_ARCH_64R2;<br>
-<br>
- uint32_t V = EF_MIPS_CPIC | EF_MIPS_ABI_O32 | EF_MIPS_ARCH_32R2;<br>
- if (Config->Shared)<br>
- V |= EF_MIPS_PIC;<br>
- return V;<br>
+ ElfFlags |= EF_MIPS_CPIC | EF_MIPS_PIC;<br>
+ else {<br>
+ ElfFlags |= EF_MIPS_CPIC | EF_MIPS_ABI_O32;<br>
+ if (Config->Shared)<br>
+ ElfFlags |= EF_MIPS_PIC;<br>
+ }<br>
+ return ElfFlags;<br>
}<br>
<br>
template <class ELFT> static typename ELFT::uint getEntryAddr() {<br>
@@ -1252,7 +1258,7 @@ template <class ELFT> void Writer<ELFT>:<br>
EHdr->e_shstrndx = Out<ELFT>::ShStrTab->SectionIndex;<br>
<br>
if (Config->EMachine == EM_MIPS)<br>
- EHdr->e_flags = getMipsEFlags(ELFT::Is64Bits);<br>
+ EHdr->e_flags = getMipsEFlags(ELFT::Is64Bits, FirstObj);<br>
<br>
if (!Config->Relocatable) {<br>
EHdr->e_phoff = sizeof(Elf_Ehdr);<br>
<br>
Modified: lld/trunk/test/ELF/basic-mips.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-mips.s?rev=276172&r1=276171&r2=276172&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-mips.s?rev=276172&r1=276171&r2=276172&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/basic-mips.s (original)<br>
+++ lld/trunk/test/ELF/basic-mips.s Wed Jul 20 15:15:24 2016<br>
@@ -30,7 +30,7 @@ __start:<br>
# CHECK-NEXT: SectionHeaderOffset: 0x30088<br>
# CHECK-NEXT: Flags [<br>
# CHECK-NEXT: EF_MIPS_ABI_O32<br>
-# CHECK-NEXT: EF_MIPS_ARCH_32R2<br>
+# CHECK-NEXT: EF_MIPS_ARCH_32<br>
# CHECK-NEXT: EF_MIPS_CPIC<br>
# CHECK-NEXT: ]<br>
# CHECK-NEXT: HeaderSize: 52<br>
<br>
Modified: lld/trunk/test/ELF/emulation.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emulation.s?rev=276172&r1=276171&r2=276172&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emulation.s?rev=276172&r1=276171&r2=276172&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/emulation.s (original)<br>
+++ lld/trunk/test/ELF/emulation.s Wed Jul 20 15:15:24 2016<br>
@@ -176,7 +176,7 @@<br>
# MIPS-NEXT: SectionHeaderOffset:<br>
# MIPS-NEXT: Flags [<br>
# MIPS-NEXT: EF_MIPS_ABI_O32<br>
-# MIPS-NEXT: EF_MIPS_ARCH_32R2<br>
+# MIPS-NEXT: EF_MIPS_ARCH_32<br>
# MIPS-NEXT: EF_MIPS_CPIC<br>
# MIPS-NEXT: ]<br>
<br>
@@ -205,7 +205,7 @@<br>
# MIPSEL-NEXT: SectionHeaderOffset:<br>
# MIPSEL-NEXT: Flags [<br>
# MIPSEL-NEXT: EF_MIPS_ABI_O32<br>
-# MIPSEL-NEXT: EF_MIPS_ARCH_32R2<br>
+# MIPSEL-NEXT: EF_MIPS_ARCH_32<br>
# MIPSEL-NEXT: EF_MIPS_CPIC<br>
# MIPSEL-NEXT: ]<br>
<br>
@@ -231,7 +231,7 @@<br>
# MIPS64-NEXT: ProgramHeaderOffset: 0x40<br>
# MIPS64-NEXT: SectionHeaderOffset:<br>
# MIPS64-NEXT: Flags [<br>
-# MIPS64-NEXT: EF_MIPS_ARCH_64R2<br>
+# MIPS64-NEXT: EF_MIPS_ARCH_64<br>
# MIPS64-NEXT: EF_MIPS_CPIC<br>
# MIPS64-NEXT: EF_MIPS_PIC<br>
# MIPS64-NEXT: ]<br>
@@ -258,7 +258,7 @@<br>
# MIPS64EL-NEXT: ProgramHeaderOffset: 0x40<br>
# MIPS64EL-NEXT: SectionHeaderOffset:<br>
# MIPS64EL-NEXT: Flags [<br>
-# MIPS64EL-NEXT: EF_MIPS_ARCH_64R2<br>
+# MIPS64EL-NEXT: EF_MIPS_ARCH_64<br>
# MIPS64EL-NEXT: EF_MIPS_CPIC<br>
# MIPS64EL-NEXT: EF_MIPS_PIC<br>
# MIPS64EL-NEXT: ]<br>
<br>
Modified: lld/trunk/test/ELF/mips-elf-flags.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-elf-flags.s?rev=276172&r1=276171&r2=276172&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-elf-flags.s?rev=276172&r1=276171&r2=276172&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/mips-elf-flags.s (original)<br>
+++ lld/trunk/test/ELF/mips-elf-flags.s Wed Jul 20 15:15:24 2016<br>
@@ -5,6 +5,14 @@<br>
# RUN: llvm-readobj -h %t.so | FileCheck -check-prefix=SO %s<br>
# RUN: ld.lld %t.o -o %t.exe<br>
# RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=EXE %s<br>
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \<br>
+# RUN: -mcpu=mips32r2 %s -o %t-r2.o<br>
+# RUN: ld.lld %t-r2.o -o %t-r2.exe<br>
+# RUN: llvm-readobj -h %t-r2.exe | FileCheck -check-prefix=EXE-R2 %s<br>
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \<br>
+# RUN: -mcpu=mips32r6 %s -o %t-r6.o<br>
+# RUN: ld.lld %t-r6.o -o %t-r6.exe<br>
+# RUN: llvm-readobj -h %t-r6.exe | FileCheck -check-prefix=EXE-R6 %s<br>
<br>
# REQUIRES: mips<br>
<br>
@@ -15,13 +23,25 @@ __start:<br>
<br>
# SO: Flags [<br>
# SO-NEXT: EF_MIPS_ABI_O32<br>
-# SO-NEXT: EF_MIPS_ARCH_32R2<br>
+# SO-NEXT: EF_MIPS_ARCH_32<br>
# SO-NEXT: EF_MIPS_CPIC<br>
# SO-NEXT: EF_MIPS_PIC<br>
# SO-NEXT: ]<br>
<br>
# EXE: Flags [<br>
# EXE-NEXT: EF_MIPS_ABI_O32<br>
-# EXE-NEXT: EF_MIPS_ARCH_32R2<br>
+# EXE-NEXT: EF_MIPS_ARCH_32<br>
# EXE-NEXT: EF_MIPS_CPIC<br>
# EXE-NEXT: ]<br>
+<br>
+# EXE-R2: Flags [<br>
+# EXE-R2-NEXT: EF_MIPS_ABI_O32<br>
+# EXE-R2-NEXT: EF_MIPS_ARCH_32R2<br>
+# EXE-R2-NEXT: EF_MIPS_CPIC<br>
+# EXE-R2-NEXT: ]<br>
+<br>
+# EXE-R6: Flags [<br>
+# EXE-R6-NEXT: EF_MIPS_ABI_O32<br>
+# EXE-R6-NEXT: EF_MIPS_ARCH_32R6<br>
+# EXE-R6-NEXT: EF_MIPS_CPIC<br>
+# EXE-R6-NEXT: ]<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>