NetBSD-Bugs archive

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

Re: port-sh3/56311: GCC 9 and 10 miscompile lint1 for sh3 (by mischoice of register)



The following reply was made to PR port-sh3/56311; it has been noted by GNATS.

From: Rin Okuyama <rokuyama.rk%gmail.com@localhost>
To: "gnats-bugs%NetBSD.org@localhost" <gnats-bugs%NetBSD.org@localhost>
Cc: Valery Ushakov <uwe%stderr.spb.ru@localhost>
Subject: Re: port-sh3/56311: GCC 9 and 10 miscompile lint1 for sh3 (by
 mischoice of register)
Date: Fri, 16 Jul 2021 17:34:30 +0900

 In my previous analysis, I carelessly forgot delay slots!
 Please ignore that (I've corrected wrong title of the PR).
 
 I've examined objdump again, more carefully this time ;)
 
 Source code and dump for initdecl() with comments are:
 
 ----
 void
 initdecl(void)
 {
 	int i;
 
 	/* declaration stack */
 	dcs = xcalloc(1, sizeof(*dcs));
 	dcs->d_ctx = EXTERN;
 	dcs->d_ldlsym = &dcs->d_dlsyms;
 
 	/* type information and classification */
 	inittyp();
 ...
 ----
 
 ----
 00407eae <initdecl>:
    407eae:	mov.l	r12,@-r15			! push r12
    407eb0:	mova	407fb4 <initdecl+0x106>,r0	! r0  = 0x407fb4
    407eb2:	mov.l	407fb4 <initdecl+0x106>,r12	! r12 = 0x03a9b8
    407eb4:	sts.l	pr,@-r15			! push pr
    407eb6:	add	r0,r12				! r12 = .got
    407eb8:	mov.l	407fb8 <initdecl+0x10a>,r1	! r1 = 0x96d4
    407eba:	mov	#80,r5				! r5 = 80
    407ebc:	bsrf	r1				! r0 = xcalloc(1, 80)
    407ebe:	  mov	#1,r4				!   r4 = 1
    407ec0:	mov.l	407fbc <initdecl+0x10e>,r1	! r1 = 0x02f0
    407ec2:	mov	r0,r2				! r2 = r0
    407ec4:	mov	r12,r0				! r0 = .got
    407ec6:	mov.l	r2,@(r0,r1)			! @(.got, 0x02f0) = dcs = r2
    407ec8:	mov	#1,r1				! r1 = EXTERN
    407eca:	mov.l	r1,@(36,r2)			! @(36, r2) = dcs->d_ctx = r1
    407ecc:	add	#64,r2				! r2 = &dcs + 64 = &dcs->d_dlsyms
    407ece:	mov.l	407fc0 <initdecl+0x112>,r1	! r1 = 0x7954
    407ed0:	bsrf	r1				! inittyp()
    407ed2:	  mov.l	r2,@(4,r12)			!   @(4, .got) = ??? = r2
 ...
 ----
 
 GCC seems to make a mistake at the last line; if it were
 
 ----
    407ed2:	  mov.l	r2,@(4,r2)
 ----
 
 it would work as expected, i.e.,
 
 ----
 	@(4, &dcs->d_dlsyms) = dcs->d_ldlsym = r2 = &dcs->d_dlsyms
 ----
 
 However, since it mistakes r12 (= .got) for r2, dcs->d_ldlsym is not
 correctly initialized, and .got becomes broken.
 
 I think this is what happens with the default optimization level.
 
 Thanks uwe@ for kind advice offlist!
 
 rin
 


Home | Main Index | Thread Index | Old Index