From kargl@troutmask.apl.washington.edu  Sat Mar  9 12:57:53 2002
Return-Path: <kargl@troutmask.apl.washington.edu>
Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.208.78.105])
	by hub.freebsd.org (Postfix) with ESMTP id 96B6437B41A
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  9 Mar 2002 12:57:52 -0800 (PST)
Received: (from kargl@localhost)
	by troutmask.apl.washington.edu (8.11.6/8.11.4) id g29Kvlg27662;
	Sat, 9 Mar 2002 12:57:47 -0800 (PST)
	(envelope-from kargl)
Message-Id: <200203092057.g29Kvlg27662@troutmask.apl.washington.edu>
Date: Sat, 9 Mar 2002 12:57:47 -0800 (PST)
From: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
Reply-To: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: kern_linker.c rev. 1.75 and newer break module loading
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         35712
>Category:       kern
>Synopsis:       kern_linker.c rev. 1.75 and newer break module loading
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 09 13:00:00 PST 2002
>Closed-Date:    Sun Mar 10 15:12:48 PST 2002
>Last-Modified:  Sun Mar 10 15:14:15 PST 2002
>Originator:     Steven G. Kargl
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
apl/uw
>Environment:
System: FreeBSD troutmask.apl.washington.edu 5.0-CURRENT FreeBSD 5.0-CURRENT #0: Thu Feb 14 11:34:33 PST 2002 kargl@troutmask.apl.washington.edu:/usr/obj/usr/src/sys/TROUTMASK i386


>Description:

This revision

Revision 1.75 Fri Feb 22 04:14:49 2002 UTC (2 weeks, 1 day ago) by arr 
Branch: MAIN 
Changes since 1.74: +1295 -1271 lines

- Massive style fixup.

Reviewed by: mike
Approved by: dfr

breaks the loading of at least linprocfs.ko after a reboot.

root[202] cat /boot/loader.conf
miibus_load="YES"
if_rl_load="YES"
snd_pcm_load="YES"
snd_maestro3_load="YES"
linux_load="YES"
agp_load="YES"
hint.acpi.0.disable="1"
root[203] kldstat
Id Refs Address    Size     Name
 1   12 0xc0100000 262e40   kernel
 2    1 0xc0363000 18330    linux.ko
 3    2 0xc037c000 15480    miibus.ko
 4    1 0xc0392000 7798     if_rl.ko
 5    2 0xc039a000 1a14c    snd_pcm.ko
 6    1 0xc03b5000 9538     snd_maestro3.ko
 7    1 0xc03bf000 c860     agp.ko
 8    1 0xcb052000 2000     blank_saver.ko
root[204] kldload linprocfs
kldload: can't load linprocfs: Exec format error
root[206] tail -1 /var/log/messages
Mar  9 10:00:27 kernel: KLD linprocfs.ko: depends on linux - not available

root[209] kldunload linux
root[210] kldload linux
root[211] kldload linprocfs
root[213] kldstat
Id Refs Address    Size     Name
 1   15 0xc0100000 262e40   kernel
 3    2 0xc037c000 15480    miibus.ko
 4    1 0xc0392000 7798     if_rl.ko
 5    2 0xc039a000 1a14c    snd_pcm.ko
 6    1 0xc03b5000 9538     snd_maestro3.ko
 7    1 0xc03bf000 c860     agp.ko
 8    1 0xcb052000 2000     blank_saver.ko
 9    2 0xcb425000 14000    linux.ko
10    1 0xcab88000 5000     linprocfs.ko

If I back up to revision 1.74 of kern_linker.c, then
this problem of "Exec format error" and "KLD linprocfs.ko:
depends on linux - not available" goes away.

As the commit message for revision 1.75 states "Massive
style fixup", I suspect a typo slipped in.  However,
this is a +1200 line diff and I haven't been able to
find it.

>How-To-Repeat:

reboot
kldload linprocfs

>Fix:

Revert to revision 1.74

>Release-Note:
>Audit-Trail:

