public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Corey Minyard <minyard@acm.org>
To: gcc@gcc.gnu.org
Subject: Optimization of strcpy with an offset outside the string
Date: Mon, 03 Dec 2001 18:44:00 -0000	[thread overview]
Message-ID: <3C0C38C6.6090306@acm.org> (raw)

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.

             reply	other threads:[~2001-12-04  2:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-03 18:44 Corey Minyard [this message]
2001-12-03 19:49 ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3C0C38C6.6090306@acm.org \
    --to=minyard@acm.org \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).