Install utop on mac m1 failed with assembly compilation error

hi masters, previously on my mac with m1 chip, I installed utop successfully, and I tried many times.
for some reasons, I maybe done brew update & upgrade, then utop can’t work any more.
When I type “utop”, it will be stuck with a “utop orgrange header”, can’t input any expressions.
So I tried to re-install utop again, but I can’t install it for below error, do you have any ideas? thank you so much

Constructing initial basis...
Number of 0-1 knapsack inequalities = 14977
Constructing conflict graph...
Conflict graph has 2534 + 605 = 3139 vertices
The following actions will be performed:
  - install utop    2.13.1
  - install lwt_log 1.1.2
===== 2 to install =====
Do you want to continue? [Y/n] y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Processing  2/6: [lwt_log.1.1.2: dl]
-> retrieved utop.2.13.1  (cached)
-> retrieved lwt_log.1.1.2  (https://opam.ocaml.org/cache)
[ERROR] The compilation of lwt_log.1.1.2 failed at "dune build -p lwt_log -j 7".
[ERROR] The compilation of utop.2.13.1 failed at "dune build -p utop -j 7 @install".

#=== ERROR while compiling utop.2.13.1 ========================================#
# context     2.1.5 | macos/x86_64 | ocaml.5.1.0 | https://opam.ocaml.org#2dcd8684
# path        ~/.opam/default/.opam-switch/build/utop.2.13.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p utop -j 7 @install
# exit-code   1
# env-file    ~/.opam/log/utop-80315-144998.env
# output-file ~/.opam/log/utop-80315-144998.out
### output ###
# /tmp/build_16c292_dune/camlasm438898.s:913:2: error: invalid instruction mnemonic 'bl'
# [...]
# /tmp/build_16c292_dune/camlasm438898.s:916:15: error: unknown token in expression
#  orr x0, xzr, #1
#               ^
# /tmp/build_16c292_dune/camlasm438898.s:917:11: error: brackets expression not supported on this target
#  ldr x30, [sp, #8]
#           ^
# /tmp/build_16c292_dune/camlasm438898.s:918:14: error: unknown token in expression
#  add sp, sp, #16
#              ^
# File "src/top/expunge/modules.ml", line 1:
# Error: Assembler error, input left in file /tmp/build_16c292_dune/camlasm438898.s


#=== ERROR while compiling lwt_log.1.1.2 ======================================#
# context     2.1.5 | macos/x86_64 | ocaml.5.1.0 | https://opam.ocaml.org#2dcd8684
# path        ~/.opam/default/.opam-switch/build/lwt_log.1.1.2
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p lwt_log -j 7
# exit-code   1
# env-file    ~/.opam/log/lwt_log-80315-4377b1.env
# output-file ~/.opam/log/lwt_log-80315-4377b1.out
### output ###
# /tmp/build_735af4_dune/camlasm81f813.s:849:2: error: unknown use of instruction mnemonic without a size suffix
# [...]
# /tmp/build_735af4_dune/camlasm81f813.s:851:15: error: unknown token in expression
#  orr x0, xzr, #1
#               ^
# /tmp/build_735af4_dune/camlasm81f813.s:852:11: error: brackets expression not supported on this target
#  ldr x30, [sp, #8]
#           ^
# /tmp/build_735af4_dune/camlasm81f813.s:853:14: error: unknown token in expression
#  add sp, sp, #16
#              ^
# File "src/core/lwt_log_rules.ml", line 1:
# Error: Assembler error, input left in file /tmp/build_735af4_dune/camlasm81f813.s



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - build lwt_log 1.1.2
| - build utop    2.13.1
+-
- No changes have been performed
# Run eval $(opam env) to update the current shell environment

If you are on an m1 you have a problem here, this should be macos/arm64.

I don’t exactly remember what you should do but try this discussion.

1 Like

I agree with @dbuenzli, it looks like this is executing the wrong toolchain under the hood (possibly through rosetta).

1 Like

thanks for your reply.

➜  ~ arch
arm64
➜  ~ opam config report
# opam config report
# opam-version         2.1.5
# self-upgrade         no
# system               arch=arm64 os=macos os-distribution=homebrew os-version=14.1
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 7
# repositories         1 (http) (default repo at 2dcd8684)
# pinned               0
# current-switch       default
# ocaml:native         true
# ocaml:native-tools   true
# ocaml:native-dynlink true
# ocaml:stubsdir       /Users/binhe/.opam/default/lib/ocaml/stublibs:/Users/binhe/.opam/default/lib/ocaml
# ocaml:preinstalled   false
# ocaml:compiler       5.0.0

seems I installed utop successfully. 
But when I use `utop`, it looks like this

➜  ~ utop
────────────────────────────────┬─────────────────────────────────────────────────────────────┬─────────────────────────────────
                                │ Welcome to utop version 2.10.0 (using OCaml version 5.0.0)! │
                                └─────────────────────────────────────────────────────────────┘
^CFatal error: exception Stdlib.Sys.Break

If I don't use ctrl+c to stop it, it will stay here forever, by right it should have a >____ for me to type ocaml expressions.

Possibly related to macOS: ocamlopt compiled for arm64 causes asm errors when running in a x86_64 environment · Issue #10374 · ocaml/ocaml · GitHub as well.