Bug 263271 - lang/gcc11: Add upstream patch to fix bug of libgccgit
Summary: lang/gcc11: Add upstream patch to fix bug of libgccgit
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Yasuhiro Kimura
URL: https://debbugs.gnu.org/cgi/bugreport...
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-14 05:32 UTC by Yasuhiro Kimura
Modified: 2022-04-16 08:15 UTC (History)
4 users (show)

See Also:


Attachments
Patch file (2.23 KB, patch)
2022-04-14 18:36 UTC, Yasuhiro Kimura
yasu: maintainer-approval? (toolchain)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yasuhiro Kimura freebsd_committer freebsd_triage 2022-04-14 05:32:44 UTC
1. Since 28.x Emacs supports native compilation.
1.1. While byte compilation converts source code of emacs lisp to byte code independent from HW and/or OS, native compilation converts it to native code of the platform on which Emacs runs.
1.2. Emacs uses libgccgit of GCC to do native compilation.
1.3. Emacs provides two ways for native compilation. One is just-in-time way that is done first time when source file (.el) is loaded. The other is explict way that is done by invoking emacs lisp function that do native compilation.

2. Native compilation is enabled when Emacs is built
2.1. It is enabled by passing '--with-native-compilation' option to configure script.
2.2. At the moment, it is off by default.
2.3. The way is also provided to native compile and install all emacs lisp files included in source tree.

3. NATIVECOMP option was added to editors/emacs-devel in June 2021.
3.1. It is off by default.
3.2. If it is enabled, all .el files included in source archive are native compiled and installed.
3.3. Currently lang/gcc11 is used to support native compilation as there is a note as following in the document of GCC 10 and before:
"Note that libgccjit is currently of “Alpha” quality; the APIs are not yet set in stone, and they shouldn’t be used in production yet."

4. With the latest ports tree build of editors/emacs-devel fails if NATIVECOMP option is enabled.
4.1. It fails with segmantation fault of emacs while native compiling 'emoji.el' as following.
https://people.freebsd.org/~yasu/poudriere/data/logs/bulk/130amd64-default-emacs/2022-04-12_17h00m39s/logs/emacs-devel-nox-29.0.50.20220331_1,2.log
4.2 I faced the failure when I updated ports tree from ports 9aa49f27ffd0 (committed on April 7) to ports 7f2e164a4b3b (committed on April 12).
4.3. According to the result of `git bisect`, the build failure happens with following commit and after.

----------------------------------------------------------------------
commit 2f6be9fb8281
Author:     Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: Mon Apr 11 10:46:01 2022 +0000
Commit:     Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: Mon Apr 11 10:46:01 2022 +0000

    lang/gcc11: switch gcc11 to LTO bootstrap
    
    lang/gcc11-devel with LTO builds fine on the cluster, switch lang/gcc11 as well.
----------------------------------------------------------------------

5. The cause of the build failure seems to be bug of lang/gcc11 about LTO
5.1 If I revert the commit above then build completes successfully.
5.2. I modified Makefile of editors/emacs-devel so it uses lang/gcc12-devel. Then build completes successfully.
5.3. I also modified the Makefile so it uses lang/gcc11-devel. In this case build fails with same error. Next, I updated lang/gcc11-devel to the 20220409 snapshot of GCC 11.2.1. Then build completes successfully.
Comment 1 Yasuhiro Kimura freebsd_committer freebsd_triage 2022-04-14 18:36:30 UTC
Created attachment 233223 [details]
Patch file

Add upstream patch to fix bug of libgccgit.

I found the build failure is already reported in bug tracker of Emacs.

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=51688

According to it the cause of the problem is bug of libgccjit. So add upstream patch to fix it.
Comment 2 Piotr Kubaj freebsd_committer freebsd_triage 2022-04-14 20:07:45 UTC
lang/gcc11 currently doesn't have a maintainer, so if it fixes compilation for you, you can just commit it.
Comment 3 Gerald Pfeifer freebsd_committer freebsd_triage 2022-04-16 01:32:15 UTC
Note if current lang/gcc11-devel is affected that one should be fixed
as well - presumably by simply updating to a current snapshot, which
is way overdue anyway.

Can you please test with lang/gcc11-devel? (If you need help on how to
go about that, let me know and I should be able to help.)
Comment 4 Yasuhiro Kimura freebsd_committer freebsd_triage 2022-04-16 02:33:32 UTC
(In reply to Gerald Pfeifer from comment #3)

As I wrote in comment #0, build error also happens with current lang/gcc11-devel but is fixed by updating it to latest snapshot of GCC 11.2.1. So I'll also commit update of lang/gcc11-devel.
Comment 5 Gerald Pfeifer freebsd_committer freebsd_triage 2022-04-16 02:55:25 UTC
Apologies, I missed item 5.3 in the original description.

Thank you for your detailed analysis and plan to address this both in
lang/gcc11 and lang/gcc11-devel. Those two ports are currently assigned
to toolchain@, which is a list, but having maintained lang/gcc* for two
decades you can go ahead with
  Approved by: gerald (toolchain@)
if you wish.
Comment 6 Yasuhiro Kimura freebsd_committer freebsd_triage 2022-04-16 07:55:47 UTC
Take.
Comment 7 commit-hook freebsd_committer freebsd_triage 2022-04-16 08:09:39 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=427746f6a3ecdb70f182adfd42e48130f273fdda

commit 427746f6a3ecdb70f182adfd42e48130f273fdda
Author:     Yasuhiro Kimura <yasu@FreeBSD.org>
AuthorDate: 2022-04-14 18:11:17 +0000
Commit:     Yasuhiro Kimura <yasu@FreeBSD.org>
CommitDate: 2022-04-16 08:07:56 +0000

    lang/gcc11: Add upstream patch to fix bug of libgccjit

    After switching to LTO bootstrap with commit 2f6be9fb8281, build of
    editors/emacs-devel fails with segmentation fault of emacs if
    NATIVECOMP option is enabled. The cause of the problem is bug of
    libgccjit and it was unveiled by switching to LTO bootstrap. So add
    upstream patch to fix it.

    PR:             263271
    Approved by:    gerald (toolchain@)

 lang/gcc11/Makefile                                |  2 +-
 .../gcc11/files/patch-gcc_jit_jit-playback.c (new) | 33 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2022-04-16 08:09:40 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e66c56ac6a69696e3650e5f5d30514cfda4929d5

commit e66c56ac6a69696e3650e5f5d30514cfda4929d5
Author:     Yasuhiro Kimura <yasu@FreeBSD.org>
AuthorDate: 2022-04-14 01:39:29 +0000
Commit:     Yasuhiro Kimura <yasu@FreeBSD.org>
CommitDate: 2022-04-16 08:07:51 +0000

    lang/gcc11-devel: Update to the 20220409 snapshot of GCC 11.2.1

    PR:             263271
    Approved by:    gerald (toolchain@)

 lang/gcc11-devel/Makefile | 3 +--
 lang/gcc11-devel/distinfo | 6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)