Skip to content

Commit e3a0945

Browse files
authored
Support linking with LLVM shared libraries (#1593)
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
1 parent 511b64c commit e3a0945

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

bap-llvm.opam.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ build: [
33
[
44
"ocaml" "tools/configure.ml"
55
"--with-llvm-config=%{conf-bap-llvm:config}%"
6+
"--%{llvm-shared?disable:enable}%-llvm-static"
67
]
78
[
89
"dune"

lib/bap_llvm/config/llvm_configurator.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ let args = [
3030

3131

3232
let () = C.main ~args ~name:"bap-llvm" @@ fun self ->
33+
let linkmode =
34+
"--link-" ^
35+
(String.strip @@
36+
C.Process.run_capture_exn self llvm_config ["--shared-mode"]) in
3337
C.Flags.write_sexp "link.flags" @@ List.concat [
34-
llvm self ["--link-static"; "--ldflags"];
35-
llvm self (["--link-static"; "--libs"] @ llvm_components);
38+
llvm self [linkmode; "--ldflags"];
39+
llvm self ([linkmode; "--libs"] @ llvm_components);
3640
["-lstdc++"; "-lcurses"; "-lzstd"];
3741
];
3842
C.Flags.write_sexp "cxx.flags" @@ List.concat [

lib/bap_llvm/llvm_disasm.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#if LLVM_VERSION_MAJOR >= 12
1313
#include <llvm/Support/Process.h>
1414
#include <llvm/Support/StringSaver.h>
15+
#if LLVM_VERSION_MAJOR <= 16
16+
#include <llvm/ADT/Optional.h>
17+
#endif
1518
#endif
1619
#include <llvm-c/Target.h>
1720

0 commit comments

Comments
 (0)