Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support linking with LLVM shared libraries #1593

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

drvink
Copy link
Contributor

@drvink drvink commented Sep 8, 2023

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

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
Copy link
Member

@ivg ivg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions in the code. And the main question: it is not clear to me that the static mode is the default (which I would like to have). Is that right? We need statically linked and self-contained bap. Of course, having an ability to dynamically link with llvm would be nice (especially since some distributions do not distribute statically linked llvm) as we do have with the OASIS and OMake build systems.

let linkmode =
"--link-" ^
(String.strip @@
C.Process.run_capture_exn self llvm_config ["--shared-mode"]) in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the --shared-mode command-line option is present on all llvm versions that we support? Maybe, it is better to be more defensive here (both against previous and future versions) and anticipate possible failures by sticking with the static mode by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It exists at least as far back as llvm 4.0. I don't know if there's a great solution here in general, since the installed version of llvm could change since bap was built, and then we might have a mismatch of the linking mode anyway.

@@ -3,6 +3,7 @@ build: [
[
"ocaml" "tools/configure.ml"
"--with-llvm-config=%{conf-bap-llvm:config}%"
"--%{llvm-shared?disable:enable}%-llvm-static"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, didn't know about this syntax, is it new? (I mean will it work with opam 2.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was added in opam 1.2.1.

@drvink
Copy link
Contributor Author

drvink commented Feb 15, 2024

Is anything preventing this from being merged?

@ivg ivg merged commit e3a0945 into BinaryAnalysisPlatform:master Feb 16, 2024
8 checks passed
@ivg
Copy link
Member

ivg commented Feb 16, 2024

Is anything preventing this from being merged?

No, not really. There was an issue with the build action, but it looks like it wasn't the problem of this PR, I will look at it later! Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants