__attribute__ ((packed))

Scott Bambrough scottb@netwinder.org
Thu May 6 07:04:00 GMT 1999


Philippe De Muyter wrote:
> 
> > Philippe De Muyter wrote:
> > >
> > > The test below is not strong enough to decide __attribute__ ((packed)) is
> > > supported.  Perhaps the best way, if `packed' is really needed, would be
> > > to do an autoconf test.
> > >
> > > Thu May  6 12:32:55 1999  Philippe De Muyter  <phdm@macqel.be>
> > >
> > >         * include/elf/external.h (Elf_External_Versym) : __attribute__ ((
> > >         packed)) turned off.
> > >
> > > --- ./include/elf/external.h    Thu May  6 12:34:15 1999
> > > +++ ./include/elf/external.h    Wed Apr 28 13:37:55 1999
> > > @@ -241,8 +241,10 @@
> > >  typedef struct {
> > >    unsigned char                vs_vers[2];
> > >  }
> > > +#if 0
> > >  #ifdef __GNUC__
> > >    __attribute__ ((packed))
> > > +#endif
> > >  #endif
> > >    Elf_External_Versym;
> > >
> >
> > This change will break some of the ELF code on the ARM.  There are places in the
> > code where sizeof(Elf_External_Versym) is used, and is expected to be 2.  On the
> > ARM without the packed attribute this struct will be 4 bytes in length.
> >
> > Scott
> >
> Then, I think that this should written to not depend of the compiler used
> to compile this code.
> 

Actually I should qualify my response.  This looks like a patch that was
submitted to the glibc source by myself or Phil Blundell.  It fixed a problem
Jim Pick had found in glibc.  Some of the code in glibc depended on
sizeof(Elf_External_Versym) being 2.  This may not be the case in GDB.

I don't know of any compiler independent way of supporting packing.  And I fail
to see why the above test is not sufficient.  If __GNUC__ is defined, then a GNU
C compiler is being used, and __attribute__ ((packed)) is supported.  Perhaps it
needs to be further qualified with version macro?

Scott


More information about the Gdb-patches mailing list