summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2011-06-11 07:24:12 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2011-06-11 07:24:12 +0000
commit03591accc7d24c3c60a53556734ce800b38c8edc (patch)
treea75e945aaca7922022b6751f82130cac078bf8ec
parent9c9ae6153de2240d3b140357e9948c83370172ee (diff)
downloadocaml-03591accc7d24c3c60a53556734ce800b38c8edc.tar.gz
PR#5276: issue with ocamlc -pack and recursively-packed modules
git-svn-id: http://caml.inria.fr/svn/ocaml/version/3.12@11083 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Changes1
-rw-r--r--bytecomp/bytepackager.ml32
2 files changed, 23 insertions, 10 deletions
diff --git a/Changes b/Changes
index 0a7310941d..a00d4ca746 100644
--- a/Changes
+++ b/Changes
@@ -63,6 +63,7 @@ Bug fixes:
- PR#5258: win32unix: unix fd leak under windows
- PR#5269: (tentative fix) Wrong ext_ref entries in .annot files
- PR#5272: caml.el doesn't recognize downto as a keyword
+- PR#5276: issue with ocamlc -pack and recursively-packed modules
- PR#5280: alignment constraints incorrectly autodetected on MIPS 32
- PR#5281: typo in error message
- camlp4 revised syntax printing bug in the toplevel (reported on caml-list)
diff --git a/bytecomp/bytepackager.ml b/bytecomp/bytepackager.ml
index 6649aa3d51..e2b6ff54bb 100644
--- a/bytecomp/bytepackager.ml
+++ b/bytecomp/bytepackager.ml
@@ -39,7 +39,7 @@ let force_link = ref false
SETGLOBAL relocations that correspond to one of the units being
consolidated. *)
-let rename_relocation objfile mapping defined base (rel, ofs) =
+let rename_relocation packagename objfile mapping defined base (rel, ofs) =
let rel' =
match rel with
Reloc_getglobal id ->
@@ -49,7 +49,14 @@ let rename_relocation objfile mapping defined base (rel, ofs) =
then Reloc_getglobal id'
else raise(Error(Forward_reference(objfile, id)))
with Not_found ->
- rel
+ (* PR#5276: unique-ize dotted global names, which appear
+ if one of the units being consolidated is itself a packed
+ module. *)
+ let name = Ident.name id in
+ if String.contains name '.' then
+ Reloc_getglobal (Ident.create_persistent (packagename ^ "." ^ name))
+ else
+ rel
end
| Reloc_setglobal id ->
begin try
@@ -58,7 +65,12 @@ let rename_relocation objfile mapping defined base (rel, ofs) =
then raise(Error(Multiple_definition(objfile, id)))
else Reloc_setglobal id'
with Not_found ->
- rel
+ (* PR#5276, as above *)
+ let name = Ident.name id in
+ if String.contains name '.' then
+ Reloc_setglobal (Ident.create_persistent (packagename ^ "." ^ name))
+ else
+ rel
end
| _ ->
rel in
@@ -112,12 +124,12 @@ let read_member_info file =
Accumulate relocs, debug info, etc.
Return size of bytecode. *)
-let rename_append_bytecode oc mapping defined ofs prefix subst objfile compunit =
+let rename_append_bytecode packagename oc mapping defined ofs prefix subst objfile compunit =
let ic = open_in_bin objfile in
try
Bytelink.check_consistency objfile compunit;
List.iter
- (rename_relocation objfile mapping defined ofs)
+ (rename_relocation packagename objfile mapping defined ofs)
compunit.cu_reloc;
primitives := compunit.cu_primitives @ !primitives;
if compunit.cu_force_link then force_link := true;
@@ -136,20 +148,20 @@ let rename_append_bytecode oc mapping defined ofs prefix subst objfile compunit
(* Same, for a list of .cmo and .cmi files.
Return total size of bytecode. *)
-let rec rename_append_bytecode_list oc mapping defined ofs prefix subst = function
+let rec rename_append_bytecode_list packagename oc mapping defined ofs prefix subst = function
[] ->
ofs
| m :: rem ->
match m.pm_kind with
| PM_intf ->
- rename_append_bytecode_list oc mapping defined ofs prefix subst rem
+ rename_append_bytecode_list packagename oc mapping defined ofs prefix subst rem
| PM_impl compunit ->
let size =
- rename_append_bytecode oc mapping defined ofs prefix subst
+ rename_append_bytecode packagename oc mapping defined ofs prefix subst
m.pm_file compunit in
let id = Ident.create_persistent m.pm_name in
let root = Path.Pident (Ident.create_persistent prefix) in
- rename_append_bytecode_list
+ rename_append_bytecode_list packagename
oc mapping (id :: defined)
(ofs + size) prefix (Subst.add_module id (Path.Pdot (root, Ident.name id, Path.nopos)) subst) rem
@@ -191,7 +203,7 @@ let package_object_files files targetfile targetname coercion =
let pos_depl = pos_out oc in
output_binary_int oc 0;
let pos_code = pos_out oc in
- let ofs = rename_append_bytecode_list oc mapping [] 0 targetname Subst.identity members in
+ let ofs = rename_append_bytecode_list targetname oc mapping [] 0 targetname Subst.identity members in
build_global_target oc targetname members mapping ofs coercion;
let pos_debug = pos_out oc in
if !Clflags.debug && !events <> [] then