From nsmart@indigo.ie  Sat Aug 29 15:23:21 1998
Received: from indigo.ie (ts01-004.dublin.indigo.ie [194.125.134.14])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA12681
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 29 Aug 1998 15:23:16 -0700 (PDT)
          (envelope-from nsmart@indigo.ie)
Received: (from nsmart@localhost)
	by indigo.ie (8.8.8/8.8.7) id XAA03397;
	Sat, 29 Aug 1998 23:16:29 +0100 (IST)
	(envelope-from nsmart)
Message-Id: <199808292216.XAA03397@indigo.ie>
Date: Sat, 29 Aug 1998 23:16:29 +0100 (IST)
From: rotel@indigo.ie
Reply-To: rotel@indigo.ie
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] modload should detect stripped kernels and use consistent option names
X-Send-Pr-Version: 3.2

>Number:         7779
>Category:       bin
>Synopsis:       [PATCH] modload should detect stripped kernels and use consistent option names
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 29 15:30:01 PDT 1998
>Closed-Date:    Sun Aug 6 11:47:42 PDT 2000
>Last-Modified:  Sun Aug 06 11:47:54 PDT 2000
>Originator:     Niall Smart
>Release:        FreeBSD 2.2.7-STABLE i386
>Organization:
>Environment:


>Description:

This patch addresses two problems:

 1) modload should fail more intelligently when the kernel has no
    symbols; I inadvertantly forgot the -d argument to strip
    when stripping down the kernel after a config -g and it
    took me a while to figure out what was happening. :)
    
 2) modload should use -N to specify the kernel file as per ps,
    fstat, ccdconfig, dmesg, vmstat, pstat, swapinfo, iostat,
    ncrcontrol, ipcs, netstat, nfsstat and w.  -A is provided
    for backwards compatability.
    
    (ahh, perfection)

>How-To-Repeat:

	strip -d /kernel
	modload -N /kernel /lkm/linux_mod.o

>Fix:

Index: modload.8
===================================================================
RCS file: /cvs/src/sbin/modload/modload.8,v
retrieving revision 1.11
diff -c -r1.11 modload.8
*** modload.8	1998/03/19 07:45:37	1.11
--- modload.8	1998/08/29 22:11:08
***************
*** 34,40 ****
  .Sh SYNOPSIS
  .Nm modload
  .Op Fl dquv
! .Op Fl A Ar kernel
  .Op Fl e Ar entry
  .Op Fl p Ar postinstall
  .Op Fl o Ar output_file
--- 34,40 ----
  .Sh SYNOPSIS
  .Nm modload
  .Op Fl dquv
! .Op Fl N Ar kernel
  .Op Fl e Ar entry
  .Op Fl p Ar postinstall
  .Op Fl o Ar output_file
***************
*** 62,72 ****
  temporary file to be kept rather than deleted.
  .It Fl v
  Print comments about the loading process.
! .It Fl A Ar kernel
  Specify the file that is passed to the linker
  to resolve module references to external symbols. 
  The symbol file must be for the currently running
  kernel or the module is likely to crash the system.
  .It Fl e Ar entry
  Specify the module entry point.
  This is passed by
--- 62,75 ----
  temporary file to be kept rather than deleted.
  .It Fl v
  Print comments about the loading process.
! .It Fl N Ar kernel
  Specify the file that is passed to the linker
  to resolve module references to external symbols. 
  The symbol file must be for the currently running
  kernel or the module is likely to crash the system.
+ The option
+ .Fl A
+ is synonymous and provided for backwards compatability.
  .It Fl e Ar entry
  Specify the module entry point.
  This is passed by
