Skip to content

Commit

Permalink
Support linking with LLVM shared libraries (#1593)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
drvink committed Feb 16, 2024
1 parent 511b64c commit e3a0945
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions bap-llvm.opam.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build: [
[
"ocaml" "tools/configure.ml"
"--with-llvm-config=%{conf-bap-llvm:config}%"
"--%{llvm-shared?disable:enable}%-llvm-static"
]
[
"dune"
Expand Down
8 changes: 6 additions & 2 deletions lib/bap_llvm/config/llvm_configurator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
3 changes: 3 additions & 0 deletions lib/bap_llvm/llvm_disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#if LLVM_VERSION_MAJOR >= 12
#include <llvm/Support/Process.h>
#include <llvm/Support/StringSaver.h>
#if LLVM_VERSION_MAJOR <= 16
#include <llvm/ADT/Optional.h>
#endif
#endif
#include <llvm-c/Target.h>

Expand Down

0 comments on commit e3a0945

Please sign in to comment.