Subject: toolchain/23340: ld.elf_so only supports sysctl's under machdep
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <roskens@elfin.net>
List: netbsd-bugs
Date: 11/02/2003 05:16:07
>Number:         23340
>Category:       toolchain
>Synopsis:       ld.elf_so only supports sysctl's under machdep
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 02 05:17:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Ron Roskens
>Release:        -current
>Organization:
>Environment:
NetBSD hysteria.tx.elfin.net 1.6ZD NetBSD 1.6ZD (GENERIC) #19: Wed Oct 22 18:35:02 CDT 2003  root@speedy.tx.elfin.net:/obj/sys/arch/i386/compile/GENERIC i386

>Description:
I've been playing around with pkgsrc sandboxes, doing bulk builds under a 
-current base. Wanting to test patches against release version of netbsd, 
I've looked into using libkver to alter what uname/sysctl return for the  
OS release. Not much information is provided by that package, other than a 
shared library. So my first thought was to add an entry into ld.so.conf   
and have it happen dynamically when libc.so is loaded, rather than export 
LD_PRELOAD=/usr/lib/libkver.so.

According to ld.so.conf's man page, if you specify a library name, its    
followed by a "sysctl_variable" then "value:libraries..." Unfortunately,  
this is only partly true. It only works for sysctl variables whose names 
are under "machdep".
>How-To-Repeat:
Best way to do this is to install pkgsrc/pkgtools/libkver and run a bulk build for an older release of netbsd.
>Fix:
The following patch allows ld.elf_so to use any sysctl variable under the "kern" prefix. It removes the unused define CTL_MACHDEP_SIZE. It ensures that when working through the sysctl list that there is a valid name. (CTL_KERN_NAMES has a {0,0} entry in the middle.) and finally, it correctly ensures that if a match is not found inside one list, it continues on to the next.


--- src/libexec/ld.elf_so/paths.c.orig     2003-07-24 05:12:26.000000000 -0500
+++ src/libexec/ld.elf_so/paths.c       2003-11-01 22:40:42.000000000 -0600
@@ -138,6 +138,7 @@
 #ifdef CTL_MACHDEP_NAMES
 static const struct sysctldesc ctl_machdep[] = CTL_MACHDEP_NAMES;
 #endif
+static const struct sysctldesc ctl_kern[] = CTL_KERN_NAMES;
 static const struct sysctldesc ctl_toplvl[] = CTL_NAMES;
 
 const struct list toplevel[] = {
@@ -148,7 +149,7 @@
 
 const struct list secondlevel[] = {
        { 0, 0 },                       /* CTL_UNSPEC */
-       { 0, KERN_MAXID },              /* CTL_KERN */
+       { ctl_kern, KERN_MAXID },       /* CTL_KERN */
        { 0, VM_MAXID },                /* CTL_VM */
        { 0, VFS_MAXID },               /* CTL_VFS */
        { 0, NET_MAXID },               /* CTL_NET */
@@ -171,8 +172,6 @@
        0
 };
 
-#define CTL_MACHDEP_SIZE (sizeof(ctl_machdep) / sizeof(ctl_machdep[0]))
-
 /*
  * Process library mappings of the form:
  *     <library_name>  <machdep_variable> <value,...:library_name,...> ... 
@@ -219,6 +218,7 @@
                                continue;
 
                        for (k = 1; k < lists[i][j].numentries; k++) {
+                               if (lists[i][j].ctl[k].name != NULL)
                                if (strcmp(lists[i][j].ctl[k].name, l) == 0)
                                        break;
                        }
@@ -228,6 +228,9 @@
                                goto cleanup;
                        }
 
+                       if (lists[i][j].numentries == k)
+                               continue;
+
                        hwptr->ctl[hwptr->ctlmax] = k;
                        hwptr->ctltype[hwptr->ctlmax++] =
                            lists[i][j].ctl[k].type;

>Release-Note:
>Audit-Trail:
>Unformatted: