From owner-freebsd-alpha Sun Jul 8 9:53:17 2001 Delivered-To: freebsd-alpha@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id D337037B401 for <alpha@freebsd.org>; Sun, 8 Jul 2001 09:53:13 -0700 (PDT) (envelope-from jdp@wall.polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.11.3/8.11.1) with ESMTP id f68GrAD90267; Sun, 8 Jul 2001 09:53:11 -0700 (PDT) (envelope-from jdp@wall.polstra.com) Received: (from jdp@localhost) by vashon.polstra.com (8.11.3/8.11.0) id f68GrAJ24108; Sun, 8 Jul 2001 09:53:10 -0700 (PDT) (envelope-from jdp) Date: Sun, 8 Jul 2001 09:53:10 -0700 (PDT) Message-Id: <200107081653.f68GrAJ24108@vashon.polstra.com> To: alpha@freebsd.org From: John Polstra <jdp@polstra.com> Cc: mjacob@feral.com Subject: Re: this a gcc bug? In-Reply-To: <Pine.BSF.4.21.0107062130090.48822-100000@beppo> References: <Pine.BSF.4.21.0107062130090.48822-100000@beppo> Organization: Polstra & Co., Seattle, WA Sender: owner-freebsd-alpha@FreeBSD.ORG Precedence: bulk List-ID: <freebsd-alpha.FreeBSD.ORG> List-Archive: <http://docs.freebsd.org/mail/> (Web Archive) List-Help: <mailto:majordomo?subject=help> (List Instructions) List-Subscribe: <mailto:majordomo?subject=subscribe%20freebsd-alpha> List-Unsubscribe: <mailto:majordomo?subject=unsubscribe%20freebsd-alpha> X-Loop: FreeBSD.org 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