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

fixes bap.top and baptop #1541

Merged
merged 1 commit into from
Jul 15, 2022

Conversation

ivg
Copy link
Member

@ivg ivg commented Jul 15, 2022

This commit fixes the bap.top library and the baptop executable so that they can now be used. Before that, they were failing with

Exception:
(Invalid_argument
  "The dynlink.cma library cannot be used inside the OCaml toplevel")

The problem was that we were trying to use the dynlink facilities to track the missing units (before that we were using findlib for that so it was working). However, for toplevel we don't need to do this, as the toplevel loader will keep track of the loaded dependencies for us.

This commit fixes the `bap.top` library and the `baptop` executable so
that they can now be used. Before that, they were failing with
```
Exception:
(Invalid_argument
  "The dynlink.cma library cannot be used inside the OCaml toplevel")
```

The problem was that we were trying to use the dynlink facilities to
track the missing units (before that we were using findlib for that so
it was working). However, for toplevel we don't need to do this, as
the toplevel loader will keep track of the loaded dependencies for
us.
@ivg ivg force-pushed the fixes-baptop-and-bap.top branch from 4b5abe2 to 0d305b5 Compare July 15, 2022 18:18
@ivg ivg merged commit b8e12b3 into BinaryAnalysisPlatform:master Jul 15, 2022
@ivg ivg deleted the fixes-baptop-and-bap.top branch August 3, 2022 19:24
ivg added a commit to ivg/bap that referenced this pull request Aug 19, 2022
After we switched to OCaml 4.08 and above, we trashed custom unit
tracking from our plugin system and started to rely on the Dynlink
facility, provided by OCaml, that offers precise unit
tracking. However, Dynlink is not allowed inside OCaml Toplevel, which
wasn't noticed, because it wasn't properly initialized (though
apparently it worked fine for our needs). But after 4.12
(see ocaml/ocaml#9790) it was properly
initialized so we started to get "The dynlink.cma library cannot be used
inside the OCaml toplevel" messages when trying to use `baptop` or
`bap.top`. A quick-fix (BinaryAnalysisPlatform#1541) did only worse as it disabled any unit
tracking and enabled double-loading of plugins and libraries (which is
perfectly allowed in OCaml toplevel and is not a bug, as it was in
regular OCaml runtime). Of course, double-loading could crash bap as
many of bap libraries have their own state, which got reset after
reloading.

This PR restores the old findlib-based unit tracker. This tracker is
not precise and may still miss loaded units. For example, if you load
bap manually and the do `#require "bap.top"` it will reload bap (which
should be a problem, but who knows). With that said, we had used this
tracker for many years, up until BAP 2.4.0, so I do have some trust in
it. Also, I don't want to invest more time in this issue as we are in
the process of switching to dune and thhe dune plugin system (that has
its own unit tracking system, which is precise). To be honest, dune
plugins also do not work in toplevel right now, but this is a
developing story (ocaml/dune#6081) and I
hope that eventually we will have it working.
ivg added a commit that referenced this pull request Aug 19, 2022
After we switched to OCaml 4.08 and above, we trashed custom unit
tracking from our plugin system and started to rely on the Dynlink
facility, provided by OCaml, that offers precise unit
tracking. However, Dynlink is not allowed inside OCaml Toplevel, which
wasn't noticed, because it wasn't properly initialized (though
apparently it worked fine for our needs). But after 4.12
(see ocaml/ocaml#9790) it was properly
initialized so we started to get "The dynlink.cma library cannot be used
inside the OCaml toplevel" messages when trying to use `baptop` or
`bap.top`. A quick-fix (#1541) did only worse as it disabled any unit
tracking and enabled double-loading of plugins and libraries (which is
perfectly allowed in OCaml toplevel and is not a bug, as it was in
regular OCaml runtime). Of course, double-loading could crash bap as
many of bap libraries have their own state, which got reset after
reloading.

This PR restores the old findlib-based unit tracker. This tracker is
not precise and may still miss loaded units. For example, if you load
bap manually and the do `#require "bap.top"` it will reload bap (which
should be a problem, but who knows). With that said, we had used this
tracker for many years, up until BAP 2.4.0, so I do have some trust in
it. Also, I don't want to invest more time in this issue as we are in
the process of switching to dune and thhe dune plugin system (that has
its own unit tracking system, which is precise). To be honest, dune
plugins also do not work in toplevel right now, but this is a
developing story (ocaml/dune#6081) and I
hope that eventually we will have it working.
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.

1 participant