diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2000-10-10 14:20:27 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2000-10-10 14:20:27 +0000 |
commit | be85acc16e8aa5c0811bbcd365e0856bd797f50b (patch) | |
tree | 2c48e47470a244e82bf60c027db6cb9d5dbab701 | |
parent | 430070c090c2292083007173e25e04e412059da6 (diff) |
Ajout verification que l'on ne fait pas reference a un module pas encore initialise
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3309 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | otherlibs/dynlink/dynlink.ml | 18 | ||||
-rw-r--r-- | otherlibs/dynlink/dynlink.mli | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/otherlibs/dynlink/dynlink.ml b/otherlibs/dynlink/dynlink.ml index 9f70e63ea..db75219e2 100644 --- a/otherlibs/dynlink/dynlink.ml +++ b/otherlibs/dynlink/dynlink.ml @@ -19,6 +19,7 @@ open Emitcode type linking_error = Undefined_global of string | Unavailable_primitive of string + | Uninitialized_global of string type error = Not_a_bytecode_file of string @@ -108,6 +109,19 @@ let check_unsafe_module cu = if (not !unsafe_allowed) & cu.cu_primitives <> [] then raise(Error(Unsafe_file)) +(* Check that all globals referenced in the object file have been + initialized already *) + +let check_global_references file_name patchlist = + List.iter + (function + (Reloc_getglobal id, pos) -> + if Obj.is_int (Symtable.get_global_value id) then + raise(Error(Linking_error(file_name, + Uninitialized_global(Ident.name id)))) + | _ -> ()) + patchlist + (* Load in-core and execute a bytecode object file *) let load_compunit ic file_name compunit = @@ -128,6 +142,7 @@ let load_compunit ic file_name compunit = let initial_symtable = Symtable.current_state() in begin try Symtable.patch_object code compunit.cu_reloc; + check_global_references file_name compunit.cu_reloc; Symtable.update_global_table() with Symtable.Error error -> let new_error = @@ -191,6 +206,9 @@ let error_message = function | Linking_error (name, Unavailable_primitive s) -> "error while linking " ^ name ^ ".\n" ^ "The external function `" ^ s ^ "' is not available" + | Linking_error (name, Uninitialized_global s) -> + "error while linking " ^ name ^ ".\n" ^ + "The module `" ^ s ^ "' is not yet initialized" | Corrupted_interface name -> "corrupted interface file " ^ name diff --git a/otherlibs/dynlink/dynlink.mli b/otherlibs/dynlink/dynlink.mli index d9cb2c013..22edece3d 100644 --- a/otherlibs/dynlink/dynlink.mli +++ b/otherlibs/dynlink/dynlink.mli @@ -55,6 +55,7 @@ val allow_unsafe_modules : bool -> unit type linking_error = Undefined_global of string | Unavailable_primitive of string + | Uninitialized_global of string type error = Not_a_bytecode_file of string | Inconsistent_import of string |