From owner-freebsd-bugs Wed Jun 14 2:40: 8 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id BD19437BF18 for ; Wed, 14 Jun 2000 02:40:05 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id CAA76259; Wed, 14 Jun 2000 02:40:05 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Wed, 14 Jun 2000 02:40:05 -0700 (PDT) Message-Id: <200006140940.CAA76259@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Bruce Evans Subject: Re: i386/19245: -fexpensive-optimizations buggy (even with -O) Reply-To: Bruce Evans Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR i386/19245; it has been noted by GNATS. From: Bruce Evans To: mi@aldan.algebra.com Cc: FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: i386/19245: -fexpensive-optimizations buggy (even with -O) Date: Wed, 14 Jun 2000 19:37:28 +1000 (EST) On Tue, 13 Jun 2000, Mikhail Teterin wrote: > >Description: > > The attached piece of code, when compiled with > ``-O -fexpensive-optimizations'', produces incorrect > binary on FreeBSD-4.0 . > > I tested the same compiler line on Mandrake Linux (an > identical machine hardware-wise) and it compiles correctly. This is hard to explain, since the bug shown by your example is in gcc (2.95.2), not in the assembler or linker. > static off_t > rfc1035QuestionPack(char *buf, > size_t sz, > const char *hostname, > unsigned short class > ) > { > off_t off = 0; > unsigned short s; > printf("In rfc1035QuestionPack: hostname is %p (%s)\n", > hostname, hostname); > s = htons(class); > memcpy(buf + off, &s, sizeof(s)); > off += sizeof(s); > assert(off <= sz); > return off; > } gcc -O -fexpensive-optimizations reuses the stack space for `hostname' and `class', and zeros this space to initialize `off' before loading `hostname' or `class'. > Yet, with the -fexpensive-optimizations flag, the hostname > argument is passed in the register, which, apparently, is > sometimes not loaded with the value and remains zero, resulting > in: No, -fexpensive-optimizations doesn't affect the function call protocol. Args are still passed on the stack. > >Fix: > Get the new assembler/binutils and add -fno-expensive-optimizations > to all CFLAGS in the meantime. Anything else? Don't use -O2 (which enables -fexpensive-optimizations) unless you want to find bugs like this :-). Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message