This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

2nd request for struct packing on m68k


We've seen this before...  We discussed it concluded the doc was wrong
and the fix should be ok.  It is also at the FSF.  I have since found
one one related problem, and that fix appears below as well.

Can these be put in now?  Thanks.


Fri Sep 26 14:06:45 1997  Mike Stump  <mrs@wrs.com>

	* c-decl.c (start_struct): Ensure that structs with forward
	declarations are in fact packed when -fpack-struct is given.

Wed Sep 24 11:31:24 1997  Mike Stump  <mrs@wrs.com>

	* stor-layout.c (layout_record): Ignore STRUCTURE_SIZE_BOUNDARY if
	we are packing a structure.  This allows a structure with only
	bytes to be aligned on a byte boundary and have no padding on a
	m68k.

Index: c-decl.c
===================================================================
RCS file: /folk/mrs/.cvsroot/egcs/gcc/c-decl.c,v
retrieving revision 1.1.1.4
retrieving revision 1.2
diff -c -p -r1.1.1.4 -r1.2
*** c-decl.c	1997/09/16 02:07:07	1.1.1.4
--- c-decl.c	1997/09/26 21:09:25	1.2
*************** start_struct (code, name)
*** 5527,5532 ****
--- 5527,5533 ----
    if (ref && TREE_CODE (ref) == code)
      {
        C_TYPE_BEING_DEFINED (ref) = 1;
+       TYPE_PACKED (ref) = flag_pack_struct;
        if (TYPE_FIELDS (ref))
  	error ((code == UNION_TYPE ? "redefinition of `union %s'"
  		: "redefinition of `struct %s'"),
------------------------------

Date: Tue, 23 Sep 1997 19:46:33 -0700
From: mrs@wrs.com (Mike Stump)
Message-Id: <199709240246.TAA29991@kankakee.wrs.com>
To: egcs@cygnus.com
Subject: struct packing on m68k

This enables __attribute__ ((packed)) and friends to work on an m68k...

struct F {
  unsigned char ver:4;
  unsigned char frag:4;
} __attribute__ ((packed));

struct IP {
  struct F f;
  unsigned char opt:4;
  unsigned char len:4;
} __attribute__ ((packed));

struct IP a = { { 1, 2 }, 3, 4};

Otherwise the size of F is 2 bytes for no real good reason(?), other
than ABI compatibility.

The theory is that if you use -fpack-struct, or __attribute__
((packed)) then you don't care about ABI compatibility and changing
the layout to be what most people expect (and what almost all others
CPU platforms do), is a good thing.

Doing diffs in stor-layout.c.~1~:
*** stor-layout.c.~1~	Fri Aug 15 11:56:53 1997
--- stor-layout.c	Tue Sep 23 17:20:51 1997
*************** layout_record (rec)
*** 306,316 ****
       tree rec;
  {
    register tree field;
- #ifdef STRUCTURE_SIZE_BOUNDARY
-   unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
- #else
    unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
- #endif
    /* These must be laid out *after* the record is.  */
    tree pending_statics = NULL_TREE;
    /* Record size so far is CONST_SIZE + VAR_SIZE bits,
--- 306,312 ----
*************** layout_record (rec)
*** 324,329 ****
--- 320,330 ----
       that we know VAR_SIZE has.  */
    register int var_align = BITS_PER_UNIT;
  
+ #ifdef STRUCTURE_SIZE_BOUNDARY
+   /* Packed structures don't need to have minimum size.  */
+   if (! TYPE_PACKED (rec))
+     record_align = MAX (record_align, STRUCTURE_SIZE_BOUNDARY);
+ #endif
  
    for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
      {
*************** layout_union (rec)
*** 563,579 ****
       tree rec;
  {
    register tree field;
- #ifdef STRUCTURE_SIZE_BOUNDARY
-   unsigned union_align = STRUCTURE_SIZE_BOUNDARY;
- #else
    unsigned union_align = BITS_PER_UNIT;
- #endif
  
    /* The size of the union, based on the fields scanned so far,
       is max (CONST_SIZE, VAR_SIZE).
       VAR_SIZE may be null; then CONST_SIZE by itself is the size.  */
    register int const_size = 0;
    register tree var_size = 0;
  
    /* If this is a QUAL_UNION_TYPE, we want to process the fields in
       the reverse order in building the COND_EXPR that denotes its
--- 564,582 ----
       tree rec;
  {
    register tree field;
    unsigned union_align = BITS_PER_UNIT;
  
    /* The size of the union, based on the fields scanned so far,
       is max (CONST_SIZE, VAR_SIZE).
       VAR_SIZE may be null; then CONST_SIZE by itself is the size.  */
    register int const_size = 0;
    register tree var_size = 0;
+ 
+ #ifdef STRUCTURE_SIZE_BOUNDARY
+   /* Packed structures don't need to have minimum size.  */
+   if (! TYPE_PACKED (rec))
+     union_align = STRUCTURE_SIZE_BOUNDARY;
+ #endif
  
    /* If this is a QUAL_UNION_TYPE, we want to process the fields in
       the reverse order in building the COND_EXPR that denotes its
--------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]