Skip to content

Make -lgcc_eh on mingw-w64 optional #147

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

Merged
merged 1 commit into from
Apr 2, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Next version
- GPR#156: Allow choosing an alternative linker and manifest tool at runtime
with -use-linker=<cmd> and -use-mt=<cmd>.
(Antonin Décimo, review by David Allsopp)
- GPR#133, GPR#147: Allow default libraries to be marked as optional (David Allsopp, report by Romain Beauxis)

Version 0.43
- GPR#108: Add -lgcc_s to Cygwin's link libraries, upstreaming a patch from the
Expand Down
38 changes: 25 additions & 13 deletions reloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ let rec map_until_found f = function
| r ->
r

let find_file =
let find_file_exn =
let memo = Hashtbl.create 16 in
fun fn ->
let k = String.lowercase_ascii fn in
Expand All @@ -339,16 +339,18 @@ let find_file =
else
["lib" ^ base], standard_suffixes
else [fn], standard_suffixes in
let r =
match map_until_found (find_file suffixes) fns with
| Some fn -> fn
| None ->
failwith (Printf.sprintf "Cannot find file %S" fn)
in
Hashtbl.add memo k r;
Hashtbl.add memo (k ^ ".lib") r;
r

match map_until_found (find_file suffixes) fns with
| Some fn ->
Hashtbl.add memo k fn;
Hashtbl.add memo (k ^ ".lib") fn;
fn
| None ->
raise Not_found

let find_file fn =
try find_file_exn fn
with Not_found ->
failwith (Printf.sprintf "Cannot find file %S" fn)

(*******************************)

Expand Down Expand Up @@ -1385,8 +1387,18 @@ let setup_toolchain () =
flush stdout
end;
default_libs :=
["-lmingw32"; "-lgcc"; "-lgcc_eh"; "-lmoldname"; "-lmingwex"; "-lmsvcrt";
"-luser32"; "-lkernel32"; "-ladvapi32"; "-lshell32" ];
[ "-lmoldname"; "-lmingwex"; "-lmsvcrt"; "-luser32"; "-lkernel32";
"-ladvapi32"; "-lshell32" ];
(* -lgcc_eh isn't guaranteed to be available (e.g. if using a static
compiler - cf. ocaml/ocaml#12996. Parsing GCC's specs is a bit too much
work, so instead treat -lgcc_eh as optional *)
let () =
try
let _ = find_file_exn "-lgcc_eh" in
default_libs := "-lgcc_eh" :: !default_libs
with Not_found -> ()
in
default_libs := "-lmingw32" :: "-lgcc" :: !default_libs;
if !exe_mode = `EXE then default_libs := "crt2.o" :: !default_libs
else default_libs := "dllcrt2.o" :: !default_libs
in
Expand Down