diff --git a/CHANGES b/CHANGES index da6c1b6..4b6b13f 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/reloc.ml b/reloc.ml index 93a8d7f..bb7fd6c 100644 --- a/reloc.ml +++ b/reloc.ml @@ -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 @@ -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) (*******************************) @@ -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