[lld] r274107 - [LTO] Infer ELFKind/EMachine from Bitcode files

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 29 09:06:09 PDT 2016


On Wed, Jun 29, 2016 at 1:24 AM, Sean Silva <chisophugis at gmail.com> wrote:
>
>
> On Tue, Jun 28, 2016 at 11:12 PM, Davide Italiano via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: davide
>> Date: Wed Jun 29 01:12:39 2016
>> New Revision: 274107
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=274107&view=rev
>> Log:
>> [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
>>
>> Modified:
>>     lld/trunk/ELF/InputFiles.cpp
>>     lld/trunk/test/ELF/lto/pic.ll
>>
>> Modified: lld/trunk/ELF/InputFiles.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=274107&r1=274106&r2=274107&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/InputFiles.cpp (original)
>> +++ lld/trunk/ELF/InputFiles.cpp Wed Jun 29 01:12:39 2016
>> @@ -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<EL
>>    }
>>  }
>>
>> -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);
>
>
> Can this message be refined? Maybe something like "could not infer e_machine
> from bitcode target triple '<thetriple>'"?
>
> -- Sean Silva
>

Sounds like a good idea, thanks for the suggestion. r274134.



-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list