From f91d502e52ae69865693d4183f9bf6283a9258e2 Mon Sep 17 00:00:00 2001 From: Mark Laws Date: Sat, 9 Sep 2023 01:15:42 +0900 Subject: [PATCH] Support linking with LLVM shared libraries This must be manually enabled by setting the variable `llvm-shared` to a true value in the current opam switch, similar to the existing `llvm-config` variable used by conf-bap-llvm. * bap_llvm/config/llvm_configurator.ml: use `llvm-config --shared-mode` to get the appropriate linking mode * bap_llvm/llvm_disasm.cpp: add missing include for Optional.h --- bap-llvm.opam.template | 1 + lib/bap_llvm/config/llvm_configurator.ml | 8 ++++++-- lib/bap_llvm/llvm_disasm.cpp | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bap-llvm.opam.template b/bap-llvm.opam.template index 8c3c19a0e..8b7096511 100644 --- a/bap-llvm.opam.template +++ b/bap-llvm.opam.template @@ -3,6 +3,7 @@ build: [ [ "ocaml" "tools/configure.ml" "--with-llvm-config=%{conf-bap-llvm:config}%" + "--%{llvm-shared?disable:enable}%-llvm-static" ] [ "dune" diff --git a/lib/bap_llvm/config/llvm_configurator.ml b/lib/bap_llvm/config/llvm_configurator.ml index 5496cd076..961feabd3 100644 --- a/lib/bap_llvm/config/llvm_configurator.ml +++ b/lib/bap_llvm/config/llvm_configurator.ml @@ -30,9 +30,13 @@ let args = [ let () = C.main ~args ~name:"bap-llvm" @@ fun self -> + let linkmode = + "--link-" ^ + (String.strip @@ + C.Process.run_capture_exn self llvm_config ["--shared-mode"]) in C.Flags.write_sexp "link.flags" @@ List.concat [ - llvm self ["--link-static"; "--ldflags"]; - llvm self (["--link-static"; "--libs"] @ llvm_components); + llvm self [linkmode; "--ldflags"]; + llvm self ([linkmode; "--libs"] @ llvm_components); ["-lstdc++"; "-lcurses"; "-lzstd"]; ]; C.Flags.write_sexp "cxx.flags" @@ List.concat [ diff --git a/lib/bap_llvm/llvm_disasm.cpp b/lib/bap_llvm/llvm_disasm.cpp index 41f9bb64f..dad0f52ab 100644 --- a/lib/bap_llvm/llvm_disasm.cpp +++ b/lib/bap_llvm/llvm_disasm.cpp @@ -12,6 +12,9 @@ #if LLVM_VERSION_MAJOR >= 12 #include #include +#if LLVM_VERSION_MAJOR <= 16 +#include +#endif #endif #include