[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#731806: debian-installer: FTBFS on sparc: genisoimage errors



Hi,

On 28/04/2014 18:25, Thomas Schmitt wrote:

has a struct on heap (#L102, #L138, #L146):

    struct w_list{
        ...
        union w_list_data
        {
            ...
            struct write_opts write;
            ...
        } u;
    }
    ...
    struct w_list *a;
    ...
    a = calloc(1, sizeof(struct w_list));

The gesture which causes the SIGBUS is (#L149)

    a->u = *(union w_list_data *)data;

The issue is that data needs to be suitably aligned on an appropriate memory boundary. SPARC requires that int32 accesses are aligned on 4 byte boundaries and that int64 aligns on 8 byte boundaries.

You have to arrange that data is properly aligned or you will get a SIGBUS due to an address misalignment.

malloc and calloc arrange that the alignment is suitable

(the manpage says)

"RETURN VALUE
The malloc() and calloc() functions return a pointer to  the  allocated
memory  that  is  suitably aligned for any kind of variable. "

I'm guessing that your void *data isn't directly allocated by calloc so it doesn't necessarily have the correct alignment.


which is not what i personally would use, but should be fully legal
nevertheless.

The SIGBUS vanishes if i compile without gcc -O2, or if i replace
the "a->u =" gesture by

    memcpy(&(a->u), data, sizeof(union w_list_data));

which i deem equivalent (and more my personal style).

The memcpy version will work just fine because memcpy takes misalignments into account and once the data has been copied into a->u the calloc'd version of struct w_list will be properly aligned because calloc guarantees that it will be.

memcpy is the correct thing to use in your case.

Regards

Richard


Reply to: