Subject: bin/6418: gcc workarounds broken with egcs
To: None <gnats-bugs@gnats.netbsd.org>
From: Hubert Feyrer <feyrer@rfhs8012.fh-regensburg.de>
List: netbsd-bugs
Date: 11/10/1998 00:53:10
>Number:         6418
>Category:       bin
>Synopsis:       gcc workarounds broken with egcs
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov  9 16:05:01 1998
>Last-Modified:
>Originator:     Hubert Feyrer
>Organization:
-- 
Hubert Feyrer <hubert.feyrer@rz.uni-regensburg.de>
>Release:        ~October 1998
>Environment:
	
System: NetBSD miyu 1.3H NetBSD 1.3H (MIYU) #33: Wed Oct 28 03:12:37 MET 1998 feyrer@miyu:/data/cvs/src/sys/arch/i386/compile/MIYU i386


>Description:
	It seems egcs doesn't deal well with some gcc-workarounds in
	our code. I've stumbled about a non-working ftp that was compiled
	with egcs. As it seems, the following were the offending lines:

	#ifdef __GNUC__                 /* to shut up gcc warnings */
        	(void)&outfile;
	#endif

	Egcs sets the given variable to 0, which is fatal for any variables
	initialized at that point, at lesat any function parameters (like the
	above). Using the following instead worked fine for me:

	#if defined(__GNUC__) && (__GNUC__ <= 2) && (__GNUC_MINOR__ < 10)
        	...
	#endif

	Beware, the same &(void)xxx construct seems to be used to work
	around some longjmp clobbering. (But maybe it shows up only there?)

	This is on i386 with egcs:
	miyu% uname -a
	NetBSD miyu 1.3H NetBSD 1.3H (MIYU) #33: Wed Oct 28 03:12:37 MET 1998     feyrer@miyu:/data/cvs/src/sys/arch/i386/compile/MIYU i386
	miyu% gcc -v
	Using builtin specs.
	gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

	This doesn't seem to be triggered on non-egcs systems, or on
	sparc and sharc with egcs. Some longjmp involvement may be 
	needed to show this bug (which is present in ftp).


>How-To-Repeat:
	ftp -o foo http://www.netbsd.org/index.html
	look if you have either "foo" or "index.html"
	if "foo" your system's fine
	if "index.html", things are broken for you.

	use gdb, set a breakpoint at usr.bin/ftp/fetch.c:723
	(rev. 1.36), run with the above arguments and detect that the
	outfile variable is nil when the breakpoint is reached.

>Fix:
	If someone wants to fix this, the following perl line does this for
	any files given (*):

perl -i.BAK -pe 's/def.*__GNUC__/ defined(__GNUC__) && (__GNUC__ <= 2) && (__GNUC_MINOR__ < 10)/ if /#.*ifdef.*__GNUC__/;' *

	Files which have "#if.*__GNUCC__\n&.*(void)" in them are:
		src/bin/ed/main.c
		src/bin/ed/main.c
		src/bin/ls/ls.c
		src/bin/pax/buf_subs.c
		src/bin/pax/buf_subs.c
		src/bin/pax/buf_subs.c
		src/bin/pax/file_subs.c
		src/bin/pax/gen_subs.c
		src/bin/rcp/rcp.c
		src/bin/rcp/rcp.c
		src/bin/sh/eval.c
		src/bin/sh/histedit.c
		src/bin/sh/parser.c
		src/bin/sh/parser.c
		src/bin/sh/var.c
		src/bin/ksh/c_ulimit.c
		src/bin/ksh/exec.c
		src/bin/ksh/lex.c
		src/usr.sbin/cron/do_command.c
		src/usr.sbin/cron/do_command.c
		src/usr.sbin/cron/do_command.c
		src/usr.sbin/cron/popen.c
		src/usr.sbin/gspa/gspa/gspa.c
		src/usr.sbin/gspa/gspa/gspa.c
		src/usr.sbin/sup/source/supscan.c
		src/usr.sbin/tcpdchk/tcpdchk.c
		src/usr.sbin/xntp/ntptime/ntptime.c
		src/games/phantasia/fight.c
		src/games/phantasia/io.c
		src/gnu/lib/libg++/libstdc++/stl/tree.h
		src/gnu/libexec/uucp/libunix/serial.c
		src/lib/libutil/passwd.c
		src/lib/libc/gen/popen.c
		src/lib/libc/stdio/fseek.c
		src/lib/libc/stdlib/strtoq.c
		src/lib/libc/stdlib/strtouq.c
		src/lib/libwrap/rfc931.c
		src/lib/libwrap/rfc931.c
		src/libexec/ftpd/ftpd.c
		src/libexec/ftpd/ftpd.c
		src/libexec/ftpd/ftpd.c
		src/libexec/ftpd/popen.c
		src/libexec/ftpd/popen.c
		src/libexec/getty/main.c
		src/sbin/mount/mount.c
		src/sbin/mount/mount.c
		src/sbin/newfs/mkfs.c
		src/sbin/restore/tape.c
		src/sbin/restore/tape.c
		src/sbin/savecore/savecore.c
		src/sbin/fsck/fsck.c
		src/sbin/fsirand/fsirand.c
		src/sys/arch/hp300/hp300/machdep.c
		src/sys/arch/mac68k/mac68k/machdep.c
		src/sys/arch/next68k/next68k/machdep.c
		src/usr.bin/ftp/fetch.c
		src/usr.bin/ftp/fetch.c
		src/usr.bin/ftp/fetch.c
		src/usr.bin/ftp/ftp.c
		src/usr.bin/ftp/ftp.c
		src/usr.bin/ftp/ftp.c
		src/usr.bin/ftp/ftp.c
		src/usr.bin/ftp/ftp.c
		src/usr.bin/ftp/ftp.c
		src/usr.bin/ftp/main.c
		src/usr.bin/ftp/main.c
		src/usr.bin/ftp/x
		src/usr.bin/ftp/x
		src/usr.bin/ftp/fetch.c.BAK
		src/usr.bin/ftp/fetch.c.BAK
		src/usr.bin/ftp/fetch.c.BAK
		src/usr.bin/ftp/ftp.c.BAK
		src/usr.bin/ftp/ftp.c.BAK
		src/usr.bin/ftp/ftp.c.BAK
		src/usr.bin/ftp/ftp.c.BAK
		src/usr.bin/ftp/ftp.c.BAK
		src/usr.bin/ftp/ftp.c.BAK
		src/usr.bin/ftp/main.c.BAK
		src/usr.bin/ftp/main.c.BAK
		src/usr.bin/gprof/dfn.c
		src/usr.bin/gprof/printgprof.c
		src/usr.bin/gprof/printgprof.c
		src/usr.bin/mail/cmd1.c
		src/usr.bin/mail/collect.c
		src/usr.bin/mail/lex.c
		src/usr.bin/mail/tty.c
		src/usr.bin/make/compat.c
		src/usr.bin/make/compat.c
		src/usr.bin/make/parse.c
		src/usr.bin/make/parse.c
		src/usr.bin/rdist/docmd.c
		src/usr.bin/rdist/docmd.c
		src/usr.bin/telnet/commands.c
		src/usr.bin/telnet/commands.c
		src/usr.bin/telnet/main.c
		src/usr.bin/time/time.c
		src/usr.bin/tip/aculib/biz22.c
		src/usr.bin/tip/aculib/courier.c
		src/usr.bin/tip/aculib/courier.c
		src/usr.bin/tip/aculib/courier.c
		src/usr.bin/tip/aculib/df.c
		src/usr.bin/tip/aculib/hayes.c
		src/usr.bin/tip/aculib/t3000.c
		src/usr.bin/tip/aculib/t3000.c
		src/usr.bin/tip/aculib/t3000.c
		src/usr.bin/tip/aculib/v3451.c
		src/usr.bin/tip/aculib/v3451.c
		src/usr.bin/tip/aculib/ventel.c
		src/usr.bin/tip/acu.c
		src/usr.bin/tip/acu.c
		src/usr.bin/tip/cmds.c
		src/usr.bin/tip/tip.c
		src/usr.bin/window/wwspawn.c
		src/domestic/usr.bin/telnet/commands.c
		src/domestic/usr.bin/telnet/commands.c
		src/domestic/usr.bin/telnet/main.c

>Audit-Trail:
>Unformatted: