Skip to content

Commit

Permalink
Compiler: fix link of packed modules
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Jul 24, 2024
1 parent 0f5949c commit 53f4db0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
15 changes: 15 additions & 0 deletions compiler/lib/ocaml_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ module Cmo_format = struct
let requires (t : t) = List.map t.cu_required_compunits ~f:(fun (Compunit u) -> u)
[@@if ocaml_version >= (5, 2, 0)]

let provides (t : t) =
List.filter_map t.cu_reloc ~f:(fun ((reloc : Cmo_format.reloc_info), _) ->
match reloc with
| Reloc_setglobal i -> Some (Ident.name i)
| Reloc_getglobal _ | Reloc_literal _ | Reloc_primitive _ -> None)
[@@if ocaml_version < (5, 2, 0)]

let provides (t : t) =
List.filter_map t.cu_reloc ~f:(fun ((reloc : Cmo_format.reloc_info), _) ->
match reloc with
| Reloc_setcompunit (Compunit u) -> Some u
| Reloc_getcompunit _ | Reloc_getpredef _ | Reloc_literal _ | Reloc_primitive _ ->
None)
[@@if ocaml_version >= (5, 2, 0)]

let primitives (t : t) = t.cu_primitives

let imports (t : t) = t.cu_imports
Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/ocaml_compiler.mli
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ module Cmo_format : sig

val requires : t -> string list

val provides : t -> string list

val primitives : t -> string list

val force_link : t -> bool
Expand Down
3 changes: 2 additions & 1 deletion compiler/lib/unit_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ let of_primitives l =

let of_cmo (cmo : Cmo_format.compilation_unit) =
let open Ocaml_compiler in
let provides = StringSet.singleton (Cmo_format.name cmo) in
(* A packed librariy register global for packed modules. *)
let provides = StringSet.of_list (Cmo_format.name cmo :: Cmo_format.provides cmo) in
let requires = StringSet.of_list (Cmo_format.requires cmo) in
let requires = StringSet.diff requires provides in
let effects_without_cps =
Expand Down
2 changes: 1 addition & 1 deletion compiler/tests-linkall/test.reference
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fatal error: exception Failure("caml_register_global: cannot locate Dynlink_compilerlibs.Binutils")
hello world

0 comments on commit 53f4db0

Please sign in to comment.