I asked:
>I'm attempting to compile some C code in which I'd like to byte align the
>data structure elements. A quick look at the manual page looks like I
>should use either the -Zpn flag or a combination of -migrate and
>-nomemmber_alignment.
>
>Using either of these generates code without warnings, but which core
>dumps on a fprintf call. Dbx says:
>
>(dbx) run -d
>signal Segmentation fault at >*[memcpy, 0x3ff80847ee4]  stq_u   r3,
>0(r16)
>
>which looks like it's somewhere in a system library. Needless to say the
>same code _without_ byte alignment runs flawlessly.
>
>Am I'm doing something wrong, or is there a problem with the
>compiler/libraries? Any ideas anyone?
Big thanks to Paul Henderson of DEC (henderson_at_unx.dec.com) for supplying
some sample code pointing out how this should be done, problems were a
misunderstanding on my part, (and a lack of supporting documentation :-).
His reply follows:
8<----------------------------------------------------------
I don't know what your actual code is, but here's an example of byte
alignment using pragmas that works properly for another customer. Maybe it 
will help...
Paul
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Henderson                  email: henderson_at_unx.dec.com
Digital Unix Engineering      decMail: unxa::henderson
                            snailmail: 200 Route 9, Manalapan,NJ,USA 07726
                                voice: (908)577-6044 (dtn 462-6044)
Here's an example:
#pragma member_alignment save
#pragma nomember_alignment quadword
typedef  struct 
{
        volatile unsigned int Value;  /* Validation code + Lock bit */
        short                 Port;           /* Process holding Lock
*/
        short                 fill;  /* required to align items in arrays
*/
} SPINLOCK;
#pragma member_alignment restore
struct uses_it {
     char fud;
     SPINLOCK A;
     SPINLOCK B;
     SPINLOCK C;
};
int align(char *s, long p) {
        printf("%s  (0x%x)  ", s, p);
        if(p % 8 == 0) printf(" 8 byte aligned\n");
        else if(p % 4 == 0) printf(" 4 byte aligned\n");
        else if(p % 2 == 0) printf(" 2 byte aligned\n");
        else printf(" NOT aligned\n");
}
main() {
     struct uses_it n;
     align("n.A.Value", (long)&n.A.Value);
     align("n.B.Value", (long)&n.B.Value);
     align("n.C.Value", (long)&n.C.Value);
}
8<----------------------------------------------------------
Thanks again Paul,
Simon
--
Simon Greaves					email:	S.J.Greaves_at_hw.ac.uk
Systems development manager			phone:	+44 (0) 131 451 3265
Computer Centre, Heriot-Watt University		fax:	+44 (0) 131 451 3261
Edinburgh, EH14 4AS, UK
Received on Fri Aug 02 1996 - 18:26:36 NZST