diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -103,6 +103,11 @@ cl::desc("Add system library paths to library search paths"), cl::init(false), cl::cat(JITLinkCategory)); +static cl::opt + TripleName("triple", + cl::desc("Override the detected target triple for disassembler"), + cl::cat(JITLinkCategory)); + static cl::opt NoExec("noexec", cl::desc("Do not execute loaded code"), cl::init(false), cl::cat(JITLinkCategory)); @@ -1997,7 +2002,17 @@ std::unique_ptr Timers = ShowTimes ? std::make_unique() : nullptr; + // Infer the target and override TT if triple is given by user auto [TT, Features] = getFirstFileTripleAndFeatures(); + if (TripleName != "") { + TT = Triple(Triple::normalize(TripleName)); + std::string ErrorStr; + if (!TargetRegistry::lookupTarget("", TT, ErrorStr)) + ExitOnErr(make_error("Error accessing target '" + + TripleName + "': " + ErrorStr, + inconvertibleErrorCode())); + } + ExitOnErr(sanitizeArguments(TT, argv[0])); auto S = ExitOnErr(Session::Create(std::move(TT), std::move(Features)));