diff options
| author | Davide Italiano <davide@freebsd.org> | 2016-06-29 06:12:39 +0000 |
|---|---|---|
| committer | Davide Italiano <davide@freebsd.org> | 2016-06-29 06:12:39 +0000 |
| commit | 60976ba86dae6a9a60d5b0c13ca884573ec1ae3a (patch) | |
| tree | 955a0075ec96f3147592614617417c54d6503ade /lld/ELF/InputFiles.cpp | |
| parent | 34e4e477c869f0e4f69935defba0eba5a1a7c3f4 (diff) | |
| download | bcm5719-llvm-60976ba86dae6a9a60d5b0c13ca884573ec1ae3a.tar.gz bcm5719-llvm-60976ba86dae6a9a60d5b0c13ca884573ec1ae3a.zip | |
[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
llvm-svn: 274107
Diffstat (limited to 'lld/ELF/InputFiles.cpp')
| -rw-r--r-- | lld/ELF/InputFiles.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 786604c8d6b..eb17d86a41d 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/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()) { |

