aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2016-06-29 06:12:39 +0000
committerDavide Italiano <davide@freebsd.org>2016-06-29 06:12:39 +0000
commit44becedacc0cf2fb327239bb7725316977e34454 (patch)
tree4aa9c521853c41b2ba480bfb56aad1cf5dbe46c5
parentd36769db932444c9bdd6777ee892813a8cddf503 (diff)
[LTO] Infer ELFKind/EMachine from Bitcode files
So that users are not forced to pass `-m` on the command line when the inputs are all bitcode. PR: 28268 Differential Revision: http://reviews.llvm.org/D21779 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@274107 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--ELF/InputFiles.cpp41
-rw-r--r--test/ELF/lto/pic.ll2
2 files changed, 41 insertions, 2 deletions
diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp
index 786604c8d..eb17d86a4 100644
--- a/ELF/InputFiles.cpp
+++ b/ELF/InputFiles.cpp
@@ -14,6 +14,7 @@
#include "SymbolTable.h"
#include "Symbols.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/CodeGen/Analysis.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
@@ -552,7 +553,45 @@ template <class ELFT> void SharedFile<ELFT>::parseRest() {
}
}
-BitcodeFile::BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}
+static ELFKind getELFKind(MemoryBufferRef MB) {
+ std::string TripleStr = getBitcodeTargetTriple(MB, Driver->Context);
+ Triple TheTriple(TripleStr);
+ bool Is64Bits = TheTriple.isArch64Bit();
+ if (TheTriple.isLittleEndian())
+ return Is64Bits ? ELF64LEKind : ELF32LEKind;
+ return Is64Bits ? ELF64BEKind : ELF32BEKind;
+}
+
+static uint8_t getMachineKind(MemoryBufferRef MB) {
+ std::string TripleStr = getBitcodeTargetTriple(MB, Driver->Context);
+ switch (Triple(TripleStr).getArch()) {
+ case Triple::aarch64:
+ return EM_AARCH64;
+ case Triple::arm:
+ return EM_ARM;
+ case Triple::mips:
+ case Triple::mipsel:
+ case Triple::mips64:
+ case Triple::mips64el:
+ return EM_MIPS;
+ case Triple::ppc:
+ return EM_PPC;
+ case Triple::ppc64:
+ return EM_PPC64;
+ case Triple::x86:
+ return EM_386;
+ case Triple::x86_64:
+ return EM_X86_64;
+ default:
+ fatal("unsupported architecture: " + TripleStr);
+ }
+}
+
+BitcodeFile::BitcodeFile(MemoryBufferRef MB) :
+ InputFile(BitcodeKind, MB) {
+ EKind = getELFKind(MB);
+ EMachine = getMachineKind(MB);
+}
static uint8_t getGvVisibility(const GlobalValue *GV) {
switch (GV->getVisibility()) {
diff --git a/test/ELF/lto/pic.ll b/test/ELF/lto/pic.ll
index 0d61d6a62..abc514d7c 100644
--- a/test/ELF/lto/pic.ll
+++ b/test/ELF/lto/pic.ll
@@ -1,7 +1,7 @@
; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
-; RUN: ld.lld %t.o -m elf_x86_64 -o %t.so -shared
+; RUN: ld.lld %t.o -o %t.so -shared
; RUN: llvm-readobj -r %t.so | FileCheck %s
; CHECK: Relocations [