Homebrew-emacs-plus: Could not install with @28 --with-native-comp - libgccjit not supported on M1

Created on 9 Apr 2021  Â·  23Comments  Â·  Source: d12frosted/homebrew-emacs-plus

Please make sure to follow these steps (and mark the checkboxes):

  • [X] run brew update and try to reproduce the issue again
  • [X] run brew doctor, fix all issues and try to reproduce your issue again
  • [X] run brew config and brew doctor and include their output

What you were trying to do

brew install emacs-plus@28 --with-native-comp

What happened (include command output)

$ brew install emacs-plus@28 --with-native-comp


Command output

==> Installing emacs-plus@28 from d12frosted/emacs-plus
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.35.4.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/ecb945b9df98160dd9c935fc128e862fbc7d4593ff50

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

==> Downloading https://homebrew.bintray.com/bottles/python%403.9-3.9.4.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/9d38ac550179a6b6004a30eb063ce659ba5d14c2412d

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

==> Downloading https://homebrew.bintray.com/bottles/ghostscript-9.53.3_1.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/e1a01add6b5692ebfd462591db21dd029d081529fbe4

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

==> Downloading https://homebrew.bintray.com/bottles/libde265-1.0.8.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/856e3db9a951f15fc2e3c416ddf64c8336d405fc1e40

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

==> Downloading https://homebrew.bintray.com/bottles/docbook-5.1_1.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/53a9dc79db8b2d06dc75009d5d09fc797ddcd5eb4ca0

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

==> Downloading https://homebrew.bintray.com/bottles/docbook-xsl-1.79.2_1.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/9604b8989c3cc180c641b00f595e59d887aa85fbd410

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

==> Downloading https://homebrew.bintray.com/bottles/gnu-getopt-2.36.2.arm64_big_sur.bottle.tar.gz

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

==> Downloading https://homebrew.bintray.com/bottles/xmlto-0.0.28.arm64_big_sur.bottle.2.tar.gz

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

==> Downloading https://homebrew.bintray.com/bottles/shared-mime-info-2.1.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/c2c98a7a02e1b23f5c7f7baafe0e4b04f22a7b1a6df7

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

==> Downloading https://homebrew.bintray.com/bottles/libheif-1.11.0_2.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/6fb1565de0cf3f02dacaf0c1ca8631132900ecd2fb65

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

==> Downloading https://homebrew.bintray.com/bottles/liblqr-0.4.2_1.arm64_big_sur.bottle.1.tar.gz

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

==> Downloading https://homebrew.bintray.com/bottles/libomp-11.1.0.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/f87f7841eb8b72650fa771af39642361aec371ea1a1f

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

==> Downloading https://homebrew.bintray.com/bottles/ilmbase-2.5.5.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/f465c8e3f824777ab727d17e11c018eff8d8afc12ffe

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

==> Downloading https://homebrew.bintray.com/bottles/openexr-2.5.5.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/b484c97399b2317707c2685fceeb4e8ba26b9eea3d03

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

==> Downloading https://homebrew.bintray.com/bottles/imagemagick-7.0.11-6.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/87fd9f93911df4e835c4fa834156dfcb44e566f174cb

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

Error: libgccjit: no bottle available!
You can try to install from source with:
brew install --build-from-source libgccjit
Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.


Output of brew config

$ brew config
HOMEBREW_VERSION: 3.0.11
ORIGIN: https://github.com/Homebrew/brew
HEAD: 8e11f03fa93b148e26044a331654241a2c307039
Last commit: 4 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: efa89684e992ed605e9faa975677174c42be70a8
Core tap last commit: 16 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: :0
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 12.0 build 1200
Git: 2.24.3 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.2.3-arm64
CLT: 12.4.0.0.1.1610135815
Xcode: 12.4
Rosetta 2: false

Output of brew doctor

$ brew doctor
Your system is ready to brew.
install error brew

Most helpful comment

@hexagonal-sun this sounds great! thanks for fixing libgccjit for M1 💯

@DanMossa and @cacology it's time to some native compilation ;)

All 23 comments

That's strange, there is a bottle (formula) for Big Sur. Though maybe it's just not provided for arm. So maybe just use the suggestion provided by brew itself:

Error: libgccjit: no bottle available!

You can try to install from source with:

brew install --build-from-source libgccjit

Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.

Though I love this controversity in their message. Sigh. But it's really not related to emacs-plus.

BTW, are there Apple Silicon users who successfully got this working?

Re: Apple Silicon

Not me. brew install --build-from-source libgccjit fails with:

