diff options
author | Lukas Zaoral <lzaoral@redhat.com> | 2021-04-20 23:25:39 +0200 |
---|---|---|
committer | MartinNowack <2443641+MartinNowack@users.noreply.github.com> | 2021-10-27 12:06:36 +0100 |
commit | f64ac45c41042e6d33024958dc82b6849844cdac (patch) | |
tree | 9639e0861ebab0fd20f9981d9c183d38eb7841ea /lib | |
parent | 2e397d9e42c640f705da70cb64ff3ada05119a5b (diff) | |
download | klee-f64ac45c41042e6d33024958dc82b6849844cdac.tar.gz |
Module/RaiseAsm: Fix crash when host and bitcode target triples differ
RaiseAsm always created a target machine for the host target and not for the bitcode one. Therefore, KLEE could crash on i686 bitcode as x86_64 target machine cannot be used to raise i686 assembly. Fixes: LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Module/RaiseAsm.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp index ff4c2467..cd8f7934 100644 --- a/lib/Module/RaiseAsm.cpp +++ b/lib/Module/RaiseAsm.cpp @@ -86,28 +86,31 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) { bool RaiseAsmPass::runOnModule(Module &M) { bool changed = false; - std::string Err; - std::string HostTriple = llvm::sys::getDefaultTargetTriple(); - const Target *NativeTarget = TargetRegistry::lookupTarget(HostTriple, Err); + + // Use target triple from the module if possible. + std::string TargetTriple = M.getTargetTriple(); + if (TargetTriple.empty()) + TargetTriple = llvm::sys::getDefaultTargetTriple(); + const Target *Target = TargetRegistry::lookupTarget(TargetTriple, Err); TargetMachine * TM = 0; - if (NativeTarget == 0) { - klee_warning("Warning: unable to select native target: %s", Err.c_str()); + if (Target == 0) { + klee_warning("Warning: unable to select target: %s", Err.c_str()); TLI = 0; } else { #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9) - TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions(), - None); + TM = Target->createTargetMachine(TargetTriple, "", "", TargetOptions(), + None); TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering(); #else - TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions()); + TM = Target->createTargetMachine(TargetTriple, "", "", TargetOptions()); TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering(); #endif - triple = llvm::Triple(HostTriple); + triple = llvm::Triple(TargetTriple); } - + for (Module::iterator fi = M.begin(), fe = M.end(); fi != fe; ++fi) { for (Function::iterator bi = fi->begin(), be = fi->end(); bi != be; ++bi) { for (BasicBlock::iterator ii = bi->begin(), ie = bi->end(); ii != ie;) { |