public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* making aliases into the middle of a structure
@ 1999-04-22 11:13 Zack Weinberg
  1999-04-22 11:25 ` Alexandre Oliva
  1999-04-30 23:15 ` Zack Weinberg
  0 siblings, 2 replies; 36+ messages in thread
From: Zack Weinberg @ 1999-04-22 11:13 UTC (permalink / raw)
  To: egcs

Consider this bit of code.

struct s
{
  int a, b;
};

struct s x = { 0, 0 };

extern __typeof(x.b) y __attribute__ ((alias("x.b")));

The goal is to have x.b and y refer to the same memory location.  I am
aware that this is somewhat perverse, but there are legitimate reasons
(binary compatibility) for it.

If gcc were to translate this into

.data
.globl x
        .align 4
        .type    x,@object
        .size    x,8
x:
        .zero   8
.globl y
        .set    y, x+4

then the assembler would generate a correct object module, and
references to `x.b' and `y' would indeed operate on the same memory
location.

Unfortunately this is not what gcc produces; instead I get

.data
.globl x
        .align 4
        .type    x,@object
        .size    x,8
x:
        .zero   8
.globl y
        .set    y,x.b


The assembler generates an undefined reference to the symbol `x.b' and
forgets about `y'.

I have experimented with workarounds involving offsetof();
unfortunately, the best this can do is

	.set y,x + ((size_t) &((s *)0)->b)

which is not an expression that the assembler can evaluate.  I do not
want to write a raw assembly module, because that will break if the
padding inside the structure, or the sizes of the component types,
change.

Any suggestions?

zw

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

end of thread, other threads:[~1999-04-30 23:15 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-22 11:13 making aliases into the middle of a structure Zack Weinberg
1999-04-22 11:25 ` Alexandre Oliva
1999-04-22 11:30   ` Zack Weinberg
1999-04-22 11:38     ` Alexandre Oliva
1999-04-22 14:31       ` Zack Weinberg
1999-04-23 15:24         ` Richard Henderson
1999-04-23 16:27           ` Zack Weinberg
1999-04-23 16:52             ` Richard Henderson
1999-04-30 23:15               ` Richard Henderson
1999-04-30 23:15             ` Zack Weinberg
1999-04-30 23:15           ` Richard Henderson
1999-04-30 23:15         ` Zack Weinberg
1999-04-23 10:34       ` Jeffrey A Law
1999-04-23 10:40         ` Zack Weinberg
1999-04-23 15:54           ` Richard Henderson
1999-04-23 16:19             ` Zack Weinberg
1999-04-26  1:46               ` Andreas Schwab
1999-04-30 23:15                 ` Andreas Schwab
1999-04-30 23:15               ` Zack Weinberg
1999-04-30 23:15             ` Richard Henderson
1999-04-30 23:15           ` Zack Weinberg
1999-04-23 13:36         ` Jamie Lokier
1999-04-23 13:49           ` Zack Weinberg
1999-04-23 15:20             ` Jamie Lokier
1999-04-30 23:15               ` Jamie Lokier
1999-04-23 22:58             ` Andi Kleen
1999-04-30 23:15               ` Andi Kleen
1999-04-30 23:15             ` Zack Weinberg
1999-04-24 21:53           ` Jeffrey A Law
1999-04-30 23:15             ` Jeffrey A Law
1999-04-30 23:15           ` Jamie Lokier
1999-04-30 23:15         ` Jeffrey A Law
1999-04-30 23:15       ` Alexandre Oliva
1999-04-30 23:15     ` Zack Weinberg
1999-04-30 23:15   ` Alexandre Oliva
1999-04-30 23:15 ` Zack Weinberg

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).