On Wed, Sep 13, 2017 at 08:34:56PM -0600, Theo de Raadt wrote:
> > If the attribute to force it into .data isn't wanted the alternative
> > gets messy as config has a bunch of bogus types and casts and treats the
> > int values as longs.
> 
> Well, I believe that messiness is a result of trying to avoid the
> consequences of the ABI.  I feel the ABI shouldn't be exposed here
> and changing the compilers is wrong...
> 
> The -1 handling could be pushed to the very top.  At the very first
> moment anything in ukc runs, set it to 0.  No conditional logic later on.

Index: mkioconf.c
===================================================================
RCS file: /cvs/src/usr.sbin/config/mkioconf.c,v
retrieving revision 1.36
diff -u -p -U4 -r1.36 mkioconf.c
--- mkioconf.c  27 Oct 2016 14:33:30 -0000      1.36
+++ mkioconf.c  14 Sep 2017 02:11:17 -0000
@@ -182,9 +182,9 @@ static long loc[%d] = {", locators.used)
 #define MAXEXTRALOC 32\n\
 #endif\n\
 long extraloc[MAXEXTRALOC] = { -1 };\n\
 int nextraloc = MAXEXTRALOC;\n\
-int uextraloc = 0;\n") < 0);
+int uextraloc = -1;\n") < 0);
 }
 
 static int nlocnames, maxlocnames = 8;
 static char **locnames;
Index: ukc.c
===================================================================
RCS file: /cvs/src/usr.sbin/config/ukc.c,v
retrieving revision 1.22
diff -u -p -U4 -r1.22 ukc.c
--- ukc.c       19 Oct 2016 16:39:02 -0000      1.22
+++ ukc.c       14 Sep 2017 03:14:43 -0000
@@ -61,8 +61,9 @@ ukc(char *file, char *outfile, int uflag
        kvm_t *kd;
        char errbuf[_POSIX2_LINE_MAX];
        int histlen = 0, ok = 1;
        char history[1024], kversion[1024];
+       int *uextraloc;
 
        if (file == NULL) {
                warnx("no file specified");
                usage();
@@ -71,8 +72,18 @@ ukc(char *file, char *outfile, int uflag
        loadkernel(file);
 
        if (nlist(file, nl) == -1)
                errx(1, "nlist: %s", file);
+
+       /*
+        * uextraloc is initialised to -1 not 0 so it will be put in .data
+        * instead of .bss so config can modify it
+        */
+       if (nl[I_UEXTRALOC].n_type != 0) {
+               uextraloc = (int *)adjust((caddr_t)nl[I_UEXTRALOC].n_value);
+               if (*uextraloc == -1)
+                       *uextraloc = 0;
+       }
 
        if (uflag) {
                if ((kd = kvm_openfiles(NULL,NULL,NULL,O_RDONLY, errbuf)) == 0)
                        errx(1, "kvm_openfiles: %s", errbuf);

Reply via email to