<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 28, 2016 at 11:12 PM, Davide Italiano 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: davide<br>
Date: Wed Jun 29 01:12:39 2016<br>
New Revision: 274107<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=274107&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=274107&view=rev</a><br>
Log:<br>
[LTO] Infer ELFKind/EMachine from Bitcode files<br>
<br>
So that users are not forced to pass `-m` on the command line<br>
when the inputs are all bitcode.<br>
<br>
PR:   28268<br>
Differential Revision:  <a href="http://reviews.llvm.org/D21779" rel="noreferrer" target="_blank">http://reviews.llvm.org/D21779</a><br>
<br>
Modified:<br>
    lld/trunk/ELF/InputFiles.cpp<br>
    lld/trunk/test/ELF/lto/pic.ll<br>
<br>
Modified: lld/trunk/ELF/InputFiles.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=274107&r1=274106&r2=274107&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=274107&r1=274106&r2=274107&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.cpp (original)<br>
+++ lld/trunk/ELF/InputFiles.cpp Wed Jun 29 01:12:39 2016<br>
@@ -14,6 +14,7 @@<br>
 #include "SymbolTable.h"<br>
 #include "Symbols.h"<br>
 #include "llvm/ADT/STLExtras.h"<br>
+#include "llvm/Bitcode/ReaderWriter.h"<br>
 #include "llvm/CodeGen/Analysis.h"<br>
 #include "llvm/IR/LLVMContext.h"<br>
 #include "llvm/IR/Module.h"<br>
@@ -552,7 +553,45 @@ template <class ELFT> void SharedFile<EL<br>
   }<br>
 }<br>
<br>
-BitcodeFile::BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}<br>
+static ELFKind getELFKind(MemoryBufferRef MB) {<br>
+  std::string TripleStr = getBitcodeTargetTriple(MB, Driver->Context);<br>
+  Triple TheTriple(TripleStr);<br>
+  bool Is64Bits = TheTriple.isArch64Bit();<br>
+  if (TheTriple.isLittleEndian())<br>
+    return Is64Bits ? ELF64LEKind : ELF32LEKind;<br>
+  return Is64Bits ? ELF64BEKind : ELF32BEKind;<br>
+}<br>
+<br>
+static uint8_t getMachineKind(MemoryBufferRef MB) {<br>
+  std::string TripleStr = getBitcodeTargetTriple(MB, Driver->Context);<br>
+  switch (Triple(TripleStr).getArch()) {<br>
+    case Triple::aarch64:<br>
+      return EM_AARCH64;<br>
+    case Triple::arm:<br>
+      return EM_ARM;<br>
+    case Triple::mips:<br>
+    case Triple::mipsel:<br>
+    case Triple::mips64:<br>
+    case Triple::mips64el:<br>
+      return EM_MIPS;<br>
+    case Triple::ppc:<br>
+      return EM_PPC;<br>
+    case Triple::ppc64:<br>
+      return EM_PPC64;<br>
+    case Triple::x86:<br>
+      return EM_386;<br>
+    case Triple::x86_64:<br>
+      return EM_X86_64;<br>
+    default:<br>
+      fatal("unsupported architecture: " + TripleStr);<br></blockquote><div><br></div><div>Can this message be refined? Maybe something like "could not infer e_machine from bitcode target triple '<thetriple>'"?</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  }<br>
+}<br>
+<br>
+BitcodeFile::BitcodeFile(MemoryBufferRef MB) :<br>
+    InputFile(BitcodeKind, MB) {<br>
+  EKind = getELFKind(MB);<br>
+  EMachine = getMachineKind(MB);<br>
+}<br>
<br>
 static uint8_t getGvVisibility(const GlobalValue *GV) {<br>
   switch (GV->getVisibility()) {<br>
<br>
Modified: lld/trunk/test/ELF/lto/pic.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/pic.ll?rev=274107&r1=274106&r2=274107&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/pic.ll?rev=274107&r1=274106&r2=274107&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/lto/pic.ll (original)<br>
+++ lld/trunk/test/ELF/lto/pic.ll Wed Jun 29 01:12:39 2016<br>
@@ -1,7 +1,7 @@<br>
 ; REQUIRES: x86<br>
<br>
 ; RUN: llvm-as %s -o %t.o<br>
-; RUN: ld.lld %t.o -m elf_x86_64 -o %t.so -shared<br>
+; RUN: ld.lld %t.o -o %t.so -shared<br>
 ; RUN: llvm-readobj -r %t.so | FileCheck %s<br>
<br>
 ; CHECK:      Relocations [<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>