From: David Malone <dwmalone@maths.tcd.ie>
To: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
Cc: FreeBSD-gnats-submit@freebsd.org, ashp@freebsd.org
Subject: Re: kern/35712: kern_linker.c rev. 1.75 and newer break module loading
Date: Sun, 10 Mar 2002 17:03:06 +0000

 On Sat, Mar 09, 2002 at 12:57:47PM -0800, Steven G. Kargl wrote:
 > As the commit message for revision 1.75 states "Massive
 > style fixup", I suspect a typo slipped in.  However,
 > this is a +1200 line diff and I haven't been able to
 > find it.
 
 I checked out both copies of the file and had a look with diff -w
 -u, which helped a bit. There were some odd style changes in this
 file. In some places,
 
 	if (!strcmp(lf->filename, koname))
 
 was replaced with:
 
 	err = strcmp(lf->filename, koname);
 	if (err == 0)
 
 which is weird, as strcmp doesn't return an error. The
 more idiomatic:
 
 	if (strcmp(lf->filename, koname) == 0)
 
 would probably have been better. In fact, the bug you are seeing
 is due to one of these changes. It is clobbering the value of
 error, which the surounding code expects to remain unchanged.
 I've included a patch below which converts these strcmp calls
 to something more sensible and fixes the bug in the process.
 
 Some comments were moved above if statements to facilitate the
 removal of braces and now the comments don't quite make as much
 sense now, but that's probably less serious.
 
 I'll commit the patch below in a few days, unless Ashley has
 any problems with it.
 
 	David.
 
 
 Index: kern_linker.c
 ===================================================================
 RCS file: /cvs/FreeBSD-CVS/src/sys/kern/kern_linker.c,v
 retrieving revision 1.77
 diff -u -r1.77 kern_linker.c
 --- kern_linker.c	27 Feb 2002 18:32:12 -0000	1.77
 +++ kern_linker.c	10 Mar 2002 16:54:51 -0000
 @@ -362,7 +362,6 @@
  {
  	linker_file_t lf = 0;
  	char *koname;
 -	int err;
  
  	koname = malloc(strlen(filename) + 4, M_LINKER, M_WAITOK);
  	if (koname == NULL)
 @@ -371,11 +370,9 @@
  
  	lockmgr(&lock, LK_SHARED, 0, curthread);
  	TAILQ_FOREACH(lf, &linker_files, link) {
 -		err = strcmp(lf->filename, koname);
 -		if (err == 0)
 +		if (strcmp(lf->filename, koname) == 0)
  			break;
 -		err = strcmp(lf->filename, filename);
 -		if (err == 0)
 +		if (strcmp(lf->filename, filename) == 0)
  			break;
  	}
  	lockmgr(&lock, LK_RELEASE, 0, curthread);
 @@ -549,7 +546,7 @@
  	linker_symval_t symval;
  	caddr_t address;
  	size_t common_size = 0;
 -	int err, i;
 +	int i;
  
  	KLD_DPF(SYM, ("linker_file_lookup_symbol: file=%x, name=%s, deps=%d\n",
  	    file, name, deps));
 @@ -589,8 +586,7 @@
  		struct common_symbol *cp;
  
  		STAILQ_FOREACH(cp, &file->common, link) {
 -			err = strcmp(cp->name, name);
 -			if (err == 0) {
 +			if (strcmp(cp->name, name) == 0) {
  				KLD_DPF(SYM, ("linker_file_lookup_symbol:"
  				    " old common value=%x\n", cp->address));
  				return (cp->address);
 @@ -983,11 +979,10 @@
  modlist_lookup(const char *name, int ver)
  {
  	modlist_t mod;
 -	int err;
  
  	TAILQ_FOREACH(mod, &found_modules, link) {
 -		err = strcmp(mod->name, name);
 -		if (err == 0 && (ver == 0 || mod->version == ver))
 +		if (strcmp(mod->name, name) == 0 &&
 +		    (ver == 0 || mod->version == ver))
  			return (mod);
  	}
  	return (NULL);
 @@ -997,15 +992,14 @@
  modlist_lookup2(const char *name, struct mod_depend *verinfo)
  {
  	modlist_t mod, bestmod;
 -	int err, ver;
 +	int ver;
  
  	if (verinfo == NULL)
  		return (modlist_lookup(name, 0));
  	bestmod = NULL;
  	for (mod = TAILQ_FIRST(&found_modules); mod;
  	    mod = TAILQ_NEXT(mod, link)) {
 -		err = strcmp(mod->name, name);
 -		if (err != 0)
 +		if (strcmp(mod->name, name) != 0)
  			continue;
  		ver = mod->version;
  		if (ver == verinfo->md_ver_preferred)
 @@ -1189,8 +1183,7 @@
  					    NULL);
  					nmodname = linker_reloc_ptr(lf,
  					    nmp->md_cval);
 -					error = strcmp(modname, nmodname);
 -					if (error == 0)
 +					if (strcmp(modname, nmodname) == 0)
  						break;
  				}
  				if (nmdp < stop)   /* it's a self reference */
 @@ -1714,8 +1707,7 @@
  			if (nmp->md_type != MDT_VERSION)
  				continue;
  			nmodname = linker_reloc_ptr(lf, nmp->md_cval);
 -			error = strcmp(modname, nmodname);
 -			if (error == 0)
 +			if (strcmp(modname, nmodname) == 0)
  				break;
  		}
  		if (nmdp < stop)/* early exit, it's a self reference */

From: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
To: Ashley Penney <ashp@freebsd.org>
Cc: David Malone <dwmalone@maths.tcd.ie>,
	FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/35712: kern_linker.c rev. 1.75 and newer break module loading
Date: Sun, 10 Mar 2002 09:51:45 -0800 (PST)

 Ashley Penney said:
 > On Sun, Mar 10, 2002 at 05:03:06PM +0000, David Malone said:
 > > I'll commit the patch below in a few days, unless Ashley has
 > > any problems with it.
 > > 
 > > 	David.
 >  
 > I'm not quite sure how I got into this mail as I've never seen/touched
 > the code in question.  All the changes make sense, on the other hand. :)
 > 
 > -- 
 > Ashley Penney: <ashp@freebsd.org>
 > 
 
 I think David wanted arr@freebsd.org, which is Andrew Reitter I believe.
 
 -- 
 Steve
 http://troutmask.apl.washington.edu/~kargl/

From: David Malone <dwmalone@maths.tcd.ie>
To: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
Cc: Ashley Penney <ashp@freebsd.org>,
	FreeBSD-gnats-submit@freebsd.org, arr@freebsd.org
Subject: Re: kern/35712: kern_linker.c rev. 1.75 and newer break module loading 
Date: Sun, 10 Mar 2002 17:57:27 +0000

 > I think David wanted arr@freebsd.org, which is Andrew Reitter I believe.
 
 *slap*
 
 Yep - too long reading diffs has made be bleary eyed.
 
 Andrew - can you have a look a the patch I sent for this PR
 and see if you agree?
 
 	http://www.FreeBSD.org/cgi/query-pr.cgi?pr=35712
 
 David.

From: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
To: David Malone <dwmalone@maths.tcd.ie>
Cc: FreeBSD-gnats-submit@freebsd.org, arr@freebsd.org
Subject: Re: kern/35712: kern_linker.c rev. 1.75 and newer break module loading
Date: Sun, 10 Mar 2002 10:34:05 -0800 (PST)

 David Malone said:
 > > I think David wanted arr@freebsd.org, which is Andrew Reitter I believe.
 > 
 > *slap*
 > 
 > Yep - too long reading diffs has made be bleary eyed.
 > 
 > Andrew - can you have a look a the patch I sent for this PR
 > and see if you agree?
 > 
 > 	http://www.FreeBSD.org/cgi/query-pr.cgi?pr=35712
 > 
 
 David, 
 
 I've just reboot with your patch in place.  The
 system came up as expected and linprocfs.ko was
 loaded without error.
 
 I stared at the diff between 1.74 and 1.75 yesterday
 for several hours.  Intuitively, I felt one of the
 strcmp() changes was the problem, but I could see it.
 (Something about forests and trees :-).
 
 -- 
 Steve
 http://troutmask.apl.washington.edu/~kargl/

From: "Andrew R. Reiter" <arr@FreeBSD.org>
To: David Malone <dwmalone@maths.tcd.ie>
Cc: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>,
	Ashley Penney <ashp@FreeBSD.org>, FreeBSD-gnats-submit@FreeBSD.org,
	arr@FreeBSD.org
Subject: Re: kern/35712: kern_linker.c rev. 1.75 and newer break module loading 
Date: Sun, 10 Mar 2002 15:08:42 -0500 (EST)

 On Sun, 10 Mar 2002, David Malone wrote:
 
 :> I think David wanted arr@freebsd.org, which is Andrew Reitter I believe.
 :
 :*slap*
 :
 :Yep - too long reading diffs has made be bleary eyed.
 :
 :Andrew - can you have a look a the patch I sent for this PR
 :and see if you agree?
 :
 :	http://www.FreeBSD.org/cgi/query-pr.cgi?pr=35712
 
 Looks good to me  -- thanks for the help.  This was an evil sized diff to
 deal with.
 
 Cheers,
 Andrew
 
 --
 Andrew R. Reiter
 arr@watson.org
 arr@FreeBSD.org
 
State-Changed-From-To: open->closed 
State-Changed-By: dwmalone 
State-Changed-When: Sun Mar 10 15:12:48 PST 2002 
State-Changed-Why:  
Fixed in -current by Maxim in revision 1.78 and again by me in 1.79 ;-) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=35712 
>Unformatted:
