This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C undefined behavior fix
- From: Cameron Simpson <cs at zip dot com dot au>
- To: Tom Rini <trini at kernel dot crashing dot org>
- Cc: Momchil Velikov <velco at fadata dot bg>, linux-kernel at vger dot kernel dot org,gcc at gcc dot gnu dot org, linuxppc-dev at lists dot linuxppc dot org,Franz Sirl <Franz dot Sirl-kernel at lauterbach dot com>,Paul Mackerras <paulus at samba dot org>,Benjamin Herrenschmidt <benh at kernel dot crashing dot org>,Corey Minyard <minyard at acm dot org>
- Date: Thu, 3 Jan 2002 15:08:43 +1100
- Subject: Re: C undefined behavior fix
- References: <87g05py8qq.fsf@fadata.bg> <20020102190910.GG1803@cpe-24-221-152-185.az.sprintbbd.net>
- Reply-to: cs at zip dot com dot au
On Wed, Jan 02, 2002 at 12:09:10PM -0700, Tom Rini <trini@kernel.crashing.org> wrote:
| On Wed, Jan 02, 2002 at 01:03:25AM +0200, Momchil Velikov wrote:
| > The GCC tries to replace the strcpy from a constant string source with
| > a memcpy, since the length is know at compile time.
|
| Okay, here's a summary of all of the options we have:
| 1) Change this particular strcpy to a memcpy
| 2) Add -ffreestanding to the CFLAGS of arch/ppc/kernel/prom.o (If this
| optimization comes back on with this flag later on, it would be a
| compiler bug, yes?)
| 3) Modify the RELOC() marco in such a way that GCC won't attempt to
| optimize anything which touches it [1]. (Franz, again by Jakub)
| 4) Introduce a function to do the calculations [2]. (Corey Minyard)
| 5) 'Properly' set things up so that we don't need the RELOC() macros
| (-mrelocatable or so?), and forget this mess altogether.
Dudes, maybe I'm missing something here, but why don't you just mark the
source data as volatile? Then it _can't_ assume it knows the length of
the strcpy because it can't assume it knows the content:
If PTRRELOC cast the pointer type to
volatile void *
or something else suitable generic but volatile then this discussion might
not be happening. It would at least move the optimisation into "definite
compiler bug" if it still happens.
--
Cameron Simpson, DoD#743 cs@zip.com.au http://www.zip.com.au/~cs/
I think... Therefore I ride. I ride... Therefore I am.
- Mark Pope <erectus@yarrow.wt.uwa.edu.au>