Skip to content

Commit 028b587

Browse files
avsmliyishuai
authored andcommitted
fix -mpopcnt compilation failure on macOS/aarch64 10.4
The problem arises from this bug in clang llvm/llvm-project#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 #164 and #168 Signed-off-by: Yishuai Li <[email protected]>
1 parent adb4623 commit 028b587

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/discover/discover.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ let () =
1414
main
1515
~name:"discover"
1616
~args:[ "-o", Set_string output, "FILENAME output file" ]
17-
(fun c ->
18-
let has_popcnt = c_test c ~c_flags:[ "-mpopcnt" ] program in
17+
(fun _c ->
18+
let f,oc = Filename.open_temp_file "baseconf" ".c" in
19+
let has_popcnt =
20+
Fun.protect ~finally:(fun () -> close_out oc; Sys.remove f)
21+
(fun () -> output_string oc program; flush oc;
22+
Sys.command (Printf.sprintf "cc %s -mpopcnt -o /dev/null >/dev/null 2>&1" f) = 0) in
1923
Flags.write_sexp !output (if has_popcnt then [ "-mpopcnt" ] else []))
2024
;;

0 commit comments

Comments
 (0)