[parisc-linux] Back to evms-1.0.1 && unaligne access && gdb

John David Anglin dave@hiauly1.hia.nrc.ca
Fri, 30 Aug 2002 13:03:29 -0400 (EDT)


> >> p is of type partition define as follow:
> >> struct partition {
> >>     unsigned char boot_ind;     /* 0x80 - active */
> >>     unsigned char head;     /* starting head */
> >>     unsigned char sector;       /* starting sector */
> >>     unsigned char cyl;      /* starting cylinder */
> >>     unsigned char sys_ind;      /* What partition type */
> >>     unsigned char end_head;     /* end head */
> >>     unsigned char end_sector;   /* end sector */
> >>     unsigned char end_cyl;      /* end cylinder */
> >>     unsigned int start_sect;    /* starting sector counting from 0 */
> >>     unsigned int nr_sects;      /* nr of sectors in partition */
> >> };
> >
> >The problem is that a struct of the above type is being allocated
> >at an unaligned address.
> 
> Sorry I do not understand, can you tell me more or where can I found additional

You may be able to find a copy of WG14/N869 (Committee Draft -- January 18,
1999) on the web.  It is a draft version of the ISO C standard.  Section
6.7.2.1 describes struct and union types.

In general, the C standard doesn't define the representation used for
objects.  However, the alignment requirement of field members (except
bit fields) is the same as its type when not in a struct or union.
The PA implementation uses a strict "natural" alignment for types.
E.g., 4 byte integers are aligned to 4 byte boundaries.  Multiple
instructions are needed for unaligned data access on the PA.

A pointer to a struct points to the initial member (ie., there is no
padding before the first member).

The above struct starts with an unsigned char type so as far as the
standard goes it could start at any byte.  Note that it contains int
types, so that if it didn't start on a 4 byte boundary, there would
have to be padding after the last char field.  If the struct was given
"char" alignment, then different code would be needed to access members
when it was and wasn't aligned to a 4 byte boundary.  To minimize
problems of this nature, gcc aligns structs based on the largest
alignment requirement of all its members.

The code generated by gcc will not properly access fields of a struct
that isn't properly aligned.  Thus, you will need to try and find
out why in this particular case the struct isn't aligned and correct
the problem.  It might be a malloc problem or data read into an
arbitrary location.

Because the initial field of the struct is an unsigned char type,
the cast to uint32_t is wrong.  The code is making implementation
dependent assumptions.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)