public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Optimization of strcpy with an offset outside the string
@ 2001-12-03 18:44 Corey Minyard
  2001-12-03 19:49 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Corey Minyard @ 2001-12-03 18:44 UTC (permalink / raw)
  To: gcc

In the PowerPC Linux kernel, at some points in time the reference to 
some constant data is at an offset (because the MMU is not set up yet). 
 So you see expressions like:

   print("test" + offset);

where offset is far outside the bounds of the string.  This causes some 
very strange behaviour.  Basically, gcc emits code to subtract the 
offset varaible from the length of the string  to calculate the length 
to memcpy.  In builtins.c in the function c_strlen(), I find the comment:

      /* We don't know the starting offset, but we do know that the string
         has no internal zero bytes.  We can assume that the offset falls
         within the bounds of the string; otherwise, the programmer deserves
         what he gets.  Subtract the offset from the length of the string,
         and return that.  This would perhaps not be valid if we were 
dealing
         with named arrays in addition to literal string constants.  */

Should the programmer really lose in this case?  I can work around it in 
the kernel, but I thought I would point this out.

-Corey

BTW, My cable modem is now operational again, so you can mail me at acm.org.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Optimization of strcpy with an offset outside the string
  2001-12-03 18:44 Optimization of strcpy with an offset outside the string Corey Minyard
@ 2001-12-03 19:49 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2001-12-03 19:49 UTC (permalink / raw)
  To: Corey Minyard; +Cc: gcc

On Mon, Dec 03, 2001 at 08:45:26PM -0600, Corey Minyard wrote:
> In the PowerPC Linux kernel, at some points in time the reference to 
> some constant data is at an offset (because the MMU is not set up yet). 
> So you see expressions like:
> 
>   print("test" + offset);
> 
> where offset is far outside the bounds of the string.  This causes some 
> very strange behaviour.  Basically, gcc emits code to subtract the 
> offset varaible from the length of the string  to calculate the length 
> to memcpy.  In builtins.c in the function c_strlen(), I find the comment:
> 
>      /* We don't know the starting offset, but we do know that the string
>         has no internal zero bytes.  We can assume that the offset falls
>         within the bounds of the string; otherwise, the programmer deserves
>         what he gets.  Subtract the offset from the length of the string,
>         and return that.  This would perhaps not be valid if we were 
> dealing
>         with named arrays in addition to literal string constants.  */
> 
> Should the programmer really lose in this case?  I can work around it in 
> the kernel, but I thought I would point this out.
> 
> -Corey
> 
> BTW, My cable modem is now operational again, so you can mail me at acm.org.

Is this still in the current PPC kernels?

Franz raised this issue several months ago, and I believe the verdict
was that it was illegal.

I personally wouldn't mind a warning being generated, though!

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-12-04  3:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-03 18:44 Optimization of strcpy with an offset outside the string Corey Minyard
2001-12-03 19:49 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).