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

Re: Alignement on ARM



OoO En  cette soirée bien amorcée du  mardi 11 mai 2010,  vers 22:41, je
disais:

>> lldpd, a program of  my own, available on https://trac.luffy.cx/lldpd/ ;,
> [...]

> I  have  another  alignment  problem   on  ARM  (still  not  related  to
> Debian). Since I did get valuable help here last year, I try again. :)
[...]

> The user  reporting the error  is using some  old uclibc which  does not
> define getifaddrs() nor struct  ifaddrs. Therefore, I have reimplemented
> getifaddrs()   and  I   declare  struct   ifaddrs  as   it   appears  in
> /usr/include/ifaddrs.h (using struct sockaddr  for ifa_addr). I see that
> there  is some  internal  datatype called  struct sockaddr_storage  that
> tries to deal with alignment issues. Is it the key to my problem?

Using a porter box, I have  discovered that this also happens in sid for
both ARM  and mips with a standard  libc. I have fixed  my problems with
this patch:
 http://cgit.luffy.cx/lldpd/commit/?id=06db3608149133dd5efc38e68d47c06840f9c86b

While the memcpy  stuff is not so ugly, I have  used offsetof() to avoid
an additional memcpy just to replace a cast.

Luca,     thanks    for     your     answer.    Unfortunately,     using
__attribute__((aligned(2)))   would   align   the  pointer   to   struct
sockaddr. I have no way to force alignment of the struct itself.

For example, consider the following code :

 unsigned short int a; /* Just here to misalign the following struct */
 struct sockaddr mysa;  /* Suppose that myaddr is aligned  on a 1-byte
                           boundary but misaligned on a 2-byte boundary */
 struct ifaddrs myifaddr;
 struct sockaddr_ll *mysall;

 myifaddr.ifa_addr = &mysa;
 mysall = (struct sockaddr_ll *)(myifaddr.ifa_addr);
 /* Equivalent to: */
 mysall = (struct sockaddr_ll *)&mysa;

I have tested anyway and the warning remain.

While I have fixed my warnings, I  am still a bit astonished that such a
common code as :
 sa = (struct sockaddr_in *)ifa->ifa_addr;
 if (... sa->sin_addr ...) ...
can  lead to  a  misaligned access  on  ARM.  Maybe  there is  something
somewhere that  ensure that struct  sockaddr and struct  sockaddr_ll are
always aligned correctly on a 4-byte boundary?
-- 
/* Fuck me gently with a chainsaw... */
        2.0.38 /usr/src/linux/arch/sparc/kernel/ptrace.c

Attachment: pgpzVRnxenUHX.pgp
Description: PGP signature


Reply to: