Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Jul 2001 09:53:10 -0700 (PDT)
From:      John Polstra <jdp@polstra.com>
To:        alpha@freebsd.org
Cc:        mjacob@feral.com
Subject:   Re: this a gcc bug?
Message-ID:  <200107081653.f68GrAJ24108@vashon.polstra.com>
In-Reply-To: <Pine.BSF.4.21.0107062130090.48822-100000@beppo>
References:  <Pine.BSF.4.21.0107062130090.48822-100000@beppo>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <Pine.BSF.4.21.0107062130090.48822-100000@beppo>,
Matthew Jacob  <mjacob@feral.com> wrote:
> 
> I was tracking down unaligned faults in ping...
> 
> They come from an unaligned reference in that:
> 
> struct sockaddr whereto;
> ...
> 	bzero((char *)&whereto, sizeof(struct sockaddr));
> 	to = (struct sockaddr_in *)&whereto;
> ...
> 	       (void)printf("PING %s (%s)", hostname,
>                     inet_ntoa(to->sin_addr));
> 
> ...
> pid 528 (ping): unaligned access: va=0x120017ad3 pc=0x120003850 ra=0x12000335c
> op=ldl
> 
> Why?
> 
> Well, in test compiling ping.c I found:
> 
> yorp.feral.com > nm /tmp/ping |grep where
> 0000000120027b0f B whereto
> 
> But was it the linker?
> 
> 
> No. Assembler output shows:
> 	...
>         .comm   options,4,4
>         .comm   rcvd_tbl,128,1
>         .comm   whereto,16,1
> 	...
> 
> 
> Say &what&? Here we have a structure (struct sockaddr) that has only
> byte required alignment?
> 
> Structs, no matter what there contents, have been ALDOUBLE since Portable C
> compiler days- or so I thought. Maybe I'm just showing my ignorance/age. Have
> I
> gone nuts?

Well, that's for you and your shrink to decide.  But you are wrong
about struct alignment.  The compiler aligns a struct such that all
of its members are properly aligned.  In the case of struct sockaddr,
every member is a signed or unsigned char, or an array of char.  Chars
don't have to be aligned at all, so neither does struct sockaddr.

I bet that if "whereto" were declared as a struct sockaddr_in, this
problem would go away.

John
-- 
  John Polstra                                               jdp@polstra.com
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-alpha" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200107081653.f68GrAJ24108>