NetBSD Problem Report #58505

From www@netbsd.org  Sun Jul 28 20:56:27 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D5A401A923C
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 28 Jul 2024 20:56:26 +0000 (UTC)
Message-Id: <20240728205625.55CA11A923E@mollari.NetBSD.org>
Date: Sun, 28 Jul 2024 20:56:25 +0000 (UTC)
From: tnn@nygren.pp.se
Reply-To: tnn@nygren.pp.se
To: gnats-bugs@NetBSD.org
Subject: GCC 12.4.0 on alpha broken at -O2
X-Send-Pr-Version: www-1.0

>Number:         58505
>Category:       toolchain
>Synopsis:       GCC 12.4.0 on alpha w/ isl broken at -O2
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    mrg
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 28 21:00:00 +0000 2024
>Closed-Date:    Sun Aug 11 12:14:28 +0000 2024
>Last-Modified:  Sun Aug 11 12:14:28 +0000 2024
>Originator:     Tobias Nygren
>Release:        10.99.11
>Organization:
>Environment:
>Description:
It cross compiles OK, but natively ./build.sh fails
immediately when bootstrapping make.

pc164sx# gcc -c -O2 -o test.o test.c
during GIMPLE pass: thread
print2.c: In function 'func':
print2.c:4:1: internal compiler error: Segmentation fault
    4 | func()

Changing a < 10 to a < 2 in the reproducer hides the problem.
Loop optimizer problem?
>How-To-Repeat:
//---8<---
int aaa(void);
void func() {
        int a, b = 0;
        for (a = 0; a < 10; a++) {
                        if (b  >= 10) {
                                aaa();
                        }
                b += aaa();
        }
}
//---8<---

Starting program: /usr/libexec/cc1 -fpreprocessed test.i -quiet -dumpbase test.c -dumpbase-ext .c -O2 -version -o test.s
...
Program received signal SIGSEGV, Segmentation fault.
0x00000001205d24d8 in ipa_edge_within_scc(cgraph_edge*) ()
(gdb) bt
#0  0x00000001205d24d8 in ipa_edge_within_scc(cgraph_edge*) ()
#1  0x0000000120f19c88 in path_range_query::range_defined_in_block(irange&, tree_node*, basic_block_def*) ()
#2  0x0000000120f1a240 in path_range_query::compute_ranges_in_phis(basic_block_def*) ()
#3  0x0000000120f1a548 in path_range_query::compute_ranges_in_block(basic_block_def*) ()
#4  0x0000000120f1ac08 in path_range_query::compute_ranges(vec<basic_block_def*, va_heap, vl_ptr> const&, bitmap_head const*) ()
#5  0x0000000120ea2b58 in back_threader::find_taken_edge_cond(vec<basic_block_def*, va_heap, vl_ptr> const&, gcond*) ()
#6  0x0000000120ea3a7c in back_threader::maybe_register_path() ()
#7  0x0000000120ea4240 in back_threader::find_paths_to_names(basic_block_def*, bitmap_head*) ()
#8  0x0000000120ea45c8 in back_threader::resolve_phi(gphi*, bitmap_head*) [clone .part.0] ()
#9  0x0000000120ea40d4 in back_threader::find_paths_to_names(basic_block_def*, bitmap_head*) ()
#10 0x0000000120ea4738 in back_threader::find_paths(basic_block_def*, tree_node*) ()
#11 0x0000000120ea4a54 in back_threader::thread_blocks() ()
#12 0x0000000120ea4af4 in (anonymous namespace)::pass_thread_jumps::execute(function*) ()
#13 0x00000001203a4048 in execute_one_pass(opt_pass*) ()
#14 0x00000001203a4c70 in execute_pass_list_1(opt_pass*) ()
#15 0x00000001203a4c8c in execute_pass_list_1(opt_pass*) ()
#16 0x00000001203a4d04 in execute_pass_list(function*, opt_pass*) ()
#17 0x0000000120c8d760 in cgraph_node::expand() ()
#18 0x0000000120c8f654 in symbol_table::compile() [clone .part.0] ()
#19 0x0000000120c92d50 in symbol_table::finalize_compilation_unit() ()
#20 0x00000001202ed338 in compile_file() ()
#21 0x00000001214eef1c in toplev::main(int, char**) ()
#22 0x00000001214ed230 in main ()

>Fix:
Workaround is to compile at -O1 or at -O2 with some of the threading passes disabled (-fdisable-tree-thread2 helps in this particular case).

>Release-Note:

>Audit-Trail:
From: Jason Thorpe <thorpej@me.com>
To: gnats-bugs@netbsd.org
Cc: port-alpha-maintainer@netbsd.org,
 gnats-admin@netbsd.org,
 netbsd-bugs@netbsd.org
Subject: Re: port-alpha/58505: GCC 12.4.0 on alpha broken at -O2
Date: Mon, 29 Jul 2024 08:20:53 -0700

 > On Jul 28, 2024, at 2:00=E2=80=AFPM, tnn@nygren.pp.se wrote:
 >=20
 >> Severity:       serious
 >> Priority:       medium
 >> Responsible:    port-alpha-maintainer

 Should this be in the toolchain category?

 -- thorpej

From: Tobias Nygren <tnn@nygren.pp.se>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-alpha/58505: GCC 12.4.0 on alpha broken at -O2
Date: Mon, 29 Jul 2024 20:55:50 +0200

 On Mon, 29 Jul 2024 15:25:02 +0000 (UTC)
 Jason Thorpe <thorpej@me.com> wrote:

 >  Should this be in the toolchain category?

 Probably. I'll move it to toolchain after root cause analysis is done.
 I did recompile my entire userland with -Os through a cross compile and
 now gcc -O2 works so it does look like a code generation problem but it
 could be something libc or rtld related as well.

From: Rin Okuyama <rokuyama.rk@gmail.com>
To: gnats-bugs@netbsd.org, port-alpha-maintainer@netbsd.org,
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, tnn@nygren.pp.se
Cc: matthew green <mrg@NetBSD.org>
Subject: Re: port-alpha/58505: GCC 12.4.0 on alpha broken at -O2
Date: Fri, 2 Aug 2024 11:03:32 +0900

 (cc: added to mrg@)

 I've found this is due to isl; the failure started from mknative for
 this change:

 ----
 build and link libisl.
 https://mail-index.netbsd.org/source-changes/2024/02/25/msg150123.html
 ----

 (1) If the following files from isl are compiled with -O1:

 ----
 isl_map_to_basic_set.c
 isl_polynomial.c
 isl_schedule*.c
 isl_set_list.c
 isl_space.c
 isl_tab*.c
 isl_tarjan.c
 isl_union_map.c
 ----

 test.c (provided by tnn@) can be compiled with -O2. However, still,
 native build.sh fails early in tools.

 (2) Even if all isl files are compiled with -O1, build.sh also
 fails in tools.

 (3) If all isl files are compiled with -O0, gcc cannot be linked
 due to truncation of relocation.

 (4) If isl is completely disabled, tools (including gcc) successfully
 build natively.

 Thanks,
 rin

From: matthew green <mrg@eterna23.net>
To: Rin Okuyama <rokuyama.rk@gmail.com>
Cc: gnats-bugs@netbsd.org, port-alpha-maintainer@netbsd.org,
    gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, tnn@nygren.pp.se
Subject: re: port-alpha/58505: GCC 12.4.0 on alpha broken at -O2
Date: Fri, 02 Aug 2024 18:26:05 +1000

 Rin Okuyama writes:
 > I've found this is due to isl; the failure started from mknative for
 > this change:

 how strange.

 can you try disabling the things that isl enables?  each alone
 or in groups might be necessary to track better..  eg, these if
 they're enabled:

 	-ftree-loop-linear
 	-floop-strip-mine
 	-floop-block
 	-fgraphite-identity
 	-floop-nest-optimize
 	-floop-parallelize-all

 at worst, we can just disable isl for alpha.

 good find, thanks.


 .mrg.

Responsible-Changed-From-To: port-alpha-maintainer->mrg
Responsible-Changed-By: tnn@NetBSD.org
Responsible-Changed-When: Fri, 02 Aug 2024 11:34:28 +0000
Responsible-Changed-Why:
reassign


From: Tobias Nygren <tnn@NetBSD.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: toolchain/58505: GCC 12.4.0 on alpha w/ isl broken at -O2
Date: Fri, 2 Aug 2024 13:30:02 +0200

 [category alpha->toolchain] 

 > Rin Okuyama writes:
 > > I've found this is due to isl

 I guess isl-enabled GCC miscompiles parts of GCC. It does not
 necessarily have to be just the isl code that gets miscompiled.

 matthew green <mrg@eterna23.net> wrote:
 > at worst, we can just disable isl for alpha.

 Are there Linux distros that build GCC with isl for alpha?
 (Are there even Linux distros that still support alpha?)

 Until we can find the miscompiled code and upstream a
 fix, I'm in favor of rerunning mknative --without-isl.

From: Rin Okuyama <rokuyama.rk@gmail.com>
To: gnats-bugs@netbsd.org, mrg@netbsd.org, gnats-admin@netbsd.org,
 netbsd-bugs@netbsd.org, tnn@nygren.pp.se
Cc: 
Subject: Re: toolchain/58505: GCC 12.4.0 on alpha w/ isl broken at -O2
Date: Sat, 3 Aug 2024 18:19:36 +0900

 (1) I've confirmed there's no regression for full ATF run on
 a system built by GCC 12.4 with isl disabled.

 On 2024/08/02 17:26, matthew green wrote:
  > can you try disabling the things that isl enables?  each alone
  > or in groups might be necessary to track better..  eg, these if
  > they're enabled:
  >
  > 	-ftree-loop-linear
  > 	-floop-strip-mine
  > 	-floop-block
  > 	-fgraphite-identity
  > 	-floop-nest-optimize
  > 	-floop-parallelize-all
  >
  > at worst, we can just disable isl for alpha.

 Unfortunately, I couldn't narrow down the problem :(

 (2) `cc -c test.c` succeeds even if all of these options specified, and
 (3) `cc -c -O2 test.c` fails even if all of these options disabled.

 On 2024/08/02 20:35, Tobias Nygren wrote:
 > > Rin Okuyama writes:
 > > > I've found this is due to isl
 > 
 > I guess isl-enabled GCC miscompiles parts of GCC. It does not
 > necessarily have to be just the isl code that gets miscompiled.

 I may misread your intention, but:

 (4) If isl is disabled **only for tools**, generated GCC 12.4 crashes
      when compiling test.c with -O2.

 Thanks,
 rin

From: Rin Okuyama <rokuyama.rk@gmail.com>
To: gnats-bugs@netbsd.org, mrg@netbsd.org, gnats-admin@netbsd.org,
 netbsd-bugs@netbsd.org, tnn@nygren.pp.se
Cc: 
Subject: Re: toolchain/58505: GCC 12.4.0 on alpha w/ isl broken at -O2
Date: Wed, 7 Aug 2024 10:19:57 +0900

 I've found this is not a recent regression:

 (1) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84204
 (2) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84353

 Upstream cannot fix it for 6 years from initial report :(

 So, we should just disable isl for alpha.

 Also, (2) suggests this is not an alpha specific problem.
 Although, I've never observed a similar regression on other
 platforms so far.

 Thanks,
 rin

 PS
 With isl disabled, I've successfully built release natively
 on my DS10, with MKDEBUG=yes, MKDEBUGLIB=yes, and MKX11=no,
 for 54 hours :)

From: matthew green <mrg@eterna23.net>
To: Rin Okuyama <rokuyama.rk@gmail.com>
Cc: gnats-bugs@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org, tnn@nygren.pp.se
Subject: re: toolchain/58505: GCC 12.4.0 on alpha w/ isl broken at -O2
Date: Wed, 07 Aug 2024 17:37:44 +1000

 i'm preparing a change to make isl non-required, default off for alpha.

 we might want it for other platforms where the benefit is dubious..


 .mrg.

From: Tobias Nygren <tnn@nygren.pp.se>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: toolchain/58505: GCC 12.4.0 on alpha w/ isl broken at -O2
Date: Wed, 7 Aug 2024 14:24:34 +0200

 I am running a native build.sh with this change.
 It has been going for 5 days. PC164SX is not the fastest ...
 I expect it will work fine, but will report back to confirm
 when done. I think it will finish tomorrow.

 --- external/gpl3/gcc/usr.bin/gcc/arch/alpha/auto-host.h	30 Jun 2024 09:36:51 -0000	1.21
 +++ external/gpl3/gcc/usr.bin/gcc/arch/alpha/auto-host.h	7 Aug 2024 12:20:17 -0000
 @@ -2215,7 +2215,7 @@

  /* Define if isl is in use. */
  #ifndef USED_FOR_TARGET
 -#define HAVE_isl 1
 +/* #undef HAVE_isl */
  #endif

 --- tools/gcc/Makefile	16 Jun 2024 16:03:30 -0000	1.113
 +++ tools/gcc/Makefile	7 Aug 2024 12:20:17 -0000
 @@ -67,6 +67,8 @@ COMMON_CONFIGURE_ARGS+=	--with-default-l
  # removing GCC 10.
  .if ${HAVE_GCC} < 12
  ISL_CONFIGURE_ARGS+=	--without-isl
 +.elif ${MACHINE_ARCH} == "alpha"
 +ISL_CONFIGURE_ARGS+=	--without-isl
  .else
  ISL_CONFIGURE_ARGS+=	--with-isl=${TOOLDIR}
  .endif

From: "matthew green" <mrg@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58505 CVS commit: src
Date: Sat, 10 Aug 2024 23:49:13 +0000

 Module Name:	src
 Committed By:	mrg
 Date:		Sat Aug 10 23:49:12 UTC 2024

 Modified Files:
 	src/external/gpl3/gcc/usr.bin: Makefile Makefile.isl
 	src/share/mk: bsd.own.mk
 	src/tools: Makefile
 	src/tools/gcc: Makefile

 Log Message:
 introduce a way to build GCC without the isl library

 if NOGCCISL is set, don't build or link against isl.  should fix PR#58505.


 To generate a diff of this commit:
 cvs rdiff -u -r1.16 -r1.17 src/external/gpl3/gcc/usr.bin/Makefile
 cvs rdiff -u -r1.1 -r1.2 src/external/gpl3/gcc/usr.bin/Makefile.isl
 cvs rdiff -u -r1.1392 -r1.1393 src/share/mk/bsd.own.mk
 cvs rdiff -u -r1.222 -r1.223 src/tools/Makefile
 cvs rdiff -u -r1.113 -r1.114 src/tools/gcc/Makefile

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: mrg@NetBSD.org
State-Changed-When: Sun, 11 Aug 2024 00:01:57 +0000
State-Changed-Why:
should be fixed in -current now. can you check, after reverting local changes?

thanks.


State-Changed-From-To: feedback->closed
State-Changed-By: tnn@NetBSD.org
State-Changed-When: Sun, 11 Aug 2024 12:14:28 +0000
State-Changed-Why:
Fix is good.
Should be revisited for next GCC major import.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.