Index: modload.c
===================================================================
RCS file: /cvs/src/sbin/modload/modload.c,v
retrieving revision 1.23
diff -c -r1.23 modload.c
*** modload.c	1998/08/12 02:39:23	1.23
--- modload.c	1998/08/29 22:11:10
***************
*** 62,68 ****
  /*
   * Expected linker options:
   *
!  * -A		executable to link against
   * -e		entry point
   * -o		output file
   * -T		address to link to in hex (assumes it's a page boundry)
--- 62,68 ----
  /*
   * Expected linker options:
   *
!  * -N		executable to link against
   * -e		entry point
   * -o		output file
   * -T		address to link to in hex (assumes it's a page boundry)
***************
*** 78,89 ****
  	char addrbuf[32], entrybuf[_POSIX2_LINE_MAX];
  	pid_t pid;
  	int status;
  
  	snprintf(entrybuf, sizeof entrybuf, "_%s", entry);
  	snprintf(addrbuf, sizeof addrbuf, "%x", address);
  
  	if (debug)
! 		printf("%s -A %s -e %s -o %s -T %s %s\n",
  		       _PATH_LD, kernel, entrybuf, outfile,
  		       addrbuf, object);
  
--- 78,100 ----
  	char addrbuf[32], entrybuf[_POSIX2_LINE_MAX];
  	pid_t pid;
  	int status;
+ 	struct exec	se;
+ 	int		fd;
+ 	
+ 	if ( (fd = open(kernel, O_RDONLY, 0)) < 0)
+ 		err(1, "open: %s", kernel);
+ 	
+ 	if (read(fd, &se, sizeof(se)) != sizeof(se))
+ 		errx(1, "cannot read exec structure: file too small: %s", kernel);
+ 	
+ 	if (se.a_syms == 0)
+ 		errx(1, "cannot load module: no debugging symbols found in %s", kernel);
  
  	snprintf(entrybuf, sizeof entrybuf, "_%s", entry);
  	snprintf(addrbuf, sizeof addrbuf, "%x", address);
  
  	if (debug)
! 		printf("%s -N %s -e %s -o %s -T %s %s\n",
  		       _PATH_LD, kernel, entrybuf, outfile,
  		       addrbuf, object);
  
***************
*** 121,127 ****
  {
  
  	fprintf(stderr, 
! 	    "usage: modload [-d] [-v] [-q] [-u] [-A <kernel>] [-e <entry]\n");
  	fprintf(stderr,
  	    "               [-p <postinstall>] [-o <output file>] <input file>\n");
  	exit(1);
--- 132,138 ----
  {
  
  	fprintf(stderr, 
! 	    "usage: modload [-d] [-v] [-q] [-u] [-N <kernel>] [-e <entry]\n");
  	fprintf(stderr,
  	    "               [-p <postinstall>] [-o <output file>] <input file>\n");
  	exit(1);
***************
*** 174,180 ****
  	int sz, bytesleft;
  	char buf[MODIOBUF];
  
! 	while ((c = getopt(argc, argv, "dvquA:e:p:o:")) != -1) {
  		switch (c) {
  		case 'd':
  			debug = 1;
--- 185,191 ----
  	int sz, bytesleft;
  	char buf[MODIOBUF];
  
! 	while ((c = getopt(argc, argv, "dvquA:N:e:p:o:")) != -1) {
  		switch (c) {
  		case 'd':
  			debug = 1;
***************
*** 188,194 ****
  		case 'q':
  			quiet = 1;
  			break;
! 		case 'A':
  			kname = optarg;
  			break;	/* kernel */
  		case 'e':
--- 199,206 ----
  		case 'q':
  			quiet = 1;
  			break;
! 		case 'A':	/* deprecated, use -N */
! 		case 'N':
  			kname = optarg;
  			break;	/* kernel */
  		case 'e':
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: nbm 
State-Changed-When: Fri Jun 23 08:18:44 PDT 2000 
State-Changed-Why:  
Does kldload need these changes, since modload is no more? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=7779 
State-Changed-From-To: feedback->closed 
State-Changed-By: nbm 
State-Changed-When: Sun Aug 6 11:47:42 PDT 2000 
State-Changed-Why:  
Feedback timeout. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=7779 
>Unformatted:
