Skip to content

Commit

Permalink
Improve error message for link order error in bytelink
Browse files Browse the repository at this point in the history
  • Loading branch information
chambart committed Feb 12, 2019
1 parent 0779456 commit ce76f15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Working version

(Changes that can break existing programs are marked with a "*")

### Compiler user-interface and warnings:

- GPR#XXXX: Improve error message for link order error in bytecode
(Pierre Chambart)

### Internal/compiler-libs changes:

- GPR#2229: Env: remove prefix_idents cache
Expand Down
19 changes: 18 additions & 1 deletion bytecomp/bytelink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type error =
| File_exists of filepath
| Cannot_open_dll of filepath
| Required_module_unavailable of modname
| Wrong_link_order of (modname * modname) list

exception Error of error

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

let missing_globals = ref Ident.Set.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 @@ -95,6 +98,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.Set.add id !missing_globals
in
List.iter add (Symtable.required_globals compunit.cu_reloc);
Expand Down Expand Up @@ -567,7 +573,12 @@ let link objfiles output_name =
begin
match Ident.Set.elements missing_modules with
| [] -> ()
| id :: _ -> raise (Error (Required_module_unavailable (Ident.name id)))
| id :: _ ->
match !badly_ordered_dependencies with
| [] ->
raise (Error (Required_module_unavailable (Ident.name id)))
| 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 @@ -694,6 +705,12 @@ let report_error ppf = function
Location.print_filename file
| Required_module_unavailable s ->
fprintf ppf "Required module `%s' is unavailable" s
| 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 @@ -34,6 +34,7 @@ type error =
| File_exists of filepath
| Cannot_open_dll of filepath
| Required_module_unavailable of modname
| Wrong_link_order of (modname * modname) list

exception Error of error

Expand Down

0 comments on commit ce76f15

Please sign in to comment.