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

Make -lgcc_eh on mingw-w64 optional #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Next version
- GPR#127: Recognise hyphens in option names in the COFF .drectve section. Fixes #126 (Reza Barazesh)
- GPR#136: Fix parallel access crashes and misbehavior (David Allsopp, Jan Midtgaard, Antonin Décimo)

- 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 @@ -314,7 +314,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 @@ -336,16 +336,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 @@ -1358,8 +1360,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