Subject: bin/9494: possible codegen bug in Alpha GCC -- alignment problem
To: None <gnats-bugs@gnats.netbsd.org>
From: None <thorpej@shagadelic.org>
List: netbsd-bugs
Date: 02/26/2000 16:57:38
>Number:         9494
>Category:       bin
>Synopsis:       possible codegen bug in Alpha GCC -- alignment problem
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 26 16:57:00 2000
>Last-Modified:
>Originator:     Jason R Thorpe
>Organization:
6th and Hugo Software
>Release:        NetBSD 1.4T, Feb 25, 2000
>Environment:
	
System: NetBSD yeah-baby 1.4T NetBSD 1.4T (YEAH-BABY) #33: Fri Feb 25 23:12:43 PST 2000 thorpej@yeah-baby:/u1/netbsd/src/sys/arch/alpha/compile/YEAH-BABY alpha


>Description:
	I noticed that I was getting unaligned access errors when running
	`ifconfig -a':

yeah-baby:thorpej 31$ ifconfig -a
tlp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        address: 00:00:f8:23:43:9d
        media: Ethernet 10base5
        inet 208.176.2.162 netmask 0xfffffff0 broadcast 208.176.2.175
        inet6 fe80::200:f8ff:fe23:439d%tlp0 prefixlen 64 scopeid 0x1
pid 17981 (ifconfig): unaligned access: va=0x1ffffb504 pc=0x12000135c ra=0x1200013fc op=ldt
pid 17981 (ifconfig): unaligned access: va=0x1ffffb50c pc=0x120001360 ra=0x1200013fc op=ldt
pid 17981 (ifconfig): unaligned access: va=0x1ffffb514 pc=0x120001364 ra=0x1200013fc op=ldt
pid 17981 (ifconfig): unaligned access: va=0x1ffffb51c pc=0x120001368 ra=0x1200013fc op=ldt
.
.
.
ray0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        nwid NETWORK_NAME
        address: 00:00:f1:11:59:07
        media: IEEE802.11 FH2 adhoc
        status: active
        inet 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255
        inet6 fe80::200:f1ff:fe11:5907%ray0 prefixlen 64 scopeid 0x8
pid 18054 (ifconfig): unaligned access: va=0x1ffffb694 pc=0x12000135c ra=0x1200015c8 op=ldt
pid 18054 (ifconfig): unaligned access: va=0x1ffffb69c pc=0x120001360 ra=0x1200015c8 op=ldt
pid 18054 (ifconfig): unaligned access: va=0x1ffffb6a4 pc=0x120001364 ra=0x1200015c8 op=ldt
pid 18054 (ifconfig): unaligned access: va=0x1ffffb6ac pc=0x120001368 ra=0x1200015c8 op=ldt
pid 18054 (ifconfig): unaligned access: va=0x1ffffb6b4 pc=0x12000135c ra=0x1200013fc op=ldt
pid 18054 (ifconfig): unaligned access: va=0x1ffffb6bc pc=0x120001360 ra=0x1200013fc op=ldt
pid 18054 (ifconfig): unaligned access: va=0x1ffffb6c4 pc=0x120001364 ra=0x120001
.
.
.

	The first PC in each block, 0x12000135c, is in the printall()
	function.  An ifconfig build with debugging symbols shows this
	to be at line 679:

		ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
679 --->	memcpy(ifrbuf, ifr, sizeof(*ifr));
		siz = ((struct ifreq *)ifrbuf)->ifr_addr.sa_len;

	Using memcpy() is the canonical way to access an unaligned
	structure: copy the unaligned data into a properly aligned
	buffer.  However, in this case, GCC is inlining the call to
	memcpy(), and generating `ldt' (a floating-point load).  However,
	since the data is unaligned, this generates a fault.

	This hypothesis is supported by the fact that the bad access
	does away if ifconfig is built with -O0 (GCC won't inline memcpy()
	calls at that optimization level).

>How-To-Repeat:
	Run `ifconfig -a'.

>Fix:
	This is probably the same problem that bit the PowerPC port
	with an X11 library (sorry, I forget which one).  As a result
	of the discussion that ensued on port-macppc, the mainline GCC
	code was changed to consider additional alignment constraints
	for inlined copies, etc.

	It sounds like these changes probably need to be merged into
	the NetBSD mainline in one way or another.

>Audit-Trail:
>Unformatted: