18

I want to compile the gccemacs branch of Emacs. When I run ./configure, the configure script errors with:

cd emacs
git checkout feature/native-comp
./autogen.sh 
./configure --with-nativecomp 

configure: error: Installed libgccjit has failed passing the smoke test.
You can verify it yourself compiling:
<https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html>.
Please report the issue to your distribution.
Here instructions on how to compile and install libgccjit from source:
<https://gcc.gnu.org/wiki/JIT>.

Here's some version info:

$ cd emacs/ 
$ git log -1
  commit 2593bbee51f4d15d3a4fc1d4e2e3b215222f783a (HEAD -> feature/native-comp, origin/feature/native-comp)
  Author: Andrea Corallo <akrl@sdf.org>
  Date:   Sat Jul 4 15:53:15 2020 +0100
  
      * Relax constant folding rules
      
      * lisp/emacs-lisp/comp.el (comp-function-optimizable-p): No need to
      check for operands or result to be fixnums.

$ uname -r
5.4.0-7634-generic

$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0

I can verify that gccjit fails by compiling https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html. It segfaults. Here's a gdb trace:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7566d63 in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
(gdb) where
#0  0x00007ffff7566d63 in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
#1  0x00007ffff7566e85 in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
#2  0x00007ffff678b2a1 in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
#3  0x00007ffff678d8d1 in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
#4  0x00007ffff678e9dd in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
#5  0x00007ffff678ea68 in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
#6  0x00007ffff678d32b in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
#7  0x00007ffff6784851 in ?? () from /lib/x86_64-linux-gnu/libgccjit.so.0
#8  0x00007ffff67775b6 in gcc_jit_context_compile () from /lib/x86_64-linux-gnu/libgccjit.so.0
#9  0x00005555555555a5 in main (argc=1, argv=0x7fffffffda38) at hello.c:99
(gdb) list
62  
63    gcc_jit_block *block = gcc_jit_function_new_block (func, NULL);
64  
65    gcc_jit_block_add_eval (
66      block, NULL,
67      gcc_jit_context_new_call (ctxt,
68                                NULL,
69                                printf_func,
70                                2, args));
71    gcc_jit_block_end_with_void_return (block, NULL);

My suspicion is that I need a more recent version of GCC, since the Dockerfile for gccemacs installs gcc from source in the demo Dockerfile: https://gitlab.com/koral/emacs-nativecomp-dockerfile/-/blob/master/Dockerfile

3
  • Did you ever resolve this? I'm having the same problem.
    – gct
    Jul 19, 2020 at 1:32
  • This may help: "Build gccemacs on MacOS catalina with gcc 10 installed by homebrew" gist.github.com/AllenDang/f019593e65572a8e0aefc96058a2d23e Jan 4, 2021 at 7:48
  • 1
    For any future readers, the original feature/native-comp branch was merged, and therefore is deprecated (and deleted upstream). If using git, checkout either emacs-28 (or a release branch for any later version), or else use the unstable master branch (if you want to be on the bleeding edge). Not using git, you can build from the tarball for any release (or pretest or release candidate) for Emacs 28 or later.
    – phils
    Mar 21 at 1:27

5 Answers 5

27

I could get it to work with Ubuntu 18.04 and 20.04. This is the recipe I used.

sudo apt install libxpm-dev libgif-dev libjpeg-dev libpng-dev libtiff-dev libx11-dev libncurses5-dev automake autoconf texinfo libgtk2.0-dev
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
sudo apt install gcc-10 g++-10 libgccjit0 libgccjit-10-dev libjansson4 libjansson-dev
git clone git://git.savannah.gnu.org/emacs.git && cd emacs
git checkout emacs-28
export CC=/usr/bin/gcc-10 CXX=/usr/bin/gcc-10
./autogen.sh 
./configure --with-nativecomp --with-json CFLAGS="-O3 -mtune=native -march=native -fomit-frame-pointer"
make -j$(nproc)

UPDATE: 11/03/21: I have updated the flags passed to configure. Other things are the same.

sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
sudo apt install gcc-10 g++-10 libgccjit0 libgccjit-10-dev libjansson4 libjansson-dev
git clone git://git.savannah.gnu.org/emacs.git && cd emacs
git checkout emacs-28
export CC=/usr/bin/gcc-10 CXX=/usr/bin/gcc-10
./autogen.sh
./configure --with-cairo --with-modules --without-compress-install --with-x-toolkit=no --with-gnutls --without-gconf --without-xwidgets --without-toolkit-scroll-bars --without-xaw3d --without-gsettings --with-mailutils --with-native-compilation --with-json --with-harfbuzz --with-imagemagick --with-jpeg --with-png --with-rsvg --with-tiff --with-wide-int --with-xft --with-xml2 --with-xpm CFLAGS="-O3 -mtune=native -march=native -fomit-frame-pointer" prefix=/usr/local
make -j$(nproc)
5
  • 5
    The key part of this answer is sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa; the default repositories contain a broken version of libgccjit that causes the smoke test to fail.
    – Clément
    Sep 28, 2020 at 16:48
  • 3
    Flag NATIVE_FULL_AOT=1 is to build for all available distributions. In 99% of scenarios this is redundant.
    – Navidot
    Dec 16, 2020 at 19:29
  • NATIVE_FULL_AOT is to build for _all the Emacs distribution _ ... it's not plural. emacswiki.org/emacs/GccEmacs#h5o-13 (I read this comment as distrubitons like macos, windows, linux)...
    – joefromct
    May 27, 2021 at 2:59
  • 2
    For everyone reading this now: native-comp was merged, so you can skip feature/native-comp and instead just build off master (or emacs-28 whenever that shows up.) Aug 3, 2021 at 13:20
  • also note that the flag for ./configure is --with-native-compilation Apr 29 at 22:13
6

Ubuntu 20.04 WSL works just fine now with default ppas.

# emacs-native
git clone git://git.savannah.gnu.org/emacs.git && cd emacs
git checkout emacs-28        
export CC=/usr/bin/gcc-10 CXX=/usr/bin/gcc-10
./autogen.sh
cd ..
mkdir emacs-build
cd emacs-build
sudo apt install libxpm-dev libgif-dev libjpeg-dev libtiff-dev libgnutls28-dev
../emacs/configure --prefix=/usr --with-native-compilation --with-json CFLAGS="-O3 -mtune=native -march=native -fomit-frame-pointer" --without-makeinfo
make -j24
sudo checkinstall
0
4

In my case, I'm in debian stable with the version 8.3.0 and had no trouble installing it, maybe you can try to downgrade gcc and install libgccjit-8-dev.

Good luck!

1

As of 2022 using Ubuntu 20.04 with its standard gcc 9.4.0 allows compiling Emacs with native compilation support, as long as the appropriate libgccjit is installed:

sudo apt install libgccjit0 libgccjit-9-dev
0

On Fedora 32 (almost latest update as of 5 Sept 2020), I got the same error. But strangely, libgccjit was not installed. I installed it and the corresponding -devel package - and the compilation worked nicely.

If anyone gets here searching for this error - check if you have libgccjit installed at all.

dnf install libgccjit-devel.x86_64 libgccjit.x86_64

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.