Subject: Re: gcc-3.3.1 optimization bug on alpha?
To: None <port-alpha@netbsd.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-alpha
Date: 09/27/2003 00:55:18
In article <030927000240.M0104560@mirage.ceres.dti.ne.jp>
I wrote:

> Today I tried a new kernel compiled gcc-3.3.1 on 3000/300,
> and I notice some ioasic devices are not detected correctly:

Ok, it's actually off-by-one problem, as Yamamoto-san pointed out.

struct ioasicdev_attachargs is defined in sys/dev/tc/ioasicvar.h
like this:

> struct ioasicdev_attach_args {
> 	char	iada_modname[TC_ROM_LLEN];
> 	tc_offset_t iada_offset;
> 	tc_addr_t iada_addr;
> 	void	*iada_cookie;
> };

but sys/dev/tc/ioasic_subr.c:ioasic_attach_devs() puts NUL
at iada_modname[TC_ROM_LLEN] (that will break memory for iada_offset):

> 		strncpy(idev.iada_modname, ioasic_devs[i].iad_modname,
> 			TC_ROM_LLEN);
> 		idev.iada_modname[TC_ROM_LLEN] = '\0';
> 		idev.iada_offset = ioasic_devs[i].iad_offset;

The following patch fixes this problem, but I don't know
why the optimization problem occurs by this off-by-one...

---
Index: sys/dev/tc/ioasicvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/tc/ioasicvar.h,v
retrieving revision 1.14
diff -u -r1.14 ioasicvar.h
--- sys/dev/tc/ioasicvar.h	17 Oct 2000 09:45:49 -0000	1.14
+++ sys/dev/tc/ioasicvar.h	26 Sep 2003 15:33:29 -0000
@@ -38,7 +38,7 @@
 };
 
 struct ioasicdev_attach_args {
-	char	iada_modname[TC_ROM_LLEN];
+	char	iada_modname[TC_ROM_LLEN + 1];
 	tc_offset_t iada_offset;
 	tc_addr_t iada_addr;
 	void	*iada_cookie;

---
Izumi Tsutsui
tsutsui@ceres.dti.ne.jp