Skip site navigation (1)Skip section navigation (2)
Date:      Sun,  2 Mar 2008 12:12:59 +1100 (EST)
From:      Edwin Groothuis <edwin@mavetju.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/121276: [patch] let link_elf_error show the name of the module which couldn't be loaded.
Message-ID:  <20080302011259.74F6413B@k7.mavetju>
Resent-Message-ID: <200803020120.m221K12V040502@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         121276
>Category:       kern
>Synopsis:       [patch] let link_elf_error show the name of the module which couldn't be loaded.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 02 01:20:00 UTC 2008
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080302011259.74F6413B>