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

Improve error message for link order error in bytelink #2245

Merged
merged 1 commit into from
May 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ Working version
destructive substitutions
(Thomas Refis, review by Gabriel Radanne, report by Hugo Heuzard)

- #2245: Improve error message for link order error in bytecode
(Pierre Chambart, review by Jérémie Dimino and Gabriel Scherer)

- #8732, improved error messages for invalid private row type definitions.
For instance, [ type t = private [< `A > `A ] ] .
(Florian Angeletti, review by Jacques Garrigue, Thomas Refis,
Expand Down
21 changes: 19 additions & 2 deletions bytecomp/bytelink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type error =
| Cannot_open_dll of filepath
| Required_module_unavailable of modname * modname
| Camlheader of string * filepath
| Wrong_link_order of (modname * modname) list

exception Error of error

Expand Down Expand Up @@ -87,6 +88,8 @@ let add_ccobjs origin l =
(* First pass: determine which units are needed *)

let missing_globals = ref Ident.Map.empty
let provided_globals = ref Ident.Set.empty
let badly_ordered_dependencies : (string * string) list ref = ref []

let is_required (rel, _pos) =
match rel with
Expand All @@ -96,6 +99,9 @@ let is_required (rel, _pos) =

let add_required compunit =
let add id =
if Ident.Set.mem id !provided_globals then
badly_ordered_dependencies :=
((Ident.name id), compunit.cu_name) :: !badly_ordered_dependencies;
missing_globals := Ident.Map.add id compunit.cu_name !missing_globals
in
List.iter add (Symtable.required_globals compunit.cu_reloc);
Expand All @@ -104,7 +110,8 @@ let add_required compunit =
let remove_required (rel, _pos) =
match rel with
Reloc_setglobal id ->
missing_globals := Ident.Map.remove id !missing_globals
missing_globals := Ident.Map.remove id !missing_globals;
provided_globals := Ident.Set.add id !provided_globals;
| _ -> ()

let scan_file obj_name tolink =
Expand Down Expand Up @@ -627,7 +634,11 @@ let link objfiles output_name =
match Ident.Map.bindings missing_modules with
| [] -> ()
| (id, cu_name) :: _ ->
raise (Error (Required_module_unavailable (Ident.name id, cu_name)))
match !badly_ordered_dependencies with
| [] ->
raise (Error (Required_module_unavailable (Ident.name id, cu_name)))
| l ->
raise (Error (Wrong_link_order l))
end;
Clflags.ccobjs := !Clflags.ccobjs @ !lib_ccobjs; (* put user's libs last *)
Clflags.all_ccopts := !lib_ccopts @ !Clflags.all_ccopts;
Expand Down Expand Up @@ -763,6 +774,12 @@ let report_error ppf = function
fprintf ppf "Module `%s' is unavailable (required by `%s')" s m
| Camlheader (msg, header) ->
fprintf ppf "System error while copying file %s: %s" header msg
| Wrong_link_order l ->
let depends_on ppf (dep, depending) =
fprintf ppf "%s depends on %s" depending dep
in
fprintf ppf "@[<hov 2>Wrong link order: %a@]"
(pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf ",@ ") depends_on) l

let () =
Location.register_error_of_exn
Expand Down
1 change: 1 addition & 0 deletions bytecomp/bytelink.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type error =
| Cannot_open_dll of filepath
| Required_module_unavailable of modname * modname
| Camlheader of string * filepath
| Wrong_link_order of (modname * modname) list

exception Error of error

Expand Down