[... omitting dependencies that install just fine]
==> Installing libgccjit
==> ../configure --build=x86_64-apple-darwin20 --prefix=/opt/homebrew/Cellar/libgccjit/10.2.0_1 --libdir=/opt/homebrew/Cellar/libgccjit/
==> make BOOT_LDFLAGS=-Wl,-headerpad_max_install_names
Last 15 lines from /Users/grumpy/Library/Logs/Homebrew/libgccjit/02.make:
echo timestamp > stmp-int-hdrs
/private/tmp/libgccjit-20210411-85488-22vlnh/gcc-10.2.0/build-jit/./gcc/xgcc -B/private/tmp/libgccjit-20210411-85488-22vlnh/gcc-10.2.0/build-jit/./gcc/ -xc -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/testsuite/selftests
/private/tmp/libgccjit-20210411-85488-22vlnh/gcc-10.2.0/build-jit/./gcc/xgcc -B/private/tmp/libgccjit-20210411-85488-22vlnh/gcc-10.2.0/build-jit/./gcc/ -xc++ -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/testsuite/selftests
cc1: note: self-tests are not enabled in this build
echo timestamp > s-selftest-c
/dev/null:1: internal compiler error: in darwin_gt_pch_use_address, at config/host-darwin.c:51
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://github.com/Homebrew/homebrew-core/issues> for instructions.
make[3]: *** [s-selftest-c++] Error 1
rm gcc.pod
make[2]: *** [all-stage1-gcc] Error 2
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2

Do not report this issue to Homebrew/brew or Homebrew/core!

The absence of an arm bottle, noted above, https://formulae.brew.sh/formula/libgccjit suggests this hasn't come to the attention of someone who knows how to fix it.

brew install --build-from-source libgccjit --HEAD fares differently but no better.

