From 637276d01f42b4214bf18e7db5a0ea39c81985ae Mon Sep 17 00:00:00 2001 From: Benjamin Mourad Date: Thu, 15 Feb 2024 19:17:06 -0500 Subject: [PATCH] Fixes for LLVM 17 (as well as LLVM 16) (#1597) --- lib/bap_llvm/llvm_disasm.cpp | 16 ++++++++++++++++ lib/bap_llvm/llvm_loader_utils.hpp | 4 ++++ lib/bap_llvm/llvm_primitives.cpp | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/lib/bap_llvm/llvm_disasm.cpp b/lib/bap_llvm/llvm_disasm.cpp index dad0f52ab..32e59b749 100644 --- a/lib/bap_llvm/llvm_disasm.cpp +++ b/lib/bap_llvm/llvm_disasm.cpp @@ -33,6 +33,9 @@ #include #include #include +#if LLVM_VERSION_MAJOR >= 16 +#include +#endif #include "disasm.hpp" #include "llvm_disasm.h" @@ -40,7 +43,11 @@ #include #include +#if LLVM_VERSION_MAJOR >= 17 +#include +#else #include +#endif #include template @@ -467,7 +474,12 @@ class llvm_disassembler : public disassembler_interface { } else if (p == is_true) { return true; } else { +#if LLVM_VERSION_MAJOR >= 16 + // MCInstrDesc needs to know its own address to access some implicit tables. + auto &d = ins_info->get(current.code); +#else auto d = ins_info->get(current.code); +#endif if (p == may_affect_control_flow) { return d.mayAffectControlFlow(mcinst, *reg_info); } else if (auto check = fun_of_pred(p)) { @@ -655,7 +667,11 @@ struct create_llvm_disassembler : disasm_factory { static void parse_environment_options(const char *prog_name, const char *env_var) { #if LLVM_VERSION_MAJOR >= 12 +#if LLVM_VERSION_MAJOR >= 16 + std::optional env_value = llvm::sys::Process::GetEnv(llvm::StringRef(env_var)); +#else llvm::Optional env_value = llvm::sys::Process::GetEnv(llvm::StringRef(env_var)); +#endif if (!env_value) return; diff --git a/lib/bap_llvm/llvm_loader_utils.hpp b/lib/bap_llvm/llvm_loader_utils.hpp index 286203265..39b8ae230 100644 --- a/lib/bap_llvm/llvm_loader_utils.hpp +++ b/lib/bap_llvm/llvm_loader_utils.hpp @@ -5,7 +5,11 @@ #include #include +#if LLVM_VERSION_MAJOR >= 17 +#include +#else #include +#endif #include "llvm_error_or.hpp" diff --git a/lib/bap_llvm/llvm_primitives.cpp b/lib/bap_llvm/llvm_primitives.cpp index 460376e79..2698dfd7b 100644 --- a/lib/bap_llvm/llvm_primitives.cpp +++ b/lib/bap_llvm/llvm_primitives.cpp @@ -1,6 +1,11 @@ #include +#include +#if LLVM_VERSION_MAJOR >= 17 +#include +#else #include +#endif #include "llvm_primitives.hpp"