Operating System - HP-UX
1753865 Members
7685 Online
108809 Solutions
New Discussion юеВ

Re: HPUX, ia64, +DD32 and alignment issue

 
ewest02
New Member

HPUX, ia64, ILP32 and alignment issue

I am building code akin to

struct node {
void * data;
struct node * next;
struct node * prev;
};

...

struct node *nptr = malloc(sizeof(struct node) + sizeof(my_data));

nptr->data = nptr + 1;
*(uint64_t *)nptr->data = 123LLU; // bus error

This causes a bus error only on ia64 compiled in ILP32 data mode.

I can circumvent this bus error with the +u compiler option or by adding an uint64_t (or a void *) member after the 'prev' pointer.

Note I can compile this code on a plethora of other platforms and architectures without error. Only the HP ia64 + ILP32 model results in the bus error without the above mentioned workarounds.

Is this expected? Is the HP compile not accessing memory or padding structs correctly?

Note I am testing with a range of HP compiler revs (latest being 6.12).

Thanks in advance.

--Eric
2 REPLIES 2
Dennis Handly
Acclaimed Contributor

Re: HPUX, ia64, +DD32 and alignment issue

>This causes a bus error only on ia64 compiled in ILP32 data mode.

This also will abort on PA if you optimize.

Your program is doing an illegal cast. nptr is only 4 byte aligned. Your struct is only 4 byte aligned and has a size of 12. So nptr+1 is only 4 byte aligned.
But uint64_t* is 8 byte aligned, so it aborts.

You need to pad your struct to be 8 byte aligned:
struct node {
    void *data;
    struct node *next, *prev;
    uint64_t :0; // align struct
};

Dennis Handly
Acclaimed Contributor

Re: HPUX, ia64, +DD32 and alignment issue

Oops, actually nptr is 16 byte aligned but nptr+1 is only 4.