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

Double linking of native modules (with -pack) #5473

Closed
vicuna opened this issue Jan 12, 2012 · 3 comments
Closed

Double linking of native modules (with -pack) #5473

vicuna opened this issue Jan 12, 2012 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Jan 12, 2012

Original bug ID: 5473
Reporter: @alainfrisch
Status: confirmed (set by @xavierleroy on 2012-01-17T14:52:31Z)
Resolution: open
Priority: low
Severity: minor
Category: compiler driver
Related to: #3488 #4231
Monitored by: @hcarty

Bug description

The code below allows us to link several modules with the same name and thus break the type system (-> segfault).

Proposal: -pack should fail if one the packed modules depends on the .cmi of a module which is itself not part of the package to be created, and whose signature refers to one the packed modules. In the example: the packed x.cmo depends on the non-packed api.cmi, whose signature mentions Abstract, which itself is part of the package. This creates an opportunity for shadowing Abstract with a different module outside the package.

Steps to reproduce

abstract.mli = sub/abstract.mli:
type t
val x: t
val f: t -> unit

abstract.ml:
type t = int
let x = 10
let f x = Printf.printf "Abstract 1 : %i\n" x

sub/abstract.ml:
type t = string
let x = "foo"
let f x = Printf.printf "Abstract 2 : %s\n" x

api.ml:
let r : Abstract.t list ref = ref []

x.ml = sub/x.ml:
let () = Api.r := Abstract.x :: !Api.r; List.iter Abstract.f !Api.r

compilation:
$ ocamlopt -c abstract.mli abstract.ml api.ml x.ml
$ cd sub
$ ocamlopt -c -for-pack P -I .. x.ml
$ ocamlopt -c -for-pack P -I .. abstract.mli
$ ocamlopt -c -for-pack P -I .. abstract.ml
$ ocamlopt -pack -o p.cmx abstract.cmx x.cmx
$ cd ..
$ ocamlopt -o main api.cmx abstract.cmx x.cmx sub/p.cmx
$ ./main
zsh: segmentation fault ./main

@vicuna
Copy link
Author

vicuna commented Dec 9, 2015

Comment author: @alainfrisch

Note: we now get

ocamlopt -pack -o p.cmx abstract.cmx x.cmx
File "p.cmx", line 1:
Error: Files x.cmx and abstract.cmx
       make inconsistent assumptions over implementation Abstract

Here are updated build instructions which avoid this error and allow to get the segfault:

rm -f *.cm* sub/*.cm* main
ocamlopt -c abstract.mli abstract.ml api.ml x.ml
cp api.cmi sub/
(cd sub && ocamlopt -c -for-pack P abstract.mli abstract.ml x.ml)
(cd sub && ocamlopt -pack -o p.cmx abstract.cmx x.cmx)
ocamlopt -o main api.cmx abstract.cmx x.cmx sub/p.cmx
./main

--> segfault, and same in bytecode.

@mshinwell
Copy link
Contributor

I'm not completely sure, but it is possible the recent work on functor packs (which has involved some more fundamental work on the packing system) might help here.

@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

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

No branches or pull requests

2 participants