patch to generate align 0 for packed attributes
Chandra Chavva
cchavva@cygnus.com
Thu Jul 27 12:24:00 GMT 2000
Hi Jeff,
On Thu, 27 Jul 2000, Jeffrey A Law wrote:
> In message < Pine.SOL.3.91.1000726120707.23599I-100000@emperor.cygnus.com >you
> write:
> > Hi,
> >
> > If a member of a struct has packed attribute and initialized, the compiler
> > does not correct alignment for such variables.
> >
> > Here is the testcase which fails for mips architecture,
> My first question, I'm guessing that the belief is that the MIPS assembler
> is automatically aligning data to their natural boundary?
>
In the example i mentioned, the compiled generates
.byte 1
.half 2
In the mips assembler, the .byte directive is aligned to 0 and the
.half directive is aligned to 1 generating the above to
address value
0000 01 .byte 1
0001 00 0200 .half 2
In the assembler, the directives are aligned only if .align is not zero.
> If so, how does an .align 0 stop that? That seems like awful strange behavior
> from an assembler.
Yes it does. This is the check done in the assembler which does that:
s_cons (log_size)
int log_size;
{
symbolS *label;
label = insn_labels != NULL ? insn_labels->label : NULL;
mips_emit_delays (false);
if (log_size > 0 && auto_align)
mips_align (log_size, 0, label);
mips_clear_insn_labels ();
cons (1 << log_size);
}
auto_align is a static variable is set to 1 if .align has some value else
it is set to 0.
>
> Second, do all MIPS assemblers do this? If not, then we need to test for
> it using autoconf.
>
> Third, you didn't include any documentation on the new target macros.
>
Yes i realized this after i sent out the patch.
> Fourth, I would be very leery of this code since it appears to be laying
> out bitfields within structures. If you do it wrong, you'll break ABI
> compatibility.
Yes my patch is wrong as it align's to 0 for every element of a struct.
Here is the revised patch.
Please let me know it is okay to apply.
Thanks
Chandra
* varasm.c (output_constructor): Add .align 0 for packed vars.
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/varasm.c,v
retrieving revision 1.125
diff -p -r1.125 varasm.c
*** varasm.c 2000/06/22 09:42:10 1.125
--- varasm.c 2000/07/27 19:21:03
*************** output_constructor (exp, size)
*** 4471,4476 ****
--- 4471,4485 ----
assemble_zeros (bitpos - total_bytes);
total_bytes = bitpos;
}
+ else if (field != 0 && DECL_PACKED (field))
+ {
+ /* 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. */
+
+ ASM_OUTPUT_ALIGN (asm_out_file, 0);
+ }
/* Determine size this element should occupy. */
if (field)
More information about the Gcc-patches
mailing list