[PATCH] D21779: [LTO] Infer EKind/EMachine from Bitcode files
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 28 20:55:13 PDT 2016
davide updated this revision to Diff 62174.
davide added a comment.
Rewrite after Rui's refactoring patch went in
http://reviews.llvm.org/D21779
Files:
ELF/InputFiles.cpp
ELF/InputFiles.h
test/ELF/lto/pic.ll
Index: test/ELF/lto/pic.ll
===================================================================
--- test/ELF/lto/pic.ll
+++ 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 [
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -242,6 +242,8 @@
Symbol *createSymbol(const llvm::DenseSet<const llvm::Comdat *> &KeptComdats,
const llvm::object::IRObjectFile &Obj,
const llvm::object::BasicSymbolRef &Sym);
+ ELFKind getELFKind(MemoryBufferRef M);
+ uint8_t getMachineKind(MemoryBufferRef M);
};
// .so file.
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ 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,47 @@
}
}
-BitcodeFile::BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}
+ELFKind BitcodeFile::getELFKind(MemoryBufferRef M) {
+ std::string TripleStr = getBitcodeTargetTriple(M, Driver->Context);
+ Triple TheTriple(TripleStr);
+ bool Is64Bits = TheTriple.isArch64Bit();
+ if (TheTriple.isLittleEndian())
+ return (Is64Bits) ? ELF64LEKind : ELF32LEKind;
+ return (Is64Bits) ? ELF64BEKind : ELF32BEKind;
+}
+
+uint8_t BitcodeFile::getMachineKind(MemoryBufferRef M) {
+ std::string TripleStr = getBitcodeTargetTriple(M, Driver->Context);
+ Triple TheTriple(TripleStr);
+ switch (TheTriple.getArch()) {
+ default:
+ break;
+ case llvm::Triple::aarch64:
+ return EM_AARCH64;
+ case llvm::Triple::arm:
+ return EM_ARM;
+ case llvm::Triple::mips:
+ case llvm::Triple::mipsel:
+ case llvm::Triple::mips64:
+ case llvm::Triple::mips64el:
+ return EM_MIPS;
+ case llvm::Triple::ppc:
+ return EM_PPC;
+ case llvm::Triple::ppc64:
+ return EM_PPC64;
+ case llvm::Triple::x86:
+ return EM_386;
+ case llvm::Triple::x86_64:
+ return EM_X86_64;
+ }
+ fatal("unsupported architecture");
+}
+
+BitcodeFile::BitcodeFile(MemoryBufferRef M) :
+ InputFile(BitcodeKind, M) {
+ EKind = getELFKind(M);
+ EMachine = getMachineKind(M);
+}
static uint8_t getGvVisibility(const GlobalValue *GV) {
switch (GV->getVisibility()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21779.62174.patch
Type: text/x-patch
Size: 2650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160629/2911f520/attachment-0001.bin>
More information about the llvm-commits
mailing list