diff --git a/testsuite/tools/test_in_prefix.ml b/testsuite/tools/test_in_prefix.ml index ead7bb22d8a8..78f71b1c0c97 100644 --- a/testsuite/tools/test_in_prefix.ml +++ b/testsuite/tools/test_in_prefix.ml @@ -857,14 +857,11 @@ let compile_test ~original env bindir = | Output_complete_obj(C_ocamlc, Shared) -> true, false, ["-output-complete-obj"], true, None | Output_complete_obj(C_ocamlopt, Static) -> - (* At the moment, the partial linker will pass -lzstd to ld -r which - will (normally) fail). Until this is done, pass the libraries - manually. *) - false, true, ["-output-complete-obj"; "-noautolink"], true, - Some ocamlcommon_native_c_libraries + false, true, ["-output-complete-obj"], true, + Some Config.comprmarsh_c_libraries | Output_complete_obj(C_ocamlopt, Shared) -> - true, true, ["-output-complete-obj"; "-noautolink"], true, - Some ocamlcommon_native_c_libraries + true, true, ["-output-complete-obj"], true, + Some Config.comprmarsh_c_libraries | Output_complete_exe Static -> false, false, ["-output-complete-exe"], false, None | Output_complete_exe Shared -> diff --git a/utils/ccomp.ml b/utils/ccomp.ml index defe4d2a4b92..96dd7ade1c1a 100644 --- a/utils/ccomp.ml +++ b/utils/ccomp.ml @@ -147,16 +147,15 @@ let create_archive archive file_list = (quote_files ~response_files:Config.ar_supports_response_files file_list)) -let expand_libname cclibs = - cclibs |> List.map (fun cclib -> - if String.starts_with ~prefix:"-l" cclib then - let libname = - "lib" ^ String.sub cclib 2 (String.length cclib - 2) ^ Config.ext_lib in - try - Load_path.find libname - with Not_found -> - libname - else cclib) +let expand_libname cclib = + if String.starts_with ~prefix:"-l" cclib then + let libname = + "lib" ^ String.sub cclib 2 (String.length cclib - 2) ^ Config.ext_lib in + try + Some (Load_path.find libname) + with Not_found -> + None + else Some cclib type link_mode = | Exe @@ -176,11 +175,16 @@ let call_linker mode output_name files extra = Profile.record_call "c-linker" (fun () -> let cmd = if mode = Partial then - let (l_prefix, files) = + let l_prefix = match Config.ccomp_type with - | "msvc" -> ("/libpath:", expand_libname files) - | _ -> ("-L", files) + | "msvc" -> "/libpath:" + | _ -> "-L" in + (* For partial linking, only include -llib if -llib can be found in the + current search path. For ld -r, this PATH is (usually) limited to the + -L directories. This should cause OCaml libraries to be linked, but + not any system libraries mentioned in .cma/.cmxa files. *) + let files = List.filter_map expand_libname files in Printf.sprintf "%s%s %s %s %s" Config.native_pack_linker (Filename.quote output_name)