From: Simon Greaves <S.J.Greaves () hw ! ac ! uk>
To: tru64-unix-managers
Subject: SUMMARY: DU3.2D-1 code bombs if not member aligned?
Date: Fri, 02 Aug 1996 15:49:11 +0000 [thread overview]
Message-ID: <96076337821265.tru64-unix-managers.marc@archive.invalid> (raw)
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@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@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@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
reply other threads:[~1996-08-02 15:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox