linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Jamie Lokier <jamie@shareable.org>,
	Nikita Danilov <Nikita@Namesys.COM>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org
Subject: Re: const versus __attribute__((const))
Date: Mon, 08 Dec 2003 23:40:39 -0800	[thread overview]
Message-ID: <3FD57C77.4000403@zytor.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0312082321470.18255@home.osdl.org>

Linus Torvalds wrote:
> 
> And as far as I know, it won't. Newer gcc's will _require_ memory
> arguments to be lvalues (well, it will warn if they aren't), and will
> always turn them into addressables of that particular lvalue.
> 

Well, I get no warning from the following code, with gcc 3.2.2 and -W -Wall:

int foo(int x)
{
   int y, z, w;

   asm("movl %1,%0" : "=r" (y) : "r" (x));
   asm("movl %1,%0" : "=r" (z) : "m" (y+1));
   asm("movl %1,%0" : "=r" (w) : "m" (33));

   return z+w;
}

The memory operand is definitely not an lvalue.  gcc allocates a stack slot
for the y+1 value as a temporary automatic and passes it in.  The value 33
is put in the .rodata segment:

00000000 <foo>:
    0:   55                      push   %ebp
    1:   89 e5                   mov    %esp,%ebp
    3:   50                      push   %eax
    4:   8b 45 08                mov    0x8(%ebp),%eax
    7:   89 c0                   mov    %eax,%eax
    9:   40                      inc    %eax
    a:   89 45 fc                mov    %eax,0xfffffffc(%ebp)
    d:   8b 15 00 00 00 00       mov    0x0,%edx
                         f: R_386_32     .rodata.cst4
   13:   8b 45 fc                mov    0xfffffffc(%ebp),%eax
   16:   01 d0                   add    %edx,%eax
   18:   c9                      leave
   19:   c3                      ret

> This is actually an issue, because some asm code depends on getting the
> proper address - not just the proper value. Things like locks etc care
> _deeply_ about more than just the value.

That would be a very bad thing indeed.  Fortunately I think it would take
some rather odd contortions on the part of the compiler for that situation
to occur at all, I would think, and if the gcc people have since been
made aware of it it should be pretty easy for them to make sure it will not
happen.

	-hpa


  reply	other threads:[~2003-12-09  7:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-08 15:46 const versus __attribute__((const)) Arnd Bergmann
2003-12-08 17:50 ` H. Peter Anvin
2003-12-08 18:27   ` Nikita Danilov
2003-12-08 18:31     ` H. Peter Anvin
2003-12-09  2:59       ` Jamie Lokier
2003-12-09  3:21         ` H. Peter Anvin
2003-12-09  3:49           ` Jamie Lokier
2003-12-09  5:37             ` H. Peter Anvin
2003-12-09  7:26               ` Linus Torvalds
2003-12-09  7:40                 ` H. Peter Anvin [this message]
2003-12-09 11:56                   ` Arnd Bergmann
2003-12-09 15:42                     ` H. Peter Anvin
2003-12-09 16:44                       ` Linus Torvalds
2003-12-09 16:51                         ` H. Peter Anvin
2003-12-09 19:15                           ` Jamie Lokier
2003-12-09  7:19             ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2003-12-08  1:19 H. Peter Anvin
2003-12-08 12:32 ` Nikita Danilov

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=3FD57C77.4000403@zytor.com \
    --to=hpa@zytor.com \
    --cc=Nikita@Namesys.COM \
    --cc=arnd@arndb.de \
    --cc=jamie@shareable.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.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 NNTP newsgroup(s).