From 54be833d33cec5072c2eb0e2f2ba390080283bee Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sun, 6 Apr 2025 11:58:00 +0100 Subject: [PATCH] fix -mpopcnt compilation failure on macOS/aarch64 10.4 The problem arises from this bug in clang https://github.com/llvm/llvm-project/issues/116278 which causes the following: ``` $ cc t.c -mpopcnt clang: error: unsupported option '-mpopcnt' for target 'arm64-apple-darwin24.4.0' $ cc t.c -mpopcnt -lpthread ``` The src/discover uses dune configurator, which always appends the C link flags from ocamlopt to the command line, and so the configurator erronously thinks that -mpopcnt will work. Since the dune configurator can't easily be overridden, this PR works around this specific link order issue by hand-calling the cc compiler from the discover binary. fixes janestreet/base#164 and janestreet/base#168 Signed-off-by: Yishuai Li --- src/discover/discover.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/discover/discover.ml b/src/discover/discover.ml index f2e0b92..913d964 100644 --- a/src/discover/discover.ml +++ b/src/discover/discover.ml @@ -14,7 +14,11 @@ let () = main ~name:"discover" ~args:[ "-o", Set_string output, "FILENAME output file" ] - (fun c -> - let has_popcnt = c_test c ~c_flags:[ "-mpopcnt" ] program in + (fun _c -> + let f,oc = Filename.open_temp_file "baseconf" ".c" in + let has_popcnt = + Fun.protect ~finally:(fun () -> close_out oc; Sys.remove f) + (fun () -> output_string oc program; flush oc; + Sys.command (Printf.sprintf "cc %s -mpopcnt -o /dev/null >/dev/null 2>&1" f) = 0) in Flags.write_sexp !output (if has_popcnt then [ "-mpopcnt" ] else [])) ;;