public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RFC: attribute "unpadded"
@ 2002-08-23 10:43 Mark Mitchell
  2002-08-23 10:49 ` Andrew Haley
                   ` (4 more replies)
  0 siblings, 5 replies; 61+ messages in thread
From: Mark Mitchell @ 2002-08-23 10:43 UTC (permalink / raw)
  To: gcc

I want to create a new type attribute "unpadded" that would, on
this code:

 struct S __attribute__((unpadded)) {
   int i;
   char c;
 };

define S to have size 5 and alignment 4 on an ILP32 machine.

The idea is that the normal tail padding of S (the three bytes
after "c" to round it out to a multiple of the alignment) would
be suppressed.  It would be illegal to create arrays of these
types, since the required alignment would not then be provided
to all of the array elements.

The motivation for this comes from work on the C++ ABI, including
the tests for interoperability that we are developing.  The C++
ABI essentially has types like the above, but they are implicit.
Making them explicit gives us a way to express the same thing in C.

This comes up in C++ like so:

 struct A { virtual void f();  char c; };
 struct B : public A { char c2 };

Here, the size of B is 8, not 12, because "c2" is packed into
the tail padding of A.  If A were "unpadded", you could express
this in C as:

 struct A __attribute__((unpadded)) { void *vptr; char c; };
 struct B { struct A __base; char c2; };

If I do not here objections, I will create a patch for this and
check it in shortly.  Rats, we are in Stage 3 -- so I will check
it in after we branch for GCC 3.3.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

^ permalink raw reply	[flat|nested] 61+ messages in thread
* Re: RFC: attribute "unpadded"
@ 2002-08-23 10:58 Benjamin Kosnik
  2002-08-23 11:05 ` Mark Mitchell
  0 siblings, 1 reply; 61+ messages in thread
From: Benjamin Kosnik @ 2002-08-23 10:58 UTC (permalink / raw)
  To: gcc, mark

> The motivation for this comes from work on the C++ ABI, including
> the tests for interoperability that we are developing.  

Can you specify for the record what you are talking about here?

-benjamin

^ permalink raw reply	[flat|nested] 61+ messages in thread
* Re: RFC: attribute "unpadded"
@ 2002-08-23 16:07 Richard Kenner
  0 siblings, 0 replies; 61+ messages in thread
From: Richard Kenner @ 2002-08-23 16:07 UTC (permalink / raw)
  To: zack; +Cc: gcc

    I wonder if Ada can do something like this already, it seems to have
    everything *else* in its type system...

Yes and no.  Certainly you need to be able to have a record in Ada where
there is no padding, but the idea of its size not being a multiple of its
alignment is problematic.  So what's actually done is that *two* sizes are
stored, the "GCC size", which includes the padding and is a multiple of the
alignment, and the "Ada size", which does not include the alignment.  The
distinction is that it's the Ada size that represents the minimum size that
the record requires when placed into another packed record.

I was trying to decide if Mark's proposal would help Ada, but can't tell:
I'd need to see more details to know for sure.

^ permalink raw reply	[flat|nested] 61+ messages in thread
* Re: RFC: attribute "unpadded"
@ 2002-08-27 14:43 Richard Kenner
  2002-08-27 20:25 ` Fergus Henderson
  0 siblings, 1 reply; 61+ messages in thread
From: Richard Kenner @ 2002-08-27 14:43 UTC (permalink / raw)
  To: fjh; +Cc: gcc

    Presumably Ada objects are layed out by GNAT,

No, Ada objects are also layed out by stor-layout.c, for the most part.

^ permalink raw reply	[flat|nested] 61+ messages in thread
* Re: RFC: attribute "unpadded"
@ 2002-08-28  4:12 Robert Dewar
  0 siblings, 0 replies; 61+ messages in thread
From: Robert Dewar @ 2002-08-28  4:12 UTC (permalink / raw)
  To: fjh, kenner; +Cc: gcc

> By "GNAT" I meant the Ada front-end combined with the GCC back-end
> (of which stor-layout.c is a part).

Then the statement that objects are layed out by GNAT is hardly informative
(since obviously *some* code in the compiler is laying out Ada objects :-)

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

end of thread, other threads:[~2002-08-30  0:12 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-23 10:43 RFC: attribute "unpadded" Mark Mitchell
2002-08-23 10:49 ` Andrew Haley
2002-08-23 10:50   ` Mark Mitchell
2002-08-23 12:39     ` Andrew Haley
2002-08-23 13:02       ` Neil Booth
2002-08-23 13:20       ` Mark Mitchell
2002-08-23 15:57         ` Zack Weinberg
2002-08-25 19:03           ` Fergus Henderson
2002-08-25 23:59             ` Zack Weinberg
2002-08-26  4:52               ` language-independent types (was: RFC: attribute "unpadded") Fergus Henderson
2002-08-23 16:42   ` RFC: attribute "unpadded" Olivier Galibert
2002-08-25 18:16     ` Mark Mitchell
2002-08-23 10:51 ` Fergus Henderson
2002-08-23 10:53   ` Mark Mitchell
2002-08-23 21:52 ` Alexandre Oliva
2002-08-24 14:05   ` Paul Koning
2002-08-25 18:00     ` Mark Mitchell
2002-08-26  6:41       ` Paul Koning
2002-08-26  8:28         ` Andreas Schwab
2002-08-26  9:23           ` Gabriel Dos Reis
2002-08-26  9:45             ` Mark Mitchell
2002-08-26 10:54               ` Gabriel Dos Reis
2002-08-27  8:00               ` Fergus Henderson
2002-08-27  9:52                 ` Tom Tromey
2002-08-27 10:46                 ` Mark Mitchell
2002-08-27 11:39                   ` Fergus Henderson
2002-08-27 12:01                     ` Mark Mitchell
2002-08-27 12:04                     ` Gabriel Dos Reis
2002-08-27 14:25                     ` Joe Buck
2002-08-29 15:12                 ` Richard Henderson
2002-08-29 15:10               ` Richard Henderson
2002-08-29 15:24                 ` Richard Henderson
2002-08-29 15:30                   ` Mark Mitchell
2002-08-29 16:30                     ` Richard Henderson
2002-08-29 15:29                 ` Mark Mitchell
2002-08-29 15:45                   ` Gabriel Dos Reis
2002-08-29 16:00                     ` Mark Mitchell
2002-08-29 16:06                       ` Gabriel Dos Reis
2002-08-29 16:32                   ` Richard Henderson
2002-08-29 16:49                     ` Mark Mitchell
2002-08-30  0:12                   ` Kai Henningsen
2002-08-26 19:10 ` Jamie Lokier
2002-08-27  0:03   ` Mark Mitchell
2002-08-28  3:50 ` Richard Earnshaw
2002-08-28 10:22   ` Joe Buck
2002-08-28 10:56     ` Richard Earnshaw
2002-08-28 11:20       ` Joe Buck
2002-08-29  2:07         ` Richard Earnshaw
2002-08-28 21:22       ` Fergus Henderson
2002-08-29  2:27         ` Richard Earnshaw
2002-08-23 10:58 Benjamin Kosnik
2002-08-23 11:05 ` Mark Mitchell
2002-08-23 11:14   ` Benjamin Kosnik
2002-08-23 11:34     ` Janis Johnson
2002-08-23 11:39       ` Mark Mitchell
2002-08-23 11:35     ` Mark Mitchell
2002-08-23 12:03       ` Benjamin Kosnik
2002-08-23 16:07 Richard Kenner
2002-08-27 14:43 Richard Kenner
2002-08-27 20:25 ` Fergus Henderson
2002-08-28  4:12 Robert Dewar

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