Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005276OCaml~DO NOT USE (was: OCaml general)public2011-05-23 15:122012-09-25 20:06
Assigned Toxleroy 
PlatformallOSallOS Versionall
Product Version3.12.0 
Target VersionFixed in Version3.12.1+dev 
Summary0005276: bug in bytecode packing algorithm
DescriptionThe algorithm used to pack bytecode units does not work correctly with hierarchical packing. It prefixes modules with the name of their package, but it does not prefix sub-modules, i.e. modules that have already been packed.

The problem arises when a package contains a package with the same name, in which case it is not possible to distinguish between the package modules and the sub-package modules.
Steps To ReproduceSee the attached archive.

1- I create a first package a/a/a.cmo containing a module X (which becomes A.X)
2- I then create a second package a/b.cmo containing the module A (X is still A.X, should have become B.A.X)
3- A module C has a reference to X.x, and prints it
4- I create a final package a.cmo, containing a/x.cmo, a/b.cmo and a/c.cmo
5- When I run that module, C displays the value of X.x found in B.A.X (2) instead of the one in A.X (1)
Additional InformationTo fix it, the algorithm should not only prefix the packaged modules, but also the modules packaged within those modules (it could check that they contain a dot, and immediatly prefix them).
TagsNo tags attached.
Attached Filesgz file icon bug-pack-bytecode.tar.gz [^] (468 bytes) 2011-05-23 15:12
patch file icon 0001-Fixed-bug-in-bytecode-packing-algorithm.patch [^] (4,231 bytes) 2011-05-23 15:37 [Show Content]

- Relationships

-  Notes
lefessan (developer)
2011-05-23 15:38
edited on: 2011-05-23 15:39

0001-Fixed-bug-in-bytecode-packing-algorithm.patch is supposed to fix the issue (beware when applying the patch that I am working in a GIT repository where the distribution is prefixed by "inline-more", so the patch should be applied at the correct level).

Note also that the bug can trigger segfaults (although my show case is purposely just displaying a bad result).

xleroy (administrator)
2011-06-10 18:07

Hi Fabrice,

Looking at the fix, it is not clear to me why *all* global names containing a dot must be prefixed by the package name. Couldn't one of these dotted global names refer to something defined outside the package being built? Just curious. -X
lefessan (developer)
2011-06-10 18:13

As far as I know, globals outside the current modules cannot contain dots, since the dotted notation X.Y is translated into a field access into the global X. Of course, it is possible that somebody used module identifiers with dots as a trick somewhere else in the compiler, but I am not aware of it.

Another solution could be to force the use of -for-pack in bytecode, and directly use the final name everywhere from the beginning...
xleroy (administrator)
2011-06-11 09:30

You're right, "dotted" global names can only appear as temporaries when initializing a packed module. So, if ocamlc -pack sees such a global, it must come from one of the units being packed.

Applied the patch (with a simplification: String.contains instead of String.index) in 3.12 bugfix branch. Will go in 3.12.1.

- Issue History
Date Modified Username Field Change
2011-05-23 15:12 lefessan New Issue
2011-05-23 15:12 lefessan File Added: bug-pack-bytecode.tar.gz
2011-05-23 15:37 lefessan File Added: 0001-Fixed-bug-in-bytecode-packing-algorithm.patch
2011-05-23 15:38 lefessan Note Added: 0005927
2011-05-23 15:39 lefessan Note Edited: 0005927
2011-06-01 23:41 doligez Status new => acknowledged
2011-06-10 18:07 xleroy Note Added: 0005999
2011-06-10 18:07 xleroy Status acknowledged => feedback
2011-06-10 18:13 lefessan Note Added: 0006000
2011-06-11 09:30 xleroy Note Added: 0006001
2011-06-11 09:30 xleroy Status feedback => resolved
2011-06-11 09:30 xleroy Resolution open => fixed
2011-06-11 09:30 xleroy Fixed in Version => 3.12.1+dev
2011-06-11 09:31 xleroy Assigned To => xleroy
2012-09-25 20:06 xleroy Status resolved => closed
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker