NetBSD Problem Report #53346

From he@smistad.uninett.no  Tue Jun  5 20:59:09 2018
Return-Path: <he@smistad.uninett.no>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id F3A5A7A153
	for <gnats-bugs@gnats.NetBSD.org>; Tue,  5 Jun 2018 20:59:08 +0000 (UTC)
Message-Id: <20180605205901.4E1F643F117@smistad.uninett.no>
Date: Tue,  5 Jun 2018 22:59:01 +0200 (CEST)
From: he@NetBSD.org
Reply-To: he@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: gcc powerpc optimizer bug exposed by lang/mercury
X-Send-Pr-Version: 3.95

>Number:         53346
>Category:       pkg
>Synopsis:       The configure test for use of labels loops on powerpc
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 05 21:00:00 +0000 2018
>Closed-Date:    Thu Jun 17 00:02:58 +0000 2021
>Last-Modified:  Thu Jun 17 16:50:01 +0000 2021
>Originator:     he@NetBSD.org
>Release:        NetBSD 8.0_BETA
>Organization:
	I Try
>Environment:


System: NetBSD golden-delicious.urc.uninett.no 8.0_BETA NetBSD 8.0_BETA (GOLDEN-DELICIOUS) #4: Mon Sep 11 00:24:51 CEST 2017  he@golden-delicious.urc.uninett.no:/usr/obj/sys/arch/macppc/compile/GOLDEN-DELICIOUS macppc
Architecture: powerpc
Machine: macppc
>Description:
	The configure test for whether one can use labels in
	the compiler in pkgsrc/lang/mercury reveals an optimizer bug
	in gcc 5.4.0 (nb1 20160606).  I've also tested with gcc 5.5.0
	(nb2 20180327), and it also loops on -O2.

	Build the test with -O1, and it works.
	Build it with -O2 or -O3, it loops.
	I added printf()s, and when it loops, it prints

foo
dummy_id
return foo
foo
dummy_id
return foo

ad infinitum or the CPU time limit is exceeded.

>How-To-Repeat:
	Here's the conftest.c file left by configure:

/* confdefs.h */
#define PACKAGE_NAME ""
#define PACKAGE_TARNAME ""
#define PACKAGE_VERSION ""
#define PACKAGE_STRING ""
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
#define MR_FULLARCH "powerpc--netbsd"
#define MR_VERSION "14.01.1"
#define MR_MKFIFO "/usr/bin/mkfifo"
#define MR_HOSTNAMECMD "/bin/hostname -f"
#define MR_HAVE_SYSCONF 1
#define MR_HAVE_GETPAGESIZE 1
#define MR_HAVE_GETHOSTNAME 1
#define MR_HAVE_MMAP 1
#define MR_HAVE_MPROTECT 1
#define MR_HAVE_POSIX_MEMALIGN 1
#define MR_HAVE_SBRK 1
#define MR_HAVE_MEMMOVE 1
#define MR_HAVE_SIGACTION 1
#define MR_HAVE_SIGINTERRUPT 1
#define MR_HAVE_SETITIMER 1
#define MR_HAVE_SNPRINTF 1
#define MR_HAVE__SNPRINTF 1
#define MR_HAVE_VSNPRINTF 1
#define MR_HAVE__VSNPRINTF 1
#define MR_HAVE_STRERROR 1
#define MR_HAVE_STRERROR_R 1
#define MR_HAVE_OPEN 1
#define MR_HAVE_CLOSE 1
#define MR_HAVE_DUP 1
#define MR_HAVE_DUP2 1
#define MR_HAVE_FDOPEN 1
#define MR_HAVE_FILENO 1
#define MR_HAVE_FSTAT 1
#define MR_HAVE_STAT 1
#define MR_HAVE_LSTAT 1
#define MR_HAVE_ISATTY 1
#define MR_HAVE_GETPID 1
#define MR_HAVE_SETPGID 1
#define MR_HAVE_FORK 1
#define MR_HAVE_EXECLP 1
#define MR_HAVE_WAIT 1
#define MR_HAVE_KILL 1
#define MR_HAVE_GRANTPT 1
#define MR_HAVE_UNLOCKPT 1
#define MR_HAVE_PTSNAME 1
#define MR_HAVE_TCGETATTR 1
#define MR_HAVE_TCSETATTR 1
#define MR_HAVE_IOCTL 1
#define MR_HAVE_ACCESS 1
#define MR_HAVE_SLEEP 1
#define MR_HAVE_OPENDIR 1
#define MR_HAVE_READDIR 1
#define MR_HAVE_CLOSEDIR 1
#define MR_HAVE_MKDIR 1
#define MR_HAVE_SYMLINK 1
#define MR_HAVE_READLINK 1
#define MR_HAVE_GETTIMEOFDAY 1
#define MR_HAVE_SETENV 1
#define MR_HAVE_PUTENV 1
#define MR_HAVE__PUTENV 1
#define MR_HAVE_POSIX_SPAWN 1
#define MR_HAVE_SCHED_YIELD 1
#define MR_HAVE_MKSTEMP 1
#define MR_HAVE_SETRLIMIT 1
#define STDC_HEADERS 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UNISTD_H 1
#define MR_HAVE_UNISTD_H 1
#define MR_HAVE_SYS_WAIT_H 1
#define MR_HAVE_SYS_SIGINFO_H 1
#define MR_HAVE_SYS_SIGNAL_H 1
#define MR_HAVE_UCONTEXT_H 1
#define MR_HAVE_SYS_PARAM_H 1
#define MR_HAVE_SYS_TIME_H 1
#define MR_HAVE_SYS_TIMES_H 1
#define MR_HAVE_SYS_TYPES_H 1
#define MR_HAVE_SYS_STAT_H 1
#define MR_HAVE_FCNTL_H 1
#define MR_HAVE_TERMIOS_H 1
#define MR_HAVE_SYS_IOCTL_H 1
#define MR_HAVE_SYS_RESOURCE_H 1
#define MR_HAVE_DIRENT_H 1
#define MR_HAVE_GETOPT_H 1
#define MR_HAVE_MALLOC_H 1
#define MR_HAVE_SEMAPHORE_H 1
#define MR_HAVE_PTHREAD_H 1
#define MR_HAVE_TIME_H 1
#define MR_HAVE_SPAWN_H 1
#define MR_HAVE_FENV_H 1
#define MR_HAVE_SYS_MMAN_H 1
#define MR_HAVE_SYS_SEM_H 1
#define MR_HAVE_SCHED_H 1
#define MR_HAVE_UTMPX_H 1
#define MR_HAVE_FESETROUND 1
#define MR_SIGACTION_FIELD sa_sigaction
#define MR_HAVE_SIGINFO 1
#define MR_HAVE_SIGINFO_T 1
#define MR_HAVE_SIGINFO 1
#define MR_WORD_TYPE int
#define MR_INTEGER_LENGTH_MODIFIER ""
#define MR_INT_LEAST64_TYPE long long
#define MR_INT_LEAST64_LENGTH_MODIFIER "ll"
#define MR_INT_LEAST32_TYPE int
#define MR_INT_LEAST32_MAX INT_MAX
#define MR_UINT_LEAST32_MAX UINT_MAX
#define HAVE_DEV_T 1
#define HAVE_INO_T 1
#define MR_HAVE_DEV_T 1
#define MR_HAVE_INO_T 1
#define MR_INT_LEAST16_TYPE short
#define MR_INT_LEAST16_MAX SHRT_MAX
#define MR_UINT_LEAST16_MAX USHRT_MAX
#define MR_LOW_TAG_BITS 2
#define MR_BYTES_PER_WORD 4
#define MR_BITS_PER_WORD 32
#define MR_BOXED_FLOAT 1
#define MR_DOUBLE_IS_64_BIT 1
#define MR_LONG_DOUBLE_IS_64_BIT 1
#define MR_SYNC_TERM_SIZE 3
#define MR_BIG_ENDIAN 1
#define MR_HAVE_OCREAT_OEXCL 1
#define MR_CAN_DO_PENDING_IO 1
/* end confdefs.h.  */

    extern void     exit(int);
    void            *entry_foo_1;
    void            *entry_bar_1;
    void            *succip;
    int             global;
    void            *dummy_identity_function(void *);

    foo() {
printf("foo\n");
        entry_foo_1 = && foo_1;
        goto *dummy_identity_function(&&return_label);
    return_label:
printf("return foo\n");
        return;
    foo_1:
printf("foo_1\n");
        __asm__ __volatile__("":::"memory");
        if (global != 42) exit(1);
        goto *entry_bar_1;
    }
    bar() {
printf("bar\n");
        entry_bar_1 = && bar_1;
        goto *dummy_identity_function(&&return_label);
    return_label:
printf("return bar\n");
        return;
    bar_1:
printf("bar_1\n");
        __asm__ __volatile__("":::"memory");
        if (global != 42) exit(1);
        goto *succip;
    }
    main() {
        global = 42;
        foo();
        bar();
        succip = &&last;
        goto *dummy_identity_function(&&return_label);
    return_label:
printf("main_return\n");
        goto *entry_foo_1;
        exit(1);
    last:
printf("main_last\n");
        __asm__ __volatile__("":::"memory");
        if (global != 42) exit(1);
        exit(0);
    }
    void *dummy_identity_function(void *p) {
printf("dummy_id\n");
        return p;
    }

>Fix:
	Sorry, don't know.

>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/53346: gcc powerpc optimizer bug exposed by lang/mercury
Date: Wed, 6 Jun 2018 09:35:22 +0200

 Same test fails on gcc 6.4.0 in -current for various archs, but works 
 on amd64.

 Martin

Responsible-Changed-From-To: bin-bug-people->pkg-manager
Responsible-Changed-By: martin@NetBSD.org
Responsible-Changed-When: Wed, 06 Jun 2018 09:07:13 +0000
Responsible-Changed-Why:
Not a compiler issue


From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/53346 (The configure test for use of labels loops on powerpc)
Date: Wed, 6 Jun 2018 11:09:39 +0200

 The gcc manual says:

 "You may not use this mechanism to jump to code in a different function.
 If you do that, totally unpredictable things happen.  The best way to
 avoid this is to store the label address only in automatic variables and
 never pass it as an argument."


 So the configure test is completely broken (pointed out by Eric Botcatzu)

 Martin

From: Havard Eidnes <he@NetBSD.org>
To: gnats-bugs@NetBSD.org, martin@duskware.de
Cc: pkg-manager@netbsd.org, gnats-admin@netbsd.org, pkgsrc-bugs@netbsd.org
Subject: Re: pkg/53346 (The configure test for use of labels loops on
 powerpc)
Date: Wed, 06 Jun 2018 11:43:31 +0200 (CEST)

 >  The gcc manual says:
 >
 >  "You may not use this mechanism to jump to code in a different funct=
 ion.
 >  If you do that, totally unpredictable things happen.  The best way t=
 o
 >  avoid this is to store the label address only in automatic variables=
  and
 >  never pass it as an argument."
 >
 >
 >  So the configure test is completely broken (pointed out by Eric Botc=
 atzu)

 Thanks, good to know.  I'll report it to the mercury maintainers.

 Regards,

 - H=E5vard

State-Changed-From-To: open->feedback
State-Changed-By: maya@NetBSD.org
State-Changed-When: Tue, 19 Jun 2018 02:04:31 +0000
State-Changed-Why:
Upstream looks like they are intentionally using non local gotos. does the commit help enough?


From: "Maya Rashish" <maya@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53346 CVS commit: pkgsrc/lang/mercury
Date: Tue, 19 Jun 2018 02:04:05 +0000

 Module Name:	pkgsrc
 Committed By:	maya
 Date:		Tue Jun 19 02:04:05 UTC 2018

 Modified Files:
 	pkgsrc/lang/mercury: distinfo
 	pkgsrc/lang/mercury/patches: patch-at

 Log Message:
 mercury: disable non-local gotos on powerpc(32) too

 PR pkg/53346: The configure test for use of labels loops on powerpc


 To generate a diff of this commit:
 cvs rdiff -u -r1.18 -r1.19 pkgsrc/lang/mercury/distinfo
 cvs rdiff -u -r1.5 -r1.6 pkgsrc/lang/mercury/patches/patch-at

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

State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Thu, 17 Jun 2021 00:02:58 +0000
State-Changed-Why:
3-year feedback timeout


From: Havard Eidnes <he@NetBSD.org>
To: gnats-bugs@netbsd.org
Cc: dholland@NetBSD.org
Subject: Re: pkg/53346 (The configure test for use of labels loops on
 powerpc)
Date: Thu, 17 Jun 2021 14:39:18 +0200 (CEST)

 FYI:

 https://github.com/Mercury-Language/mercury/issues/95

 Regards,

 - H=E5vard

From: David Holland <dholland-pbugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/53346 (The configure test for use of labels loops on powerpc)
Date: Thu, 17 Jun 2021 16:48:46 +0000

 On Thu, Jun 17, 2021 at 12:40:01PM +0000, Havard Eidnes wrote:
  >  https://github.com/Mercury-Language/mercury/issues/95

 *facepalm*

 -- 
 David A. Holland
 dholland@netbsd.org

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.