Subject: pkg/15889: i386 cpp and cpp in cross/powerpc-netbsd use __GNUC__ differently
To: None <gnats-bugs@gnats.netbsd.org>
From: None <klaus.heinz@onlinehome.de>
List: netbsd-bugs
Date: 03/13/2002 03:39:04
>Number:         15889
>Category:       pkg
>Synopsis:       i386 cpp and cpp in cross/powerpc-netbsd use __GNUC__ differently
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 12 19:41:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Klaus Heinz
>Release:        NetBSD 1.5.2
>Organization:
none
>Environment:
System: NetBSD silence.homedns.org 1.5.2 NetBSD 1.5.2 (GENERIC) #3: Sat Aug 18 23:37:05 CEST 2001 he@hamster.urc.uninett.no:/usr/src/sys/arch/i386/compile/GENERIC i386


>Description:
	I am trying to cross-build with the compiler package
	cross/powerpc-netbsd (i386 -> powerpc). The build fails in bin/ksh
	with the following error (ppc-make is a shell script setting various
	variables, attached at the end of this description):

	  $ ppc-make build
	  ...
	  dependall ===> bin/ksh
	  sh /var/tmp2/src-1.5.2/bin/ksh/emacs-gen.sh /var/tmp2/src-1.5.2/bin/ksh/emacs.c > tmpemacs.out
	  mv tmpemacs.out emacs.out
	  sh /var/tmp2/src-1.5.2/bin/ksh/siglist.sh "/usr/pkg/cross/lib/gcc-lib/powerpc-netbsd/egcs-2.91.60/cpp  -DHAVE_CONFIG_H -I. -nostdinc -idirafter /a/root/usr/include  -I. -I/var/tmp2/src-1.5.2/bin/ksh" < /var/tmp2/src-1.5.2/bin/ksh/siglist.in > tmpsiglist.out
5A
	  In file included from /a/root/usr/include/powerpc/types.h:37,
	                 from /a/root/usr/include/machine/types.h:3,
	                 from /a/root/usr/include/sys/types.h:47,
	                 from /a/root/usr/include/stdio.h:45,
	                 from /var/tmp2/src-1.5.2/bin/ksh/sh.h:20,
	                 from tmpi1361.c:1:
	  /a/root/usr/include/sys/cdefs.h:190: #error "No function renaming possible"
	  *** Error code 1

	  Stop.
	  *** Error code 1

	  Stop.
	  *** Error code 1

	  Stop.
	  *** Error code 1

	  Stop.


	Line 190 in cdefs.h gets triggered when __GNUC__ is _not_ defined.
	I can verify this by:

	  $ /usr/pkg/cross/lib/gcc-lib/powerpc-netbsd/egcs-2.91.60/cpp -v       
	  GNU CPP version egcs-2.91.60 19981201 (egcs-1.1.1 release) (PowerPC System V.4)
	  $ /usr/pkg/cross/lib/gcc-lib/powerpc-netbsd/egcs-2.91.60/cpp -dM </dev /null
	  #define __NetBSD__ 1 
	  #define __KPRINTF_ATTRIBUTE__ 1 
	  #define __ELF__ 1 
	  #define __powerpc__ 1 
	  $ /usr/pkg/cross/bin/powerpc-netbsd-cc -E -dM foo.c
	  #define __NetBSD__ 1 
	  #define __KPRINTF_ATTRIBUTE__ 1 
	  #define __GNUC_MINOR__ 91 
	  #define __CHAR_UNSIGNED__ 1 
	  #define __GNUC__ 2 
	  #define _CALL_SYSV 1 
	  #define __ELF__ 1 
	  #define __powerpc__ 1 


        With the native cpp on i386 (admittedly with a different version) I get:

	  $ /usr/bin/cpp -v
	  GNU CPP version egcs-2.91.66 19990314 (egcs-1.1.2 release) (80386, BSD syntax)
	  $ /usr/bin/cpp -dM </dev/null
	  #define __NetBSD__ 1
	  #define __KPRINTF_ATTRIBUTE__ 1
	  #define i386 1
	  #define __GNUC__ 1
	  #define __ELF__ 1
	  $ /usr/bin/cc -E -dM foo.c
	  #define __i386__ 1 
	  #define __NetBSD__ 1 
	  #define __i386 1 
	  #define __KPRINTF_ATTRIBUTE__ 1 
	  #define __GNUC_MINOR__ 91 
	  #define i386 1 
	  #define __GNUC__ 2 
	  #define __ELF__ 1 


	According to cpp.info

          This macro is defined only when the entire GNU C compiler is in use;
	  if you invoke the preprocessor directly, `__GNUC__' is undefined.

	the cross-compiler does the right thing by omitting __GNUC__ with cpp
	and defining it as '2' with cc, but on i386 (and the source code seems
	to expect this behaviour, see usage of cpp before the error message
	in bin/ksh above) cpp _does_ define __GNUC__ (as '1') when used
	standalone and cc defines as '2'.

	I don't know whether cpp.info, cpp/cc in pkgsrc/cross/powerpc-netbsd or 
	cpp/cc on i386 is wrong, but there seems to be an incosistency.

	Contents of ppc-make:
	
	  #! /bin/sh
	  DESTDIR=/a/root export DESTDIR
	  MACHINE=bebox export MACHINE
	  MACHINE_ARCH=powerpc export MACHINE_ARCH
	  WHICH=powerpc-netbsd

	  LOCAL=/usr/pkg
	  BINDIR=$LOCAL/cross/bin
	  PATH=$PATH:$BINDIR:$LOCAL/cross/$WHICH/bin:$PATH:$LOCAL/cross/bin export PATH

	  GCC_EXEC_PREFIX=$WHICH

	  AR=$BINDIR/$WHICH-ar export AR
	  AS=$BINDIR/$WHICH-as export AS
	  CC=$BINDIR/$WHICH-gcc export CC
	  CPP=`$CC -print-prog-name=cpp` export CPP
	  CXX=$BINDIR/$WHICH-c++ export CXX
	  FC=$BINDIR/$WHICH-f77 export FC
	  LD=$BINDIR/$WHICH-ld export LD
	  NM=$BINDIR/$WHICH-nm export NM
	  RANLIB=$BINDIR/$WHICH-ranlib export RANLIB
	  SIZE=$BINDIR/$WHICH-size export SIZE
	  ADDR2LINE=$BINDIR/$WHICH-addr2line export ADDR2LINE
	  GASP=$BINDIR/$WHICH-gasp export GASP
	  OBJCOPY=$BINDIR/$WHICH-objcopy export OBJCOPY
	  OBJDUMP=$BINDIR/$WHICH-objdump export OBJDUMP
	  STRINGS=$BINDIR/$WHICH-strings export STRINGS
	  STRIP=$BINDIR/$WHICH-strip export STRIP

	  MKPROFILE=no export MKPROFILE
	  #MKMAN=no export MKMAN
	  MKLINT=no export MKLINT

	  HOSTED_CC=cc export HOSTED_CC

	  MAKE=make export MAKE
	  #MAKE="make -f ${DESTDIR}/usr/share/mk/sys.mk -f Makefile"; export MAKE
	  #MAKEFLAGS="-I ${DESTDIR}/usr/share/mk" ; export MAKEFLAGS

	  set -x
	  exec $MAKE "$@"

>How-To-Repeat:
	
	$ cd /usr/pkgsrc/cross/powerpc-netbsd/
	$ make install
	$ cd /usr/src/
	$ ppc-make build

>Fix:
	none known yet
>Release-Note:
>Audit-Trail:
>Unformatted: