diff options
| author | Xavier Leroy <xavier.leroy@inria.fr> | 2012-03-21 14:31:18 +0000 |
|---|---|---|
| committer | Xavier Leroy <xavier.leroy@inria.fr> | 2012-03-21 14:31:18 +0000 |
| commit | 8313b6b4ff5a044f8e55c9084e2df142b868c50e (patch) | |
| tree | 95a2173d5ef2f8c62669d0abce7d83d7786b7835 /otherlibs | |
| parent | 853fa0207e1d0be44dfb2b6f931b42b0713e735c (diff) | |
| download | ocaml-8313b6b4ff5a044f8e55c9084e2df142b868c50e.tar.gz | |
PR#5215 continued: as unique ident for dynlinked bytecode units, use MD5 of .cmo/.cma file combined with name of unit within the .cma
git-svn-id: http://caml.inria.fr/svn/ocaml/version/4.00@12253 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs')
| -rw-r--r-- | otherlibs/dynlink/dynlink.ml | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/otherlibs/dynlink/dynlink.ml b/otherlibs/dynlink/dynlink.ml index 64cd9c3b16..7415ae6c2d 100644 --- a/otherlibs/dynlink/dynlink.ml +++ b/otherlibs/dynlink/dynlink.ml @@ -158,10 +158,10 @@ let check_unsafe_module cu = (* Load in-core and execute a bytecode object file *) -external register_code_fragment: string -> int -> unit +external register_code_fragment: string -> int -> string -> unit = "caml_register_code_fragment" -let load_compunit ic file_name compunit = +let load_compunit ic file_name file_digest compunit = check_consistency file_name compunit; check_unsafe_module compunit; seek_in ic compunit.cu_pos; @@ -190,7 +190,11 @@ let load_compunit ic file_name compunit = | _ -> assert false in raise(Error(Linking_error (file_name, new_error))) end; - register_code_fragment code code_size; + (* PR#5215: identify this code fragment by + digest of file contents + unit name. + Unit name is needed for .cma files, which produce several code fragments.*) + let digest = Digest.string (file_digest ^ compunit.cu_name) in + register_code_fragment code code_size digest; begin try ignore((Meta.reify_bytecode code code_size) ()) with exn -> @@ -202,6 +206,8 @@ let loadfile file_name = init(); if not (Sys.file_exists file_name) then raise(Error (File_not_found file_name)); let ic = open_in_bin file_name in + let file_digest = Digest.channel ic (-1) in + seek_in ic 0; try let buffer = try Misc.input_bytes ic (String.length Config.cmo_magic_number) @@ -210,7 +216,8 @@ let loadfile file_name = if buffer = Config.cmo_magic_number then begin let compunit_pos = input_binary_int ic in (* Go to descriptor *) seek_in ic compunit_pos; - load_compunit ic file_name (input_value ic : compilation_unit) + let cu = (input_value ic : compilation_unit) in + load_compunit ic file_name file_digest cu end else if buffer = Config.cma_magic_number then begin let toc_pos = input_binary_int ic in (* Go to table of contents *) @@ -222,7 +229,7 @@ let loadfile file_name = with Failure reason -> raise(Error(Cannot_open_dll reason)) end; - List.iter (load_compunit ic file_name) lib.lib_units + List.iter (load_compunit ic file_name file_digest) lib.lib_units end else raise(Error(Not_a_bytecode_file file_name)); close_in ic |
