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

Modules name conflict during dynamic loading #6957

Closed
vicuna opened this issue Aug 12, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Aug 12, 2015

Original bug ID: 6957
Reporter: @ivg
Assigned to: @mshinwell
Status: resolved (set by @mshinwell on 2017-06-09T16:09:47Z)
Resolution: duplicate
Priority: normal
Severity: minor
Version: 4.02.2
Target version: later
Category: otherlibs
Related to: #4229 #4231 #4839 #6462 #6950
Monitored by: @ivg

Bug description

Disclaimer

It is hard to reduce this issue to a small test case, mostly because, it looks like that many different parts of infrastructure are involved. So, to reproduce, one need to install bap from opam.

Short description

A dynamically linked module accidentally accesses the same named module from the host program, thus provoking a segfault.

The setup

In BAP library we use dynamic loading to dynamically load program analysis plugins into our main application. Plugins are loaded with Dynlink.load_file and created with our own ocamlbuild plugin, that basically is doing the following: (1) build a cmxa of all files that constitute a plugin, (2) build a shared object from it with ocamlfind ocamlopt -linkpkg -shared xxx.cmxa -o xxx.plugin.

The problem

In main application we have a filename options.ml. In a plugin I also have the same named module, that define a record type and value of that type. Fields of the record are defined as mutable. If I make the fields immutable everything works fine. If I rename the file, there is also no segfaults.

But if everything is left as it is, then when I load and execute the loaded code, the first field of the record is not a None (as it was initialized), but points to Some value, that provokes a segmentation fault, when I try to dereference it.

Wild guess

It looks suspicious that the issue only manifests itself, when field records are marked as mutable. Maybe there is some optimization pass, that is responsible for that.

Steps to reproduce

  1. install bap

$ opam install bap

  1. untar the attached file

$ tar xzvf segfault

  1. compile the plugin

$ bapbuild use.plugin

  1. run the plugin

$ bap -luse /bin/true

File attachments

@vicuna

This comment has been minimized.

Copy link
Author

commented Aug 12, 2015

Comment author: @ivg

on 4.02.3 it is also reproducible

@vicuna

This comment has been minimized.

Copy link
Author

commented Aug 13, 2015

Comment author: @lpw25

Possibly the same as #6462

@vicuna

This comment has been minimized.

Copy link
Author

commented Aug 13, 2015

Comment author: @ivg

yes, looks like another manifestation. We saw that previously, when we link plugin with the a library, that is already linked into a host program. We even created a workaround - our ocamlbuild plugin prevents from this, by excluding this libraries. (I wasn't sure that this was a bug).

It looks like that #4839 is about the same.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 9, 2017

Comment author: @mshinwell

This should be fixed by #1063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.