==> ../configure --build=x86_64-apple-darwin20 --prefix=/opt/homebrew/Cellar/libgccjit/HEAD-ac20079_1 --libdir=/opt/homebrew/Cellar/libg
==> make BOOT_LDFLAGS=-Wl,-headerpad_max_install_names
Last 15 lines from /Users/grumpy/Library/Logs/Homebrew/libgccjit/02.make:
      __ZL13do_mpc_ckconvP10real_valueS0_PK12__mpc_structbPK11real_format in libbackend.a(fold-const-call.o)
      __ZL14do_mpfr_ckconvP10real_valuePK13__mpfr_structbPK11real_format in libbackend.a(fold-const-call.o)
  "_mpfr_y0", referenced from:
      __ZL17fold_const_call_111combined_fnP9tree_nodeS1_ in libbackend.a(fold-const-call.o)
  "_mpfr_y1", referenced from:
      __ZL17fold_const_call_111combined_fnP9tree_nodeS1_ in libbackend.a(fold-const-call.o)
  "_mpfr_yn", referenced from:
      __ZL17fold_const_call_111combined_fnP9tree_nodeS1_S1_ in libbackend.a(fold-const-call.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [cc1plus] Error 1
rm gcov.pod fsf-funding.pod lto-dump.pod gpl.pod cpp.pod gfdl.pod gcc.pod gcov-dump.pod gcov-tool.pod
make[2]: *** [all-stage2-gcc] Error 2
make[1]: *** [stage2-bubble] Error 2
make: *** [all] Error 2

Furthermore, brew install --build-from-source libgccjit -i and handholding:

  • ./configure --prefix=/opt/homebrew/Cellar/libgccjit/10.2.0_1 --libdir=/opt/homebrew/Cellar/libgccjit/
  • make BOOT_LDFLAGS=-Wl,-headerpad_max_install_names

Gives what I think is the real problem:

[... lots omitted]
*** Configuration arm-apple-darwin20.3.0 not supported
make[2]: *** [configure-stage1-gcc] Error 1
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2

Mutatis mutandis for handholding HEAD:

[... lots omitted]
*** Configuration aarch64-apple-darwin20.3.0 not supported
make[2]: *** [configure-stage1-gcc] Error 1
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2

EDIT:

A quick follow-up, the issue seems to be that GCC isn't ported yet:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96168 and https://github.com/iains/gcc-darwin-arm64

Thanks for the links @cacology 💯 It's sad that it's still not there.

P. S. pinned for visibility.

I've posted a PR that gets libgccjit to be built for M1 (https://github.com/Homebrew/homebrew-core/pull/77345). This allowed emacs-plus --with-native-comp to be built and lisp-code to be natively compiled.

However, when I used this to compile spacemacs after executing git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d, I'm now getting the error:

Warning (initialization): An error occurred while loading ‘/Users/matthew/.emacs.d/init.el’:

Native compiler error: (lambda (&optional arg6) (let ((f #'kill-emacs)) (funcall f arg6))), Compiling /Users/matthew/.emacs.d/eln-cache/28.0.50-38d341e0/subr--trampoline-6b696c6c2d656d616373_kill_emacs_0.eln...
ld: library not found for -lgcc_s.1.1
libgccjit.so: error: error invoking gcc driver
Debugger entered--Lisp error: (native-ice "failed to compile" "/Users/matthew/.emacs.d/eln-cache/28.0.50-38d341e0..." "error invoking gcc driver")
  comp--compile-ctxt-to-file("/Users/matthew/.emacs.d/eln-cache/28.0.50-38d341e0...")
  comp-compile-ctxt-to-file("/Users/matthew/.emacs.d/eln-cache/28.0.50-38d341e0...")
  comp-final1()
  load-with-code-conversion("/var/folders/np/hdxg_hbs4xq3spsvdl1mx5m80000gn/T/e..." "/var/folders/np/hdxg_hbs4xq3spsvdl1mx5m80000gn/T/e..." nil t)
  command-line-1(("-l" "/var/folders/np/hdxg_hbs4xq3spsvdl1mx5m80000gn/T/e..."))
  command-line()
  normal-top-level()

This is when executing /Applications/Emacs.app. If I invoke with emacs -nw on a terminal JIT for external packages works fine. I'm assuning that my enviroment isn't set correctly when launching from /Applications/Emacs.app

@hexagonal-sun That's the exact error I got when trying out the libgccjit smoketest here: https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html -- after unsucessfully hacking a m1 build as you were working on your PR (but before I knew about your PR :) https://github.com/Homebrew/homebrew-core/issues/77327#issuecomment-841633139

Would that smoketest perhaps help to debug this gcc_s.1.1 error better?

@hexagonal-sun I have now built and installed your PR https://github.com/Homebrew/homebrew-core/pull/77345 , with the livecheck fix suggested there, and after that emacs-plus with nativecomp.

I can get full GUI emacs with nativecomp by invoking /Applications/Emacs.app/Contents/MacOS/Emacs & from my shell (Emacs.app is symlinked there as per the formula's recommendation), but indeed when I invoke it via double-clicking on the application from Finder, I get the same error you showed above.

I have narrowed it down to /opt/homebrew/bin needing to be in the PATH environment variable.

This solution on SO https://apple.stackexchange.com/a/51737 suggests setting CFBundleExecutable in the plist to point to a script which modifies the env and then starts up the real app.

@cpbotha Thanks for the feedback. Sounds like the same issue that I'm having. I presume that it's something to do with the enviroment from which the Emacs process is started.

After some more testing, I've found another issue. I'm using spacemacs and after a fresh compilation of all the packages, invoking SPC f f causes a SIGABRT with the following printed on a terminal:

Fatal error 6: Aborted
fish: Job 1, 'emacs -nw' terminated by signal SIGABRT (Abort)

Backtrace:

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x0000000193b58e78 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x193b58e78 <+8>:  b.lo   0x193b58e98               ; <+40>
    0x193b58e7c <+12>: pacibsp
    0x193b58e80 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x193b58e84 <+20>: mov    x29, sp
Target 0: (Emacs) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x0000000193b58e78 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x0000000193b8ab98 libsystem_pthread.dylib`pthread_kill + 292
    frame #2: 0x0000000193a6ae14 libsystem_c.dylib`raise + 32
    frame #3: 0x00000001046381e8 Emacs`terminate_due_to_signal + 204
    frame #4: 0x00000001046388e4 Emacs`emacs_abort + 20
    frame #5: 0x0000000104618f9c Emacs`ns_term_shutdown + 132
    frame #6: 0x0000000104521020 Emacs`shut_down_emacs + 328
    frame #7: 0x00000001046381b0 Emacs`terminate_due_to_signal + 148
    frame #8: 0x00000001046388e4 Emacs`emacs_abort + 20
    frame #9: 0x0000000104549410 Emacs`Factive_minibuffer_window + 232
    frame #10: 0x000000014adbcf00 window-0d1b8b93-d2367f9f.eln`F6d696e696275666665722d77696e646f772d6163746976652d70_minibuffer_window_active_p_0 + 48
    frame #11: 0x0000000104590a00 Emacs`funcall_subr + 308
    frame #12: 0x00000001045904c8 Emacs`Ffuncall + 644
    frame #13: 0x00000001045c7768 Emacs`exec_byte_code + 1500
    frame #14: 0x0000000104590dc0 Emacs`funcall_lambda + 740
    frame #15: 0x0000000104590440 Emacs`Ffuncall + 508
    frame #16: 0x00000001045906ec Emacs`funcall_nil + 12
    frame #17: 0x00000001045906ac Emacs`run_hook_with_args + 296

@hexagonal-sun Over here on vanilla Emacs with my own home-grown config everything seems to be fine. I've tried different kinds of ways of opening files, and also orgmode, org-roam, mu4e, magit and everything runs great. Whenever I use a new mode for the first time, I can see the compiler doing its thing in *Async-native-compile-log*.

For now I've addressed the path problem by adding this to the start of my init.el:

(when (memq window-system '(mac ns))
  (setenv "PATH" (concat "/opt/homebrew/bin/:" (getenv "PATH"))))

(this only works because the basic stuff has already been native compiled during the first startup from the terminal, and that path gets added early enough for a normal gui startup to work perfectly.)

I see in your traceback the last call before emacs_abort was Factive_minibuffer_window -- I just invoked (active-minibuffer-window) without issues on my side.

@cpbotha Thanks for the info. I don't have the livecheck fix on my version of libgccjit. That could be the issue. I'll rebuild and give it another shot.

Hm. I'm now getting segmentation faults when building emacs. @cpbotha what was the command you used to build emacs? I'm using:

brew install emacs-plus@28 --with-spacemacs-icon --with-native-comp

segfaults while building emacs, goodness!

I did brew reinstall emacs-plus@28 --verbose --with-no-titlebar --with-native-comp

In my case, an explicit brew link libgccjit beforehand was necessary, else the emacs configure did not find gccjit.

... well this is surprising. I just redid the emacs build to see if I could reproduce, and now I too am getting a segfault.

Could it be that the extra one or two commits it just pulled in from emacs master caused this?

What's also super interesting, is that the most recent commit changed code involved in Factive_minibuffer_window where you were previously getting a segfault!

commit 46e4704e2abca4d264a43965f92eab7608211ee6 (HEAD -> master, origin/master, origin/HEAD)
Author: Alan Mackenzie <[email protected]>
Date:   Sat May 15 11:49:49 2021 +0000

    Miscellaneous corrections to src/minibuf.c for bug #48337

    * src/minibuf.c (read_minibuf): Call get_minibuffer before incrementing
    minibuf_level, in case a hook function calls Factive_minibuffer_window.
    (init_minibuf_once_for_pdumper): Create  *Minibuf-0* here (moved from
    init_minibuf_once), and set its mode, so that clicking in the mini-window
    immediately after start up works (thanks, Eli Z.).

@cpbotha Hmm, interesting. I'm going to try and pop a few commits off HEAD, build manually and get it working.

@hexagonal-sun I modified the emacs-plus formula to use the commit right before that one, and then it builds!

  1. clone the homebrew-emacs-plus repo
  2. edit [email protected] changing the url line to read as follows:
url "https://github.com/emacs-mirror/emacs.git", revision: "248ec838aa8b1a720a05b422be760f6ab32aa630"
  1. rebuild with:
brew install --verbose --formula /your/dir/homebrew-emacs-plus/Formula/[email protected] --with-no-titlebar --with-native-comp

I wonder if that last Emacs commit will break the nativecomp compilation on more systems than just homebrew on M1.

@cpbotha Confirmed. The above allows Emacs to be compiled again. I've still got the issue with SPC f f but at least it compiles!

I can also confirm that building at 43701a84367b76ccc93ad46f89110486988eec10 also fixed the SPC f f abort I was seeing (I think the follwoing commit broke it). I'll send a report upstream.

Eli fixed the nativecomp segfault a bit later yesterday!

commit b5e6dba05fcb4fa1c716dc759f8c4b2561bacaa7
Author: Eli Zaretskii <[email protected]>
Date:   Sat May 15 20:44:40 2021 +0300

    Fix segfaults when byte-compiling with native-compilation

    * src/emacs.c (main): Call 'set_initial_minibuffer_mode' before
    entering recursive-exit.
    * src/minibuf.c (init_minibuf_once_for_pdumper): Don't call
    'set_minibuffer_mode' here...
    (set_initial_minibuffer_mode): ... set it in this new function.
    (Bug#48446)
    * src/lisp.h: Add prototype for 'set_initial_minibuffer_mode'.

@hexagonal-sun and @cpbotha Thank you both for sharing your experience on building Emacs 28 with native comp on M1. From your comments I assume that thanks to https://github.com/Homebrew/homebrew-core/pull/77345 it is now possible without any extra ritual dancing? Am I right? :)

@d12frosted looks good on my end. I've been using a native-comp Emacs for a good few days now and have had no issues!

@hexagonal-sun this sounds great! thanks for fixing libgccjit for M1 💯

@DanMossa and @cacology it's time to some native compilation ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frankjonen picture frankjonen  Â·  3Comments

d12frosted picture d12frosted  Â·  6Comments

tshu-w picture tshu-w  Â·  6Comments

AbstProcDo picture AbstProcDo  Â·  3Comments

paulhenrich picture paulhenrich  Â·  8Comments