Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 801580 - sys-devel/gcc-11.1.0-r2[jit]: gccjit runtime failure with ccache (was: app-editors/emacs-28.0.9999[jit] fails with FEATURES=ccache)
Summary: sys-devel/gcc-11.1.0-r2[jit]: gccjit runtime failure with ccache (was: app-ed...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All All
: Normal normal with 1 vote (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-11 13:12 UTC by Thomas Schneider
Modified: 2022-12-11 15:35 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
config.log (config.log,234.75 KB, text/x-log)
2021-07-11 13:12 UTC, Thomas Schneider
Details
a.c (a.c,4.88 KB, text/x-csrc)
2021-07-11 16:50 UTC, Sergei Trofimovich (RETIRED)
Details
tut01-hello-world.c (tut01-hello-world.c,3.39 KB, text/plain)
2021-07-12 09:59 UTC, Ulrich Müller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schneider 2021-07-11 13:12:31 UTC
Created attachment 723280 [details]
config.log

Emacs as of v28 (not yet released, so this is with 28.0.9999) supports using libgccjit (sys-devel/gcc[jit]) to compile lisp code not only to byte code, but also to native code.

This fails with a somewhat confusing error message when using ccache:

```
checking for gcc_jit_context_acquire in -lgccjit... yes
checking libgccjit.h usability... yes
checking libgccjit.h presence... yes
checking for libgccjit.h... yes
configure: error: The installed libgccjit failed to compile and run a test program using
the libgccjit library; see config.log for the details of the failure.
The test program can be found here:
<https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html>.
You can try compiling it yourself to investigate the issues.
Please report the issue to your distribution if libgccjit was installed
through that.
You can find the instructions on how to compile and install libgccjit from
source on this site:
<https://gcc.gnu.org/wiki/JIT>.

!!! Please attach the following file when seeking support:
!!! /tmp/portage/app-editors/emacs-28.0.9999/work/emacs/config.log
 * ERROR: app-editors/emacs-28.0.9999::gentoo failed (configure phase):
 *   econf failed
```

relevant portion of config.log (see attachment for full file):
```
configure:17126: checking libgccjit.h presence
configure:17126: x86_64-pc-linux-gnu-gcc -E    conftest.c
configure:17126: $? = 0
configure:17126: result: yes
configure:17126: checking for libgccjit.h
configure:17126: result: yes
configure:17192: x86_64-pc-linux-gnu-gcc -o conftest -O2 -pipe -march=native -g -pthread -isystem /usr/include/librsvg-2.0 -isystem /usr/include/gdk-pixbuf-2.0 -isystem /usr/include/libmount -isys
tem /usr/include/blkid -isystem /usr/include/cairo -isystem /usr/lib64/libffi/include -isystem /usr/include/pixman-1 -isystem /usr/include/uuid -isystem /usr/include/freetype2 -isystem /usr/includ
e/harfbuzz -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/libpng16 -isystem /usr/include/cairo -isystem /usr/lib64/libffi/include -isystem /usr/include/p
ixman-1 -isystem /usr/include/uuid -isystem /usr/include/freetype2 -isystem /usr/include/harfbuzz -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/libpng16
    -Wl,-O1 -Wl,--as-needed conftest.c -lgccjit >&5 
configure:17192: $? = 0
configure:17192: ./conftest
ld: cannot find crtbeginS.o: No such file or directory
ld: cannot find -lgcc
ld: cannot find -lgcc_s
libgccjit.so: error: error invoking gcc driver
configure:17192: $? = 1
configure: program exited with status 1
```

I guessed that ccache was the problem, and it worked fine after overriding with FEATURES=-ccache.  This is of course no proof, but it sounds reasonable to me that ccache is the culprit.
Probably distcc won’t work either, but I don’t have it set up here, so I can’t test that.
Comment 1 Ulrich Müller gentoo-dev 2021-07-11 14:47:39 UTC
(In reply to Thomas Schneider from comment #0)

I can reproduce the problem, and it looks like a regression.

Configure also fails with commit e761e12498 from the Emacs master branch, which is the version I had tested when adding the jit flag to the ebuild. So it doesn't seem to be caused by changes in Emacs.

CCing toolchain maintainers, any idea what would would cause this error:

> ld: cannot find crtbeginS.o: No such file or directory
> ld: cannot find -lgcc
> ld: cannot find -lgcc_s
> libgccjit.so: error: error invoking gcc driver
Comment 2 Sergei Trofimovich (RETIRED) gentoo-dev 2021-07-11 16:50:32 UTC
Created attachment 723316 [details]
a.c

Extracted config.log test into a.c.

ccache's PATH interferes with gccjit's driver path discovery:

$ gcc a.c -o a -lgccjit && ./a

$ gcc a.c -o a -lgccjit && PATH=/usr/lib/ccache/bin:$PATH ./a
ld: cannot find crtbeginS.o: No such file or directory
ld: cannot find -lgcc
ld: cannot find -lgcc_s
libgccjit.so: error: error invoking gcc driver

stracing the details. Good:

# gcc a.c -o a -lgccjit && strace -f -etrace=execve ./a
execve("./a", ["./a"], 0x7ffef6ecc2c0 /* 32 vars */) = 0
strace: Process 399994 attached
[pid 399994] execve("/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../x86_64-pc-linux-gnu/bin/as", ["/usr/lib/gcc/x86_64-pc-linux-gnu"..., "--64", "-o", "/tmp/ccABa2Ug.o", "/tmp/libgccjit-tjiTFw/fake.s"], 0x55ccc5b1a810 /* 35 vars */) = 0
[pid 399994] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=399994, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 399995 attached
[pid 399995] execve("/usr/libexec/gcc/x86_64-pc-linux-gnu/11.1.0/collect2", ["/usr/libexec/gcc/x86_64-pc-linux"..., "--eh-frame-hdr", "-m", "elf_x86_64", "-shared", "-o", "/tmp/libgccjit-tjiTFw/fake.so", "/usr/lib/gcc/x86_64-pc-linux-gnu"..., "/usr/lib/gcc/x86_64-pc-linux-gnu"..., "-L/usr/lib/gcc/x86_64-pc-linux-g"..., "-L/usr/lib/gcc/x86_64-pc-linux-g"..., "-L/lib/../lib64", "-L/usr/lib/../lib64", "-L/usr/lib/gcc/x86_64-pc-linux-g"..., "-L/usr/lib/gcc/x86_64-pc-linux-g"..., "/tmp/ccABa2Ug.o", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "-lc", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "/usr/lib/gcc/x86_64-pc-linux-gnu"..., "/usr/lib/gcc/x86_64-pc-linux-gnu"...], 0x55ccc5b1a9d0 /* 37 vars */) = 0
strace: Process 399996 attached
[pid 399996] execve("/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../x86_64-pc-linux-gnu/bin/ld", ["/usr/lib/gcc/x86_64-pc-linux-gnu"..., "--eh-frame-hdr", "-m", "elf_x86_64", "-shared", "-o", "/tmp/libgccjit-tjiTFw/fake.so", "/usr/lib/gcc/x86_64-pc-linux-gnu"..., "/usr/lib/gcc/x86_64-pc-linux-gnu"..., "-L/usr/lib/gcc/x86_64-pc-linux-g"..., "-L/usr/lib/gcc/x86_64-pc-linux-g"..., "-L/lib/../lib64", "-L/usr/lib/../lib64", "-L/usr/lib/gcc/x86_64-pc-linux-g"..., "-L/usr/lib/gcc/x86_64-pc-linux-g"..., "/tmp/ccABa2Ug.o", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "-lc", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "/usr/lib/gcc/x86_64-pc-linux-gnu"..., "/usr/lib/gcc/x86_64-pc-linux-gnu"...], 0x7ffef72ad908 /* 37 vars */) = 0
[pid 399996] +++ exited with 0 +++
[pid 399995] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=399996, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
[pid 399995] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=399995, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++

Bad:

# gcc a.c -o a -lgccjit && PATH=/usr/lib/ccache/bin:$PATH strace -f -etrace=execve ./a
execve("./a", ["./a"], 0x7ffc2b3f7d30 /* 32 vars */) = 0
strace: Process 400006 attached
[pid 400006] execve("/usr/lib/ccache/bin/as", ["as", "--64", "-o", "/tmp/ccal5ZVU.o", "/tmp/libgccjit-ami65f/fake.s"], 0x555fab77b810 /* 35 vars */) = -1 ENOENT (No such file or directory)
[pid 400006] execve("/usr/local/sbin/as", ["as", "--64", "-o", "/tmp/ccal5ZVU.o", "/tmp/libgccjit-ami65f/fake.s"], 0x555fab77b810 /* 35 vars */) = -1 ENOENT (No such file or directory)
[pid 400006] execve("/usr/local/bin/as", ["as", "--64", "-o", "/tmp/ccal5ZVU.o", "/tmp/libgccjit-ami65f/fake.s"], 0x555fab77b810 /* 35 vars */) = -1 ENOENT (No such file or directory)
[pid 400006] execve("/usr/sbin/as", ["as", "--64", "-o", "/tmp/ccal5ZVU.o", "/tmp/libgccjit-ami65f/fake.s"], 0x555fab77b810 /* 35 vars */) = -1 ENOENT (No such file or directory)
[pid 400006] execve("/usr/bin/as", ["as", "--64", "-o", "/tmp/ccal5ZVU.o", "/tmp/libgccjit-ami65f/fake.s"], 0x555fab77b810 /* 35 vars */) = 0
[pid 400006] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=400006, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 400007 attached
[pid 400007] execve("/usr/lib/ccache/bin/ld", ["ld", "--eh-frame-hdr", "-m", "elf_x86_64", "-shared", "-o", "/tmp/libgccjit-ami65f/fake.so", "/usr/lib/../lib64/crti.o", "crtbeginS.o", "-L/lib/../lib64", "-L/usr/lib/../lib64", "/tmp/ccal5ZVU.o", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "-lc", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "crtendS.o", "/usr/lib/../lib64/crtn.o"], 0x555fab77b9d0 /* 37 vars */) = -1 ENOENT (No such file or directory)
[pid 400007] execve("/usr/local/sbin/ld", ["ld", "--eh-frame-hdr", "-m", "elf_x86_64", "-shared", "-o", "/tmp/libgccjit-ami65f/fake.so", "/usr/lib/../lib64/crti.o", "crtbeginS.o", "-L/lib/../lib64", "-L/usr/lib/../lib64", "/tmp/ccal5ZVU.o", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "-lc", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "crtendS.o", "/usr/lib/../lib64/crtn.o"], 0x555fab77b9d0 /* 37 vars */) = -1 ENOENT (No such file or directory)
[pid 400007] execve("/usr/local/bin/ld", ["ld", "--eh-frame-hdr", "-m", "elf_x86_64", "-shared", "-o", "/tmp/libgccjit-ami65f/fake.so", "/usr/lib/../lib64/crti.o", "crtbeginS.o", "-L/lib/../lib64", "-L/usr/lib/../lib64", "/tmp/ccal5ZVU.o", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "-lc", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "crtendS.o", "/usr/lib/../lib64/crtn.o"], 0x555fab77b9d0 /* 37 vars */) = -1 ENOENT (No such file or directory)
[pid 400007] execve("/usr/sbin/ld", ["ld", "--eh-frame-hdr", "-m", "elf_x86_64", "-shared", "-o", "/tmp/libgccjit-ami65f/fake.so", "/usr/lib/../lib64/crti.o", "crtbeginS.o", "-L/lib/../lib64", "-L/usr/lib/../lib64", "/tmp/ccal5ZVU.o", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "-lc", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "crtendS.o", "/usr/lib/../lib64/crtn.o"], 0x555fab77b9d0 /* 37 vars */) = -1 ENOENT (No such file or directory)
[pid 400007] execve("/usr/bin/ld", ["ld", "--eh-frame-hdr", "-m", "elf_x86_64", "-shared", "-o", "/tmp/libgccjit-ami65f/fake.so", "/usr/lib/../lib64/crti.o", "crtbeginS.o", "-L/lib/../lib64", "-L/usr/lib/../lib64", "/tmp/ccal5ZVU.o", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "-lc", "-lgcc", "--push-state", "--as-needed", "-lgcc_s", "--pop-state", "crtendS.o", "/usr/lib/../lib64/crtn.o"], 0x555fab77b9d0 /* 37 vars */) = 0
ld: cannot find crtbeginS.o: No such file or directory
ld: cannot find -lgcc
ld: cannot find -lgcc_s
[pid 400007] +++ exited with 1 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=400007, si_uid=0, si_status=1, si_utime=0, si_stime=0} ---
libgccjit.so: error: error invoking gcc driver
+++ exited with 1 +++
Comment 3 Sergei Trofimovich (RETIRED) gentoo-dev 2021-07-11 17:00:42 UTC
The difference of 'as' load is not too bad:
  /usr/x86_64-pc-linux-gnu/binutils-bin/2.36.1/as
vs
  /usr/bin/as

The difference of 'ld' is bigger:
  /usr/libexec/gcc/x86_64-pc-linux-gnu/11.1.0/collect2
vs
  /usr/bin/ld

As if gcc's driver was bypassed completely. As a result we lost all the startfiles. Probably a gcc/gccjit driver bug.
Comment 4 Ulrich Müller gentoo-dev 2021-07-11 17:58:31 UTC
Looks like the issue is related to this gcc/jit upstream bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87808#c8
Comment 5 Larry the Git Cow gentoo-dev 2021-07-11 18:45:38 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5bd9495d157f02609a2942992e42cf08121ea15a

commit 5bd9495d157f02609a2942992e42cf08121ea15a
Author:     Ulrich Müller <ulm@gentoo.org>
AuthorDate: 2021-07-11 18:45:12 +0000
Commit:     Ulrich Müller <ulm@gentoo.org>
CommitDate: 2021-07-11 18:45:32 +0000

    app-editors/emacs: Work around jit not working with ccache
    
    Bug: https://bugs.gentoo.org/801580
    Package-Manager: Portage-3.0.20, Repoman-3.0.3
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>

 app-editors/emacs/emacs-28.0.9999.ebuild | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
Comment 6 Ulrich Müller gentoo-dev 2021-07-11 18:47:17 UTC
I've worked around it for now by setting LIBRARY_PATH explicitly. Please test.

Still, this should be fixed properly, therefore leaving this bug open.
Comment 7 Ulrich Müller gentoo-dev 2021-07-12 09:59:15 UTC
Created attachment 723508 [details]
tut01-hello-world.c

It also fails with the hello world program from the libgccjit tutorial (attaching it here for later reference):
https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html

$ gcc tut01-hello-world.c -o tut01-hello-world -lgccjit
$ ./tut01-hello-world 
hello world
$ PATH=/usr/lib/ccache/bin:${PATH} ./tut01-hello-world 
ld: cannot find crtbeginS.o: No such file or directory
ld: cannot find -lgcc
ld: cannot find -lgcc_s
libgccjit.so: error: error invoking gcc driver

So this definitely isn't an Emacs bug.
Comment 8 Thomas Schneider 2021-07-27 13:17:15 UTC
(In reply to Ulrich Müller from comment #6)
> I've worked around it for now by setting LIBRARY_PATH explicitly. Please
> test.
> 
> Still, this should be fixed properly, therefore leaving this bug open.

Yes, this works now for app-editors/emacs-28.0.9999.
Comment 9 Petr Šourek 2022-12-09 10:07:10 UTC
Hello,

sorry I am wondering where should I point the LIBRARY_PATH? I have ccache enabled on package level, both sys-devel/gcc and app-editors/emacs are enabled, but even when I "disable" the packages for ccache in /etc/portage/package.env file, recompile them, I am unable to install spacemacs into emacs. Everytime it fails with:

Debugger entered--Lisp error: (native-ice "failed to compile" "/home/djmanas/.emacs.d/eln-cache/28.2-d445f548/sub..." "error invoking gcc driver")


sys-devel/gcc version 11.3.0 USE="cxx fortran graphite jit lto multilib nls nptl openmp pie sanitize ssp vtv -ada -cet -custom-cflags -d -debug -doc -fixed-point -go -hardened -libssp -objc -objc++ -objc-gc -pch -pgo -systemtap -test -valgrind -vanilla -zstd"

app-editors/emacs version 28.2-r2 USE="acl alsa cairo dbus dynamic-loading games gfile gif gmp gpm gsettings gtk gui gzip-el inotify jit jpeg json lcms libxml2 png ssl svg systemd threads tiff xft xpm xwidgets zlib -Xaw3d -aqua -athena -harfbuzz -imagemagick -kerberos -livecd -m17n-lib -mailutils -motif -selinux -sound -source -toolkit-scroll-bars -wide-int"

Thanks,
Regards,
Petr Sourek
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-12-09 13:51:04 UTC Comment hidden (obsolete)
Comment 11 Petr Šourek 2022-12-09 22:17:05 UTC
(In reply to Sam James from comment #10)

> This shouldn't make any difference to when building stuff as a user.

Oh ok. So its emacs error then? I am only trying to install and setup spacemacs from scratch, but wasn't able since I had switched from MacOS. Tried more versions of emacs, all of them failed with this exact same error about:
> ld: cannot find crtbeginS.o: No such file or directory
> ld: cannot find -lgcc
> ld: cannot find -lgcc_s
> libgccjit.so: error: error invoking gcc driver

So I had thought its gentoo related. I will try it there.
Thanks,
Regards,
Petr Sourek
Comment 12 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-12-09 22:24:47 UTC Comment hidden (obsolete)
Comment 13 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-12-09 22:56:03 UTC
Sorry, I was completely wrong there -- I didn't re-read the bug and went off memory. If you built Emacs (or possibly spacemacs) with ccache, it will affect it.
Comment 14 Petr Šourek 2022-12-11 15:35:35 UTC
I had rebuilt it with ccache disabled, and it did not work. It seems there is problem with the path to library.

Now I am trying to install Emacs Doom and specifying the path on the start of doom seems to work. Hope it will take it into account when generating env variables.

LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/ ~/.emacs.d/bin/doom install

Maybee adding this variable to .spacemacs.env would work too. Thanks. It seems its ok for me with this workaround.