From edwin@mavetju.org  Sun Mar  2 01:13:02 2008
Return-Path: <edwin@mavetju.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 0B8D61065675
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  2 Mar 2008 01:13:02 +0000 (UTC)
	(envelope-from edwin@mavetju.org)
Received: from mail5out.barnet.com.au (mail5.barnet.com.au [202.83.178.78])
	by mx1.freebsd.org (Postfix) with ESMTP id A88B08FC33
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  2 Mar 2008 01:13:01 +0000 (UTC)
	(envelope-from edwin@mavetju.org)
Received: by mail5out.barnet.com.au (Postfix, from userid 1001)
	id D90582218AC9; Sun,  2 Mar 2008 12:13:00 +1100 (EST)
Received: from mail5auth.barnet.com.au (mail5.barnet.com.au [202.83.178.78])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail5auth.barnet.com.au", Issuer "*.barnet.com.au" (verified OK))
	by mail5.barnet.com.au (Postfix) with ESMTP id 551E321B2003
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  2 Mar 2008 12:13:00 +1100 (EST)
Received: from k7.mavetju (k7.mavetju.org [10.251.1.18])
	by mail5auth.barnet.com.au (Postfix) with ESMTP id ACFB72218ABE
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  2 Mar 2008 12:12:59 +1100 (EST)
Received: by k7.mavetju (Postfix, from userid 1001)
	id 74F6413B; Sun,  2 Mar 2008 12:12:59 +1100 (EST)
Message-Id: <20080302011259.74F6413B@k7.mavetju>
Date: Sun,  2 Mar 2008 12:12:59 +1100 (EST)
From: Edwin Groothuis <edwin@mavetju.org>
Reply-To: Edwin Groothuis <edwin@mavetju.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] let link_elf_error show the name of the module which couldn't be loaded.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         121276
>Category:       kern
>Synopsis:       [kernel] [patch] let link_elf_error show the name of the module which couldn't be loaded.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    edwin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 02 01:20:00 UTC 2008
>Closed-Date:    Tue Jul 15 01:30:04 UTC 2008
>Last-Modified:  Tue Jul 15 01:30:09 UTC 2008
>Originator:     Edwin Groothuis
>Release:        FreeBSD 6.3-RELEASE i386
>Organization:
-
>Environment:
System: FreeBSD k7.mavetju 6.3-RELEASE FreeBSD 6.3-RELEASE #0: Sun Feb 17 22:11:52 EST 2008 edwin@k7.mavetju:/usr/src/sys/i386/compile/SMP i386


>Description:

After the upgrade of 6.2 to 6.3 I get some warnings on my console:

kldload: Unsupported file type
kldload: Unsupported file type

I couldn't figure out which file it was, so I changed link_elf_error()
to display the filename:

kldload: /boot/modules/test.ko: Unsupported file type
kldload: /boot/modules/test1.ko: Unsupported file type

>How-To-Repeat:
>Fix:

In src/sys/kern: 

--- link_elf.c.orig	2008-03-02 11:52:39.000000000 +1100
+++ link_elf.c	2008-03-02 11:53:42.000000000 +1100
@@ -213,9 +213,12 @@
 extern struct _dynamic _DYNAMIC;
 
 static void
