Segmentation fault after update elixir and erlang

Hi,

MacBook Pro (13-inch, M1, 2020)
MacOS Big Sur 11.3.1
Homebrew (all updated to the latest version)

After updating to erlang (24.0 OTP) and elixir (1.12)

colibri@colibri-core ~ % erl
zsh: segmentation fault  erl
colibri@colibri-core ~ % iex
zsh: segmentation fault  iex
colibri@colibri-core ~ % mix local.rebar
zsh: segmentation fault  mix local.rebar
colibri@colibri-core ~ % mix local.hex                  
zsh: segmentation fault  mix local.hex
colibri@colibri-core ~ % mix archive.install hex phx_new
zsh: segmentation fault  mix archive.install hex phx_new

after a while

colibri@colibri-core ~ % iex
Erlang/OTP 24 [erts-12.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.12.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
a
colibri@colibri-core ~ % iex
zsh: segmentation fault  iex

How did you install Erlang / Elixir?

1 Like

I see [jit], could it be related that support of M1 is only in development? https://twitter.com/josevalim/status/1395702461776728064

1 Like

brew install erlang (elixir) - еverything was working fine before
updated yesterday - brew update && brew upgrade - and this problem appeared

P.S I always have fresh erlang/elixir updates on M1, previous versions worked fine, earlier there was a problem with :observer.start(), I fixed it.

Yes, the problem is only on the M1
iMac 3,5 GHz Intel Core i5, works great after the upgrade erlang/elixir

1 Like

…You can either completely disable BeamAsm by passing --disable-jit to configure. …
Erlang -- BeamAsm, the Erlang JIT

So, just turn it off

1 Like

Thanks!
Yes, I did it yesterday, but this is a temporary solution, the problem of building with --enable-jit option remains the same.

We have updated Erlang(24.0.1 OTP) and Elixir (1.12.0) installed via Homebrew.
When running interactive mode (erl or iex) we got a segmentation fault error.
For correctly work Erlang/Elixir, we need to disable jit option in Erlang and update wxmac from version 3.0.5.1 to version 3.1.4 to make :observer.start() work properly
So, let’s do it…

STEPS:

  1. Edit Formula brew edit erlang
  2. Add --disable-jit option to def install → args list
  3. Save Formula
  4. Edit Formula brew edit wxmac
  5. Replace the lines url and sha256 with these
    url "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.4/wxWidgets-3.1.4.tar.bz2"
    sha256 "3ca3a19a14b407d0cdda507a7930c2e84ae1c8e74f946e0144d2fa7d881f1a94"
  6. Comment bottle section
  # bottle do
  #   sha256 cellar: :any, arm64_big_sur: "f8d6ccae11c8d99b893e2605ca272a376a374faac8864304d1cdf544c6152421"
  #   sha256 cellar: :any, big_sur:       "95b66fefa42f869430da0597abb27500d551d5f99662e285c4f0d3a9e2800bdf"
  #   sha256 cellar: :any, catalina:      "110aa0b2134d8bff1647de0cd8500f160133794b347f789bba3e1894b991b788"
  #   sha256 cellar: :any, mojave:        "5f703423fc3f1e36d647a2d8be2d271a92f5d60f49ceba8e3478391bbd4f5303"
  #   sha256 cellar: :any, high_sierra:   "1de8aa03e1c50af387888ffa51cfa4e0c99d158f25edb0acbf312e10c629a31d"
  # end
  1. Add "--enable-compat28", option to def install → args list
  2. Save Formula
  3. brew upgrade wxmac

DONE

colibri@colibri-core ~ % iex
Erlang/OTP 24 [erts-12.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [dtrace]

Interactive Elixir (1.12.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 
1 Like

I can’t reproduce your problem.

It should not be possible to have the JIT enabled in OTP 24 on an M1 Mac, because the configure script will complain if you try to enable the JIT:

./configure --enable-jit
.
.
.
configure: error: JIT only works on x86 64-bit
ERROR: /Users/bjorng/git/otp/erts/configure failed!

If you run ./configure without any other options, the JIT will be automatically disabled unless the platform is x86_64.

I can only assume that something very weird happened when homebrew upgraded the version of Erlang to OTP 24. I can’t reproduce the problem myself, because I have never used homebrew before and can’t do the same update and upgrade that you did. When I downloaded homebrew for the first time and installed Erlang on my M1 Mac, it worked immediately without any problems.

I would recommend that you remove the --disable-jit line from the homebrew formula and force homebrew to rebuild Erlang from scratch. That should work. If not, I would be very interested in build logs to see what parameters homebrew passed to configure and which environment variables that were set. If it happens to be a bug in the configure script for the OTP that would incorrectly enable the JIT on a M1 under some circumstances, I would want to fix it.

5 Likes
colibri@colibri-core ~ % brew install -s erlang                    
==> Downloading https://ghcr.io/v2/homebrew/core/wxmac/manifests/3.0.5.1_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/wxmac/blobs/sha256:95b66fefa42f869430da0597abb27500d551d5f99662e285c4f0d3a9e2800bdf
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:95b66fefa42f869430da0597abb27500d551d5f99662e285c4f0d3a9e2800bdf?se=2021-05-23T08%3A15%3A00Z&s
######################################################################## 100.0%
==> Downloading https://www.erlang.org/download/otp_doc_html_24.0.tar.gz
==> Downloading from http://erlang.org/download/otp_doc_html_24.0.tar.gz
######################################################################## 100.0%
==> Downloading https://github.com/erlang/otp/releases/download/OTP-24.0.1/otp_src_24.0.1.tar.gz
==> Downloading from https://github-releases.githubusercontent.com/374927/851c2280-b983-11eb-8807-475fd4248fef?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH5
######################################################################## 100.0%
==> Installing dependencies for erlang: wxmac
==> Installing erlang dependency: wxmac
==> Pouring wxmac--3.0.5.1_1.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/wxmac/3.0.5.1_1: 810 files, 52.2MB
==> Installing erlang
==> ./configure --prefix=/usr/local/Cellar/erlang/24.0.1 --enable-dynamic-ssl-lib --enable-hipe --enable-shared-zlib --enable-smp-support --enable-threads --enable-wx --with-ssl=/
==> make
Last 15 lines from /Users/colibri/Library/Logs/Homebrew/erlang/02.make:
           < megaco_flex_scanner_drv.flex.src > megaco_flex_scanner_drv_mt.flex
flex -Ca -Pmegaco_flex_scanner_drv -omegaco_flex_scanner_drv.c megaco_flex_scanner_drv.flex
flex -R -Ca --yylineno -Pmegaco_flex_scanner_drv_mt -omegaco_flex_scanner_drv_mt.c megaco_flex_scanner_drv_mt.flex
compiling std driver:
clang -c -DMEGACO_DRV_NAME=\"megaco_flex_scanner_drv\" -fno-common -Werror=return-type -g -O2 -fPIC -fno-common -DOTP_RELEASE -DMFS_FLEX_DEBUG=0 -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/emulator/beam -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/include -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/include/x86_64-apple-darwin20.4.0 -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/include/internal -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/include/internal/x86_64-apple-darwin20.4.0 -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/emulator/sys/unix -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/emulator/sys/common -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/x86_64-apple-darwin20.4.0  -funroll-loops -Wall -DMEGACO_LINENO -o ../../priv/obj/x86_64-apple-darwin20.4.0/megaco_flex_scanner_drv.o megaco_flex_scanner_drv.c
compiling multi-threaded driver:
clang -c -DMEGACO_DRV_NAME=\"megaco_flex_scanner_drv_mt\" -fno-common -Werror=return-type -g -O2 -fPIC -fno-common -DOTP_RELEASE -DMFS_FLEX_DEBUG=0 -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/emulator/beam -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/include -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/include/x86_64-apple-darwin20.4.0 -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/include/internal -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/include/internal/x86_64-apple-darwin20.4.0 -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/emulator/sys/unix -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/emulator/sys/common -I/private/tmp/erlang-20210523-57611-1ctzn8v/otp_src_24.0.1/erts/x86_64-apple-darwin20.4.0  -funroll-loops -Wall -DMEGACO_LINENO  -D_THREAD_SAFE -D_REENTRANT -DPOSIX_THREADS -DMEGACO_REENTRANT_FLEX_SCANNER -o ../../priv/obj/x86_64-apple-darwin20.4.0/megaco_flex_scanner_drv_mt.o megaco_flex_scanner_drv_mt.c
make[5]: *** [../../ebin/megaco_flex_scanner.beam] Segmentation fault: 11
make[5]: *** Waiting for unfinished jobs....
make[5]: *** [../../ebin/megaco_flex_scanner_handler.beam] Segmentation fault: 11
make[4]: *** [opt] Error 2
make[3]: *** [opt] Error 2
make[2]: *** [opt] Error 2
make[1]: *** [opt] Error 2
make: *** [libs] Error 2

READ THIS: https://docs.brew.sh/Troubleshooting

These open issues may also help:
erlang@21 21.3.8.23 https://github.com/Homebrew/homebrew-core/pull/77725
colibri@colibri-core ~ %

Where do I send the installation log(01.configure and if needed 02.make)?

2021-05-23 11:17:48 +0300

./configure
--disable-debug
--disable-silent-rules
--prefix=/usr/local/Cellar/erlang/24.0.1
--enable-dynamic-ssl-lib
--enable-hipe
--enable-shared-zlib
--enable-smp-support
--enable-threads
--enable-wx
--with-ssl=/usr/local/opt/openssl@1.1
--without-javac
--enable-darwin-64bit
--enable-kernel-poll
--with-dynamic-trace=dtrace

=== Running configure in /private/tmp/erlang-20210523-78454-1pyowcr/otp_src_24.0.1/erts ===
./configure '--disable-debug' '--disable-silent-rules' '--prefix=/usr/local/Cellar/erlang/24.0.1' '--enable-dynamic-ssl-lib' '--enable-hipe' '--enable-shared-zlib' '--enable-smp-support' '--enable-threads' '--enable-wx' '--with-ssl=/usr/local/opt/openssl@1.1' '--without-javac' '--enable-darwin-64bit' '--enable-kernel-poll' '--with-dynamic-trace=dtrace' --disable-option-checking --cache-file=/dev/null --srcdir="/private/tmp/erlang-20210523-78454-1pyowcr/otp_src_24.0.1/erts"
checking build system type... x86_64-apple-darwin20.4.0
checking host system type... x86_64-apple-darwin20.4.0
checking for gcc... clang
2021-05-23 12:12:47 +0300

make

Makefile:1235: warning: overriding commands for target `dialyzer'
Makefile:510: warning: ignoring old commands for target `dialyzer'
test X"$ERTS_SKIP_DEPEND" = X"true" || (cd erts/emulator && PATH=/private/tmp/erlang-20210523-30020-1ujj30m/otp_src_24.0.1/bootstrap/bin:"${PATH}" ERL_TOP=/private/tmp/erlang-20210523-30020-1ujj30m/otp_src_24.0.1 make generate)
/Library/Developer/CommandLineTools/usr/bin/make -f x86_64-apple-darwin20.4.0/Makefile generate
if utils/gen_git_version x86_64-apple-darwin20.4.0/gen_git_version.mk; then touch beam/erl_bif_info.c; fi
dtrace -h -C -Ibeam -s beam/erlang_dtrace.d -o ./erlang_dtrace.tmp
LANG=C /usr/bin/perl utils/beam_makeops \
		-wordsize 64 \
		-code-model @CODE_MODEL@ \
		-outdir x86_64-apple-darwin20.4.0/opt/jit \
		-jit yes \
		-DUSE_VM_PROBES=1 \
		-emulator /private/tmp/erlang-20210523-30020-1ujj30m/otp_src_24.0.1/lib/compiler/src/genop.tab beam/predicates.tab beam/generators.tab beam/jit/x86/ops.tab beam/jit/x86/predicates.tab beam/jit/x86/generators.tab && echo /private/tmp/erlang-20210523-30020-1ujj30m/otp_src_24.0.1/lib/compiler/src/genop.tab beam/predicates.tab beam/generators.tab beam/jit/x86/ops.tab beam/jit/x86/predicates.tab beam/jit/x86/generators.tab utils/beam_makeops x86_64-apple-darwin20.4.0/Makefile >x86_64-apple-darwin20.4.0/opt/jit/OPCODES-GENERATED
LANG=C /usr/bin/perl utils/make_tables -src x86_64-apple-darwin20.4.0/opt/jit -include x86_64-apple-darwin20.4.0/opt/jit\
		-dst no -jit yes\
1 Like

No need to send any more files. I see the problem:

The build system type is determined as x86_64-apple-darwin20.4.0, not as aarch64-apple-darwin20.4.0 as it should be on an M1 Mac. That will cause configure to enable the JIT.

So it seems that on your M1 Mac homebrew is running under Rosetta emulation (emulating an Intel Mac), at least when the configure script is run. I don’t know why that is happening. Did the first versions of homebrew for M1 Macs run under emulation and you are still using that version? With my recently installed homebrew, the configure script correctly determines the build type to be aarch64-apple-darwin20.4.0.

8 Likes

I got this laptop in December 2020.
Installed Homebrew right away, it was only rosette-enabled at the time.

Thank you very much for pointing out this problem and for pointing out a solution.

STEPS:

  1. Delete Homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
  2. Disabled the rosette support for the terminal.
  3. Cleaned the system from the debris left behind.
  4. Install Homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

DONE

P.S It’s hard to be among the pioneers :slight_smile:

15 Likes

This did not work for me. Still getting segmentation faults. Pretty stuck. I’ve tried this and I’ve also tried installing erlang via this asdf thread. Not sure what else to try. Just starting out so I don’t have the skills to dig much deeper. Help would be much appreciated.

1 Like

I could try to help you through teamviewer program if you want?

2 Likes

yikes finally got it to work
used arm homebrew , only diabled --jit and install erl and then elixir finally able to run elixir on m1

so we dont need to disable JIT and stuff?

just this fixes it ?

:frowning: i did both but zsh: segmentation fault erl :frowning:

Have you tried this?

This is the only correct solution to this problem…

it was working fine but after installing postgres it broke again :’ (

==> Upgrading 1 dependent:

erlang 24.1.2 → 24.1.3

==> Downloading https://ghcr.io/v2/homebrew/core/erlang/manifests/24.1.3

######################################################################## 100.0%

==> Downloading https://ghcr.io/v2/homebrew/core/erlang/blobs/sha256:03ed4af1c1b

==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh

######################################################################## 100.0%

==> Upgrading erlang

24.1.2 → 24.1.3

==> Pouring erlang–24.1.3.big_sur.bottle.tar.gz

==> Caveats

Man pages can be found in:

/usr/local/opt/erlang/lib/erlang/man

Access them with erl -man, or add this directory to MANPATH.

==> Summary

:beer: /usr/local/Cellar/erlang/24.1.3: 7,145 files, 483.5MB

Removing: /usr/local/Cellar/erlang/24.1.2… (7,145 files, 483.1MB)

this happened and broke it :crying_cat_face:

Simple but this solution is enough. No need to disable JIT, change openssl versions or anything. Simply install brew using Terminal(with Rosetta disabled), install brew, install Erlang and Elixir using brew.This worked for me. Thanks a lot colibri!

2 Likes

I’ve tried all these solutions (I think), but still getting seg faults when installing erlang 24.3.4 on Apple M1, on ZSH with iTerm. I’ve installed homebrew from scratch, installed asdf again, set the KERL_CONFIGURE_OPTIONS="--disable-hipe --with-ssl=$(brew --prefix openssl@1.1) --without-wx --without-debugger --without-observer --without-cdv --without-et --with-odbc=$(brew --prefix unixodbc) --enable-darwin-64bit --without-javac", but I keep getting the following errors:

/bin/sh: line 1: 62351 Segmentation fault: 11  erlc -W -Werror +debug_info -DUSE_ESOCK=true -DENABLE_MEGACO_FLEX_SCANNER=true -DMEGACO_REENTRANT_FLEX_SCANNER=true -Dmegaco_parser_inline -pa /Users/zamith/.asdf/plugins/erlang/kerl-home/builds/asdf_24.3.4/otp_src_24.3.4/lib/et/ebin -pa /Users/zamith/.asdf/plugins/erlang/kerl-home/builds/asdf_24.3.4/otp_src_24.3.4/lib/megaco/ebin +'{parse_transform,sys_pre_attributes}' +'{attribute,insert,app_vsn,"megaco-4.3"}' -I../../include -o../../ebin megaco_flex_scanner.erl
make[5]: *** [../../ebin/megaco_flex_scanner.beam] Error 139
make[5]: *** Waiting for unfinished jobs....
/bin/sh: line 1: 62352 Segmentation fault: 11  erlc -W -Werror +debug_info -DUSE_ESOCK=true -DENABLE_MEGACO_FLEX_SCANNER=true -DMEGACO_REENTRANT_FLEX_SCANNER=true -Dmegaco_parser_inline -pa /Users/zamith/.asdf/plugins/erlang/kerl-home/builds/asdf_24.3.4/otp_src_24.3.4/lib/et/ebin -pa /Users/zamith/.asdf/plugins/erlang/kerl-home/builds/asdf_24.3.4/otp_src_24.3.4/lib/megaco/ebin +'{parse_transform,sys_pre_attributes}' +'{attribute,insert,app_vsn,"megaco-4.3"}' -I../../include -o../../ebin megaco_flex_scanner_handler.erl
make[5]: *** [../../ebin/megaco_flex_scanner_handler.beam] Error 139
make[4]: *** [opt] Error 2
make[3]: *** [opt] Error 2
make[2]: *** [opt] Error 2
make[1]: *** [opt] Error 2
make: *** [libs] Error 2

I’ve tried different KERL configs, but been bumping into different errors