This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
patch to align gobal vars having packed attribute
- To: gcc-patches at gcc dot gnu dot org
- Subject: patch to align gobal vars having packed attribute
- From: Chandra Chavva <cchavva at cygnus dot com>
- Date: Thu, 10 Aug 2000 09:13:07 -0700 (PDT)
Here is the patch which generates .align 0 for elements of a struct
having packed attribute.
The patch solves the following 'C' code for mips target.
struct {
char m1;
short m2 __attribute__ ((packed));
} x = {1, 2};
int main()
{
printf("%d\n", x.m2);
return 0;
}
Here is the patch
* c-typeck.c (output_init_element): Add .align 0 to fields of a
global struct having packed attribute.
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-typeck.c,v
retrieving revision 1.81
diff -p -r1.81 c-typeck.c
*** c-typeck.c 2000/08/08 23:19:11 1.81
--- c-typeck.c 2000/08/10 16:01:27
*************** output_init_element (value, type, field,
*** 6004,6022 ****
}
else
{
/* Structure elements may require alignment.
Do this, if necessary. */
if (TREE_CODE (constructor_type) == RECORD_TYPE
&& ! tree_int_cst_equal (constructor_bit_index,
bit_position (field)))
--- 6004,6032 ----
}
else
{
+
+ /* Some assemblers automaticallly align a datum according
+ to its size if no align directive is specified. The
+ datum, however, may be declared with 'packed' attribute,
+ so we have to disable such a feature. */
+
+ if (TREE_CODE (constructor_type) == RECORD_TYPE
+ && field && DECL_PACKED (field))
+ ASM_OUTPUT_ALIGN (asm_out_file, 0);
+
/* Structure elements may require alignment.
Do this, if necessary. */
if (TREE_CODE (constructor_type) == RECORD_TYPE
&& ! tree_int_cst_equal (constructor_bit_index,
bit_position (field)))
Is it okay to apply.
Thanks
Chandra
(I have applied similiar patch in varasm.c, that solves only local
struct having packed attribute.)