Re: const versus __attribute__((const))

From: Linus Torvalds
Date: Tue Dec 09 2003 - 02:28:17 EST




On Mon, 8 Dec 2003, H. Peter Anvin wrote:
>
> Sure it will:

No, Jamie was thinking of a variable that _already_ has a memory location
having its value copied around to _another_ memory location (ie a
temporary stack slot).

What your example shows is that gcc will create a stack slot for an
automatic variable if it doesn't have one already, in order to make it an
lvalue with a memory address.

So what's interesting is if gcc would take something like

extern int variable;

asm("..." : :"m" (variable));

and cause this to create a _new_ temporary on the stack slot, and pass the
asm the pointer to that temporary rather than the "real" address of
'variable'.

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.

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.

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/