-link_elf_error(const char *s)
+link_elf_error(const char *filename, const char *s)
 {
-    printf("kldload: %s\n", s);
+	if (filename == NULL)
+		printf("kldload: %s\n", s);
+	else
+		printf("kldload: %s: %s\n", filename, s);
 }
 
 /*
@@ -599,23 +602,23 @@
 
     if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
       || hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
-	link_elf_error("Unsupported file layout");
+	link_elf_error(filename, "Unsupported file layout");
 	error = ENOEXEC;
 	goto out;
     }
     if (hdr->e_ident[EI_VERSION] != EV_CURRENT
       || hdr->e_version != EV_CURRENT) {
-	link_elf_error("Unsupported file version");
+	link_elf_error(filename, "Unsupported file version");
 	error = ENOEXEC;
 	goto out;
     }
     if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN) {
-	link_elf_error("Unsupported file type");
+	link_elf_error(filename, "Unsupported file type");
 	error = ENOEXEC;
 	goto out;
     }
     if (hdr->e_machine != ELF_TARG_MACH) {
-	link_elf_error("Unsupported machine");
+	link_elf_error(filename, "Unsupported machine");
 	error = ENOEXEC;
 	goto out;
     }
@@ -628,7 +631,7 @@
     if (!((hdr->e_phentsize == sizeof(Elf_Phdr)) &&
 	  (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= PAGE_SIZE) &&
 	  (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= nbytes)))
-	link_elf_error("Unreadable program headers");
+	link_elf_error(filename, "Unreadable program headers");
 
     /*
      * Scan the program header entries, and save key information.
@@ -646,7 +649,7 @@
 
 	case PT_LOAD:
 	    if (nsegs == MAXSEGS) {
-		link_elf_error("Too many sections");
+		link_elf_error(filename, "Too many sections");
 		error = ENOEXEC;
 		goto out;
 	    }
@@ -666,7 +669,7 @@
 	    break;
 
 	case PT_INTERP:
-	    link_elf_error("Unsupported file type");
+	    link_elf_error(filename, "Unsupported file type");
 	    error = ENOEXEC;
 	    goto out;
 	}
@@ -674,12 +677,12 @@
 	++phdr;
     }
     if (phdyn == NULL) {
-	link_elf_error("Object is not dynamically-linked");
+	link_elf_error(filename, "Object is not dynamically-linked");
 	error = ENOEXEC;
 	goto out;
     }
     if (nsegs == 0) {
-	link_elf_error("No sections");
+	link_elf_error(filename, "No sections");
 	error = ENOEXEC;
 	goto out;
     }
--- link_elf_obj.c.orig	2008-03-02 12:06:16.000000000 +1100
+++ link_elf_obj.c	2008-03-02 12:07:16.000000000 +1100
@@ -151,9 +151,12 @@
 static int	relocate_file(elf_file_t ef);
 
 static void
-link_elf_error(const char *s)
+link_elf_error(const char *filename, const char *s)
 {
-	printf("kldload: %s\n", s);
+	if (filename == NULL)
+		printf("kldload: %s\n", s);
+	else
+		printf("kldload: %s: %s\n", filename, s);
 }
 
 static void
@@ -437,23 +440,23 @@
 
 	if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
 	    || hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
-		link_elf_error("Unsupported file layout");
+		link_elf_error(filename, "Unsupported file layout");
 		error = ENOEXEC;
 		goto out;
 	}
 	if (hdr->e_ident[EI_VERSION] != EV_CURRENT
 	    || hdr->e_version != EV_CURRENT) {
-		link_elf_error("Unsupported file version");
+		link_elf_error(filename, "Unsupported file version");
 		error = ENOEXEC;
 		goto out;
 	}
 	if (hdr->e_type != ET_REL) {
-		link_elf_error("Unsupported file type");
+		link_elf_error(filename, "Unsupported file type");
 		error = ENOEXEC;
 		goto out;
 	}
 	if (hdr->e_machine != ELF_TARG_MACH) {
-		link_elf_error("Unsupported machine");
+		link_elf_error(filename, "Unsupported machine");
 		error = ENOEXEC;
 		goto out;
 	}
@@ -517,19 +520,19 @@
 		}
 	}
 	if (ef->nprogtab == 0) {
-		link_elf_error("file has no contents");
+		link_elf_error(filename, "file has no contents");
 		error = ENOEXEC;
 		goto out;
 	}
 	if (nsym != 1) {
 		/* Only allow one symbol table for now */
-		link_elf_error("file has no valid symbol table");
+		link_elf_error(filename, "file has no valid symbol table");
 		error = ENOEXEC;
 		goto out;
 	}
 	if (symstrindex < 0 || symstrindex > hdr->e_shnum ||
 	    shdr[symstrindex].sh_type != SHT_STRTAB) {
-		link_elf_error("file has invalid symbol strings");
+		link_elf_error(filename, "file has invalid symbol strings");
 		error = ENOEXEC;
 		goto out;
 	}
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: grog 
Responsible-Changed-When: Sun Mar 2 06:30:55 UTC 2008 
Responsible-Changed-Why:  
Submitter is a committer, so he can process this PR himself. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121276 

From: Edwin Groothuis <edwin@mavetju.org>
To: FreeBSD Gnats Submit <freebsd-gnats-submit@freebsd.org>
Cc:  
Subject: kern/121276: [kernel] [patch] let link_elf_error show the name of the module which couldn't be loaded.
Date: Wed, 25 Jun 2008 15:52:36 +1000

 Against a new current which has kern_ctf (yay for jb@)
 
 Index: kern_ctf.c
 ===================================================================
 --- kern_ctf.c	(revision 179467)
 +++ kern_ctf.c	(working copy)
 @@ -323,3 +323,12 @@
  
  	return (error);
  }
 +
 +void
 +link_elf_error(const char *filename, const char *s)
 +{
 +	if (filename == NULL)
 +		printf("kldload: %s\n", s);
 +	else
 +		printf("kldload: %s: %s\n", filename, s);
 +}
 Index: link_elf_obj.c
 ===================================================================
 --- link_elf_obj.c	(revision 179467)
 +++ link_elf_obj.c	(working copy)
 @@ -170,12 +170,6 @@
  static int	relocate_file(elf_file_t ef);
  
  static void
 -link_elf_error(const char *s)
 -{
 -	printf("kldload: %s\n", s);
 -}
 -
 -static void
  link_elf_init(void *arg)
  {
  
 @@ -460,23 +454,23 @@
  
  	if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
  	    || hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
 -		link_elf_error("Unsupported file layout");
 +		link_elf_error(filename, "Unsupported file layout");
  		error = ENOEXEC;
  		goto out;
  	}
  	if (hdr->e_ident[EI_VERSION] != EV_CURRENT
  	    || hdr->e_version != EV_CURRENT) {
 -		link_elf_error("Unsupported file version");
 +		link_elf_error(filename, "Unsupported file version");
  		error = ENOEXEC;
  		goto out;
  	}
  	if (hdr->e_type != ET_REL) {
 -		link_elf_error("Unsupported file type");
 +		link_elf_error(filename, "Unsupported file type");
  		error = ENOEXEC;
  		goto out;
  	}
  	if (hdr->e_machine != ELF_TARG_MACH) {
 -		link_elf_error("Unsupported machine");
 +		link_elf_error(filename, "Unsupported machine");
  		error = ENOEXEC;
  		goto out;
  	}
 @@ -540,19 +534,19 @@
  		}
  	}
  	if (ef->nprogtab == 0) {
 -		link_elf_error("file has no contents");
 +		link_elf_error(filename, "file has no contents");
  		error = ENOEXEC;
  		goto out;
  	}
  	if (nsym != 1) {
  		/* Only allow one symbol table for now */
 -		link_elf_error("file has no valid symbol table");
 +		link_elf_error(filename, "file has no valid symbol table");
  		error = ENOEXEC;
  		goto out;
  	}
  	if (symstrindex < 0 || symstrindex > hdr->e_shnum ||
  	    shdr[symstrindex].sh_type != SHT_STRTAB) {
 -		link_elf_error("file has invalid symbol strings");
 +		link_elf_error(filename, "file has invalid symbol strings");
  		error = ENOEXEC;
  		goto out;
  	}
 Index: link_elf.c
 ===================================================================
 --- link_elf.c	(revision 179467)
 +++ link_elf.c	(working copy)
 @@ -231,12 +231,6 @@
   */
  extern struct _dynamic _DYNAMIC;
  
 -static void
 -link_elf_error(const char *s)
 -{
 -    printf("kldload: %s\n", s);
 -}
 -
  /*
   * Actions performed after linking/loading both the preloaded kernel and any
   * modules; whether preloaded or dynamicly loaded.
 @@ -624,23 +618,23 @@
  
      if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
        || hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
 -	link_elf_error("Unsupported file layout");
 +	link_elf_error(filename, "Unsupported file layout");
  	error = ENOEXEC;
  	goto out;
      }
      if (hdr->e_ident[EI_VERSION] != EV_CURRENT
        || hdr->e_version != EV_CURRENT) {
 -	link_elf_error("Unsupported file version");
 +	link_elf_error(filename, "Unsupported file version");
  	error = ENOEXEC;
  	goto out;
      }
      if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN) {
 -	link_elf_error("Unsupported file type");
 +	link_elf_error(filename, "Unsupported file type");
  	error = ENOEXEC;
  	goto out;
      }
      if (hdr->e_machine != ELF_TARG_MACH) {
 -	link_elf_error("Unsupported machine");
 +	link_elf_error(filename, "Unsupported machine");
  	error = ENOEXEC;
  	goto out;
      }
 @@ -653,7 +647,7 @@
      if (!((hdr->e_phentsize == sizeof(Elf_Phdr)) &&
  	  (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= PAGE_SIZE) &&
  	  (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= nbytes)))
 -	link_elf_error("Unreadable program headers");
 +	link_elf_error(filename, "Unreadable program headers");
  
      /*
       * Scan the program header entries, and save key information.
 @@ -671,7 +665,7 @@
  
  	case PT_LOAD:
  	    if (nsegs == MAXSEGS) {
 -		link_elf_error("Too many sections");
 +		link_elf_error(filename, "Too many sections");
  		error = ENOEXEC;
  		goto out;
  	    }
 @@ -691,7 +685,7 @@
  	    break;
  
  	case PT_INTERP:
 -	    link_elf_error("Unsupported file type");
 +	    link_elf_error(filename, "Unsupported file type");
  	    error = ENOEXEC;
  	    goto out;
  	}
 @@ -699,12 +693,12 @@
  	++phdr;
      }
      if (phdyn == NULL) {
 -	link_elf_error("Object is not dynamically-linked");
 +	link_elf_error(filename, "Object is not dynamically-linked");
  	error = ENOEXEC;
  	goto out;
      }
      if (nsegs == 0) {
 -	link_elf_error("No sections");
 +	link_elf_error(filename, "No sections");
  	error = ENOEXEC;
  	goto out;
      }
 
 -- 
 Edwin Groothuis      |            Personal website: http://www.mavetju.org
 edwin@mavetju.org    |              Weblog: http://www.mavetju.org/weblog/
State-Changed-From-To: open->patched 
State-Changed-By: edwin 
State-Changed-When: Tue Jul 8 23:52:47 UTC 2008 
State-Changed-Why:  
Commit to HEAD 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121276 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/121276: commit references a PR
Date: Tue,  8 Jul 2008 23:52:00 +0000 (UTC)

 edwin       2008-07-08 23:51:38 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/kern             link_elf.c link_elf_obj.c 
   Log:
   SVN rev 180374 on 2008-07-08 23:51:38Z by edwin
   
   Improve the output of kldload(8) to show which module can't be loaded.
   
   Was:            kldload: Unsupported file type
   Is now:         kldload: /boot/modules/test.ko: Unsupported file type
   
   PR:             kern/121276
   Submitted by:   Edwin Groothuis <edwin@mavetju.org>
   Approved by:    bde (mentor)
   MFC after:      1 week
   
   Revision  Changes    Path
   1.98      +14 -11    src/sys/kern/link_elf.c
   1.101     +12 -9     src/sys/kern/link_elf_obj.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: edwin 
State-Changed-When: Tue Jul 15 01:29:50 UTC 2008 
State-Changed-Why:  
Commitd. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121276 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/121276: commit references a PR
Date: Tue, 15 Jul 2008 01:26:52 +0000 (UTC)

 edwin       2008-07-15 01:26:20 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     sys/kern             link_elf.c link_elf_obj.c 
   Log:
   SVN rev 180521 on 2008-07-15 01:26:20Z by edwin
   
   MFC of r180374
   
   Improve the output of kldload(8) to show which module can't be loaded.
   
   Was:            kldload: Unsupported file type
   Is now:         kldload: /boot/modules/test.ko: Unsupported file type
   
   PR:             kern/121276
   Submitted by:   Edwin Groothuis <edwin@mavetju.org>
   Approved by:    bde (mentor)
   MFC after:      1 week
   
   Revision  Changes    Path
   1.81.8.7  +14 -11    src/sys/kern/link_elf.c
   1.87.2.5  +12 -9     src/sys/kern/link_elf_obj.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/121276: commit references a PR
Date: Tue, 15 Jul 2008 01:28:38 +0000 (UTC)

 edwin       2008-07-15 01:28:14 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sys/kern             link_elf.c link_elf_obj.c 
   Log:
   SVN rev 180522 on 2008-07-15 01:28:14Z by edwin
   
   MFC of r180374
   
   Improve the output of kldload(8) to show which module can't be loaded.
   
   Was:            kldload: Unsupported file type
   Is now:         kldload: /boot/modules/test.ko: Unsupported file type
   
   PR:             kern/121276
   Submitted by:   Edwin Groothuis <edwin@mavetju.org>
   Approved by:    bde (mentor)
   MFC after:      1 week
   
   Revision  Changes    Path
   1.93.2.2  +14 -11    src/sys/kern/link_elf.c
   1.95.2.2  +12 -9     src/sys/kern/link_elf_obj.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:

grog, 2 March 2008

	Assigned to submitter.
