NetBSD Problem Report #45439

From hf@spg.tu-darmstadt.de  Fri Oct  7 13:24:50 2011
Return-Path: <hf@spg.tu-darmstadt.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 3215063BA16
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  7 Oct 2011 13:24:50 +0000 (UTC)
Message-Id: <201110071324.p97DOd5j028278@Gstoder.nt.e-technik.tu-darmstadt.de>
Date: Fri, 7 Oct 2011 15:24:39 +0200 (CEST)
From: Hauke Fath <hf@Espresso.Rhein-Neckar.DE>
Reply-To: Hauke Fath <hf@Espresso.Rhein-Neckar.DE>
To: gnats-bugs@gnats.NetBSD.org
Cc: Hauke Fath <hf@Espresso.Rhein-Neckar.DE>
Subject: gcc generates out-of-range branch insn for m68k
X-Send-Pr-Version: 3.95

>Number:         45439
>Category:       toolchain
>Synopsis:       gcc generates out-of-range branch insn for m68k
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          feedback
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 07 13:25:00 +0000 2011
>Closed-Date:    
>Last-Modified:  Thu Sep 20 22:08:18 +0000 2012
>Originator:     Hauke Fath
>Release:        NetBSD 5.1_STABLE
>Organization:
-- 
     The ASCII Ribbon Campaign                    Hauke Fath
()     No HTML/RTF in email	        Institut für Nachrichtentechnik
/\     No Word docs in email                     TU Darmstadt
     Respect for open standards              Ruf +49-6151-16-3281
>Environment:


System: NetBSD fattie.causeuse.org 5.1_STABLE NetBSD 5.1_STABLE (Q650) #0: Thu Apr 21 16:03:44 CEST 2011  hauke@fattie.causeuse.org:/bsdsrc/netbsd-5/src/sys/arch/mac68k/compile/Q650 mac68k
Architecture: m68k
Machine: mac68k
>Description:

	During the build of perl 5.14.[12] (pkgsrc lang/perl5), the
	gcc 4.1.3 on NetBSD/m68k generates an out-of-range FPU
	assembler branch instruction:

[...]
Making all in ext/re
 /usr/bin/make all PERL_CORE=1 LIBPERL_A=libperl.so LINKTYPE=dynamic
cp re.pm ../../lib/re.pm
rm -f re_exec.c
cp ../../regexec.c re_exec.c
cc -c    -O2 -pthread -I/usr/include -fno-strict-aliasing -pipe -fstack-protector -I/usr/pkg/include -O2 -pthread -I/usr/include    -DVERSION=\"0.18\"  -DXS_VERSION=\"0.18\" -DPIC -fPIC "-I../.."  -DPERL_EXT_RE_BUILD -DPERL_EXT_RE_DEBUG -DPERL_EXT re_exec.c
{standard input}: Assembler messages:
{standard input}:18033: Error: value out of range
*** Error code 1Unsuccessful make(ext/re): code=256 at make_ext.pl line 463.

Stop.
make: stopped in /var/obj/pkgsrc/lang/perl5/work/perl-5.14.2/ext/re
*** Error code 25*** Error code 1

	The relevant assembler procedure is
[...]
   8485 .L3744:
   8486         move.l PL_memory_wrap@GOT(%a5),-(%sp)
   8487         move.l .LC68@GOT(%a5),-(%sp)
   8488         bsr.l Perl_croak_nocontext@PLTPC
[...]
  18029 .L2762:
  18030         fmovecr #0xf,%fp1
  18031         fadd.x %fp1,%fp0
  18032         fcmp.d #0r1.073741823e+9,%fp0
>>18033         fbgt .L3744
  18034         lsl.l #2,%d0
  18035         move.l %d0,-(%sp)
  18036         bsr.l Perl_safesysmalloc@PLTPC
  18037         move.l %a0,588(%a4)
  18038         clr.l -260(%fp)
  18039         clr.l (%sp)
  18040         move.l %a4,-(%sp)
  18041         bsr.l S_regcppush@PLTPC
  18042         move.l %d5,%a0
  18043         move.l %d0,28(%a0)
  18044         move.l -36(%fp),%d0
  18045         addq.l #8,%sp
  18046         btst #19,%d0
  18047         jbeq .L2765
  18048         jbra .L3880
[...]

	with L3744 being (too) pretty far away in the source code.

	See also
	<http://mail-index.netbsd.org/port-m68k/2011/09/oindex.html>.


	Files provided: 

	ext/re/re_exec.s is at
	<http://la.causeuse.org/hauke/NetBSD/gcc-m68k-perl/re_exec.s.gz>,
	built with

% cc -S -O2 -pthread -I/usr/include -fno-strict-aliasing -pipe -fstack-protector -I/usr/include -DVERSION=\"0.18\" -DXS_VERSION=\"0.18\" -DPIC -fPIC "-I../.." -DPERL_EXT_RE_BUILD -DPERL_EXT_RE_DEBUG -DPERL_EXT re_exec.c
%

	ext/re/verbose-re_exec.s (different line numbers) is at
	<http://la.causeuse.org/hauke/NetBSD/gcc-m68k-perl/verbose-re_exec.s.gz>,
	built with

% cc -S -fverbose-asm -O2 -pthread -I/usr/include -fno-strict-aliasing -pipe -fstack-protector -I/usr/include -DVERSION=\"0.18\" -DXS_VERSION=\"0.18\" -DPIC -fPIC "-I../.." -DPERL_EXT_RE_BUILD -DPERL_EXT_RE_DEBUG -DPERL_EXT re_exec.c
%

	ext/re/re_exec.i (preprocessor output) is at
	<http://la.causeuse.org/hauke/NetBSD/gcc-m68k-perl/re_exec.i.gz>,
	built with

% cc -E -O2 -pthread -I/usr/include -fno-strict-aliasing -pipe -fstack-protector -I/usr/include -DVERSION=\"0.18\" -DXS_VERSION=\"0.18\" -DPIC -fPIC "-I../.." -DPERL_EXT_RE_BUILD -DPERL_EXT_RE_DEBUG -DPERL_EXT re_exec.c > re_exec.i
%

	The problem can be reproduced by compiling the preprocessed file.


>How-To-Repeat:

	Build lang/perl5 on a netbsd-5 m68k machine. I don't know
	about -current, but m68k still defaults to gcc 4.1.3 because
	of gcc 4.5 m68k breakage.


>Fix:

	Fix gcc m68k code generation. A workaround appears to build
	with -Os instead of the default	-O2.

>Release-Note:

>Audit-Trail:
From: David Laight <david@l8s.co.uk>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: toolchain/45439: gcc generates out-of-range branch insn for m68k
Date: Fri, 7 Oct 2011 19:17:23 +0100

 Possibly this is an assembler bug.
 The 68k coprocesser conditional branches can have either a 16bit
 or 32bit signed offset.

 The compiler could add an explicit .l suffix, but I don't expect
 that it expects to - and probably doesn't for non-coprocessor
 branches.

 	David

 -- 
 David Laight: david@l8s.co.uk

From: Hauke Fath <hauke@Espresso.Rhein-Neckar.DE>
To: gnats-bugs@NetBSD.org
Cc: toolchain-manager@NetBSD.org, gnats-admin@NetBSD.org
Subject: Re: toolchain/45439: gcc generates out-of-range branch insn for
 m68k
Date: Fri, 7 Oct 2011 21:18:52 +0200

 At 18:20 Uhr +0000 7.10.2011, David Laight wrote:
 > Possibly this is an assembler bug.
 > The 68k coprocesser conditional branches can have either a 16bit
 > or 32bit signed offset.
 >
 > The compiler could add an explicit .l suffix, but I don't expect
 > that it expects to - and probably doesn't for non-coprocessor
 > branches.

 The as(1) info documentation has a paragraph about the magic it works to
 pick the proper displacement for branch insns, to the point where it will
 insert a jmp for a bra if needs be. The corresponding paragraph on fpu
 branches is way shorter:

      Each of these pseudo-operations always expands to a single Motorola
      coprocessor branch instruction, word or long.  All Motorola
      coprocessor branch instructions allow both word and long
      displacements.

 So gcc grew to expect a smart assembler, and gas is dragging its feet?

 	hauke

 --
 "It's never straight up and down"     (DEVO)


From: "Hauke Fath" <hauke@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/45439 CVS commit: pkgsrc/lang/perl5
Date: Tue, 11 Oct 2011 10:02:14 +0000

 Module Name:	pkgsrc
 Committed By:	hauke
 Date:		Tue Oct 11 10:02:14 UTC 2011

 Modified Files:
 	pkgsrc/lang/perl5: hacks.mk

 Log Message:
 On m68k, gcc creates short assembler branch insns, and expects the
 assembler to adapt them to the distance. m68k gas appears not to do
 that for fpu branch insns, resulting in an out-of-range FPU assembler
 branch instruction error in "ext/re/re_exec.c".

 As a workaround, building with "-Os" instead of "-O2" reduces the size
 of the object file enough to allow short branches.

 See PR toolchain/45439.


 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 pkgsrc/lang/perl5/hacks.mk

 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: Thu, 20 Sep 2012 22:08:18 +0000
State-Changed-Why:
does this still happen with netbsd-6?


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.