Skip to content

Commit

Permalink
Don't pass (unnecessary?) -L flags to gcc -shared from opttoplevel (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ccasin authored Jun 8, 2023
1 parent 863a33f commit f75965b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions backend/asmlink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ let make_shared_startup_file unix ~ppf_dump ~sourcefile_for_dwarf genfns units =
might drop some of them (in case of libraries) *)
Emit.end_assembly ()

let call_linker_shared file_list output_name =
let exitcode = Ccomp.call_linker Ccomp.Dll output_name file_list "" in
let call_linker_shared ?(native_toplevel = false) file_list output_name =
let exitcode =
Ccomp.call_linker ~native_toplevel Ccomp.Dll output_name file_list ""
in
if not (exitcode = 0)
then raise(Error(Linking_error exitcode))

Expand Down
2 changes: 1 addition & 1 deletion backend/asmlink.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ val link: (module Compiler_owee.Unix_intf.S) -> ppf_dump:formatter ->
val link_shared: (module Compiler_owee.Unix_intf.S) ->
ppf_dump:formatter -> string list -> string -> unit

val call_linker_shared: string list -> string -> unit
val call_linker_shared: ?native_toplevel:bool -> string list -> string -> unit

val reset : unit -> unit
val check_consistency: filepath -> Cmx_format.unit_infos -> Digest.t -> unit
Expand Down
2 changes: 1 addition & 1 deletion native_toplevel/opttoploop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ let default_load ppf (program : Lambda.program) =
~filename ~prefixname:filename
~pipeline ~ppf_dump:ppf
program;
Asmlink.call_linker_shared [filename ^ ext_obj] dll;
Asmlink.call_linker_shared ~native_toplevel:true [filename ^ ext_obj] dll;
Sys.remove (filename ^ ext_obj);
let dll =
if Filename.is_implicit dll
Expand Down
5 changes: 3 additions & 2 deletions ocaml/utils/ccomp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ let remove_Wl cclibs =
(String.sub cclib 4 (String.length cclib - 4))
else cclib)

let call_linker mode output_name files extra =
let call_linker ?(native_toplevel = false) mode output_name files extra =
Profile.record_call "c-linker" (fun () ->
let cmd =
if mode = Partial then
Expand All @@ -194,7 +194,8 @@ let call_linker mode output_name files extra =
)
(Filename.quote output_name)
"" (*(Clflags.std_include_flag "-I")*)
(quote_prefixed "-L" (Load_path.get_paths ()))
(if native_toplevel then ""
else quote_prefixed "-L" (Load_path.get_paths ()))
(String.concat " " (List.rev !Clflags.all_ccopts))
(quote_files files)
extra
Expand Down
9 changes: 8 additions & 1 deletion ocaml/utils/ccomp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ type link_mode =
| MainDll
| Partial

val call_linker: link_mode -> string -> string list -> string -> int
(* If the ~native_toplevel flag is true, we don't pass any `-L` flags to gcc.
In some cases we observed so many flags being passed that gcc would crash,
but they should all be unnecessary as we're compiling with `-shared` in that
case. *)
(* CR-someday ccasinghino: the argument above equally applies to all cases when
`link_mode` is `Dll`, but that didn't seem to work. Understand why. *)
val call_linker:
?native_toplevel:bool -> link_mode -> string -> string list -> string -> int

val linker_is_flexlink : bool

0 comments on commit f75965b

Please sign in to comment.