NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/42479: netbsd-5-0 tools config(1) generates bad config_file.h on i386 5.99.22



>Number:         42479
>Category:       toolchain
>Synopsis:       netbsd-5-0 tools config(1) generates bad config_file.h on i386 
>5.99.22
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 19 17:00:01 +0000 2009
>Originator:     Izumi Tsutsui
>Release:        NetBSD 5.99.22, updated around 20091213
>Organization:
>Environment:
System: NetBSD mirage 5.99.22: Sun Dec 13 19:02:02 JST 2009
Architecture: i386
Machine: i386
>Description:
When I tried to build netbsd-5-0's NetBSD/arc ISO image by
"build.sh -m arc -U -u release iso-image" command on
NetBSD/i386 5.99.22 host, it failed during compiling GENERIC kernel:

---
 :
#   compile  GENERIC/param.o
/r/work/netbsd-5-0/src/obj.arc/tooldir.NetBSD-5.99.22-i386/bin/mipsel--netbsd-gcc
 \
-G 0 -mno-abicalls -msoft-float -ffixed-23 -ffreestanding \
-fno-zero-initialized-in-bss -O2 -std=gnu99 -fno-strict-aliasing \
-Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith \
-Wmissing-prototypes -Wstrict-prototypes -Wswitch -Wshadow -Wcast-qual \
-Wwrite-strings -Wno-unreachable-code -Wno-sign-compare -Wno-pointer-sign \
-Wno-attributes -Werror -march=mips3 -mabi=32 -Darc -I. \
-I../../../../../common/include -I../../../../arch -I../../../.. \
-nostdinc -DMIPS3 -DMIPS3_ENABLE_CLOCK_INTR -DLKM -DMAXUSERS=32 -D_KERNEL \
-D_KERNEL_OPT -I../../../../lib/libkern/../../../common/lib/libc/quad \
-I../../../../lib/libkern/../../../common/lib/libc/string \
-I../../../../lib/libkern/../../../common/lib/libc/arch/mips/string \
-I../../../../dist/ipf -c param.c
In file included from param.c:77:
config_file.h:30: error: expected ',' or ';' before '_CFG_'
config_file.h:30: error: stray '\' in program
config_file.h:30: error: missing terminating " character
config_file.h:35: error: stray '##' in program
config_file.h:35: error: stray '#' in program
config_file.h:35: error: stray '##' in program
config_file.h:35: error: stray '#' in program
config_file.h:35: error: stray '##' in program

 :

*** Failed target:  param.o

 :

Stop.
nbmake: stopped in /r/work/netbsd-5-0/src/sys/arch/arc/compile/GENERIC
---

config_file.h generated by ${TOOLDIR}/bin/nbconfig seems corrupted:
---
#include <sys/cdefs.h>

#include "opt_config.h"

/*
 * Add either (or both) of
 *
 *      options INCLUDE_CONFIG_FILE
 *      options INCLUDE_JUST_CONFIG
 *
 * to your kernel config file to embed it in the resulting
 * kernel.  The latter option does not include files that are
 * included (recursively) by your config file.  The embedded
 * data be extracted by using the command:
 *
 *      strings netbsd | sed -n 's/^_CFG_//p' | unvis
 */

#ifdef CONFIG_FILE
#if defined(INCLUDE_CONFIG_FILE) || defined(INCLUDE_JUST_CONFIG)

static const char config[] __used =

#ifdef INCLUDE_CONFIG_FILE

"_CFG_### START CONFIG FILE \"GENERIC\"\n"

#endif /* INCLUDE_CONFIG_FILE */

"_CFG_"_CFG_"_CFG_"_CFG_"_CFG_"_CFG_"_CFG_"_CFG_" [...too long...] _CFG_\n"
#ifdef INCLUDE_CONFIG_FILE

"_CFG_### END CONFIG FILE \"GENERIC\"\n"
"_CFG_### (included from \"arch/arc/conf/std.arc\")\n"
"_CFG_###> "_CFG_###> "_CFG_###> "_CFG_###> "_CFG_###> [....] "_CFG_###> \n"
"_CFG_### (end include \"arch/arc/conf/std.arc\")\n"
"_CFG_### (included from \"conf/std\")\n"
"_CFG_###> "_CFG_###> "_CFG_###> "_CFG_###> "_CFG_###> [...] "_CFG_###> \n"
"_CFG_### (end include \"conf/std\")\n"
#endif /* INCLUDE_CONFIG_FILE */
;
#endif /* INCLUDE_CONFIG_FILE || INCLUDE_JUST_CONFIG */
#endif /* CONFIG_FILE */
---

and nbconfig actually complains as following:
---
% /work/netbsd-5-0/src/obj.arc/tooldir.NetBSD-5.99.22-i386/bin/nbconfig GENERIC
nbconfig: GENERIC: newline missing at EOF
nbconfig: arch/arc/conf/std.arc: newline missing at EOF
nbconfig: conf/std: newline missing at EOF
Build directory is ../compile/GENERIC
Don't forget to run "make depend"
% 
---

These warnings are come from src/usr.bin/config/main.c:logconfig_include()
---
void
logconfig_include(FILE *cf, const char *filename)
{
        char line[1024], in[2048], *out;
        struct stat st;
        int missingeol;

        if (!cfg)
                return;

        missingeol = 0;
        if (fstat(fileno(cf), &st) == -1)
                return;
        if (cfgtime < st.st_mtime)
                cfgtime = st.st_mtime;

        if (filename)
                (void)fprintf(cfg,
                    "\"_CFG_### (included from \\\"%s\\\")\\n\"\n",
                    filename);
        while (fgets(line, sizeof(line), cf) != NULL) {
                missingeol = 1;
                (void)fprintf(cfg, "\"_CFG_");
                if (filename)
                        (void)fprintf(cfg, "###> ");
--->            strvis(in, line, VIS_TAB);
                for (out = in; *out; out++)
                        switch (*out) {
                        case '\n':
                                (void)fprintf(cfg, "\\n\"\n");
                                missingeol = 0;
                                break;
                        case '"': case '\\':
                                (void)fputc('\\', cfg);
                                /* FALLTHROUGH */
                        default:
                                (void)fputc(*out, cfg);
                                break;
                        }
        }
        if (missingeol) {
                (void)fprintf(cfg, "\\n\"\n");
                warnx("%s: newline missing at EOF",
                    filename != NULL ? filename : conffile);
        }
        if (filename)
                (void)fprintf(cfg, "\"_CFG_### (end include \\\"%s\\\")\\n\"\n",
                    filename);

        rewind(cf);
}
---

"strvis(in, line, VIS_TAB);" seems to return NUL into "in" pointer.

- netbsd-5-0 nbconfig built on 5.99.15 didn't have problem.
- Using strvis(3) in libc (not in libnbcompat, by -lc) fixes the problem.
- Compiling vis.c with -O0 in src/tools/compat also fixes the problem.
- Pulling src/lib/libc/gen/vis.c rev 1.39 (and 1.40) also fixes the problem.

Looks like compiler's bug, but triggered by new binutils?

>How-To-Repeat:
- get netbsd-5-0 source tree on NetBSD/i386 5.99.22 host
- build.sh -m arc release
- then will get the above errors.

>Fix:
Probably we should track and fix gcc or binutils bugs,
but for now easist workaround is to partially pull vis.c changes
(replacing conditionals with a function pointer, but excluding
 MIMESTYLE support) in rev 1.39 and 1.40, which also avoid this bug?

Index: lib/libc/gen/vis.c
===================================================================
RCS file: /cvsroot/src/lib/libc/gen/vis.c,v
retrieving revision 1.38
diff -u -r1.38 vis.c
--- lib/libc/gen/vis.c  4 Sep 2008 09:41:44 -0000       1.38
+++ lib/libc/gen/vis.c  19 Dec 2009 16:47:11 -0000
@@ -91,6 +91,7 @@
 #define iswhite(c)     (c == ' ' || c == '\t' || c == '\n')
 #define issafe(c)      (c == '\b' || c == BELL || c == '\r')
 #define xtoa(c)                "0123456789abcdef"[c]
+#define XTOA(c)                "0123456789ABCDEF"[c]
 
 #define MAXEXTRAS      5
 
@@ -211,6 +212,18 @@
        return dst;
 }
 
+typedef char *(*visfun_t)(char *, int, int, int, const char *);
+
+/*
+ * Return the appropriate encoding function depending on the flags given.
+ */
+static visfun_t
+getvisfun(int flag)
+{
+       if (flag & VIS_HTTPSTYLE)
+               return do_hvis;
+       return do_svis;
+}
 
 /*
  * svis - visually encode characters, also encoding the characters
@@ -220,6 +233,7 @@
 svis(char *dst, int c, int flag, int nextc, const char *extra)
 {
        char *nextra = NULL;
+       visfun_t f;
 
        _DIAGASSERT(dst != NULL);
        _DIAGASSERT(extra != NULL);
@@ -228,10 +242,8 @@
                *dst = '\0';            /* can't create nextra, return "" */
                return dst;
        }
-       if (flag & VIS_HTTPSTYLE)
-               dst = do_hvis(dst, c, flag, nextc, nextra);
-       else
-               dst = do_svis(dst, c, flag, nextc, nextra);
+       f = getvisfun(flag);
+       dst = (*f)(dst, c, flag, nextc, nextra);
        free(nextra);
        *dst = '\0';
        return dst;
@@ -260,6 +272,7 @@
        char *start;
        char *nextra = NULL;
        const unsigned char *src = (const unsigned char *)csrc;
+       visfun_t f;
 
        _DIAGASSERT(dst != NULL);
        _DIAGASSERT(src != NULL);
@@ -269,16 +282,12 @@
                *dst = '\0';            /* can't create nextra, return "" */
                return 0;
        }
-       if (flag & VIS_HTTPSTYLE) {
-               for (start = dst; (c = *src++) != '\0'; /* empty */)
-                       dst = do_hvis(dst, c, flag, *src, nextra);
-       } else {
-               for (start = dst; (c = *src++) != '\0'; /* empty */)
-                       dst = do_svis(dst, c, flag, *src, nextra);
-       }
+       f = getvisfun(flag);
+       for (start = dst; (c = *src++) != '\0'; /* empty */)
+               dst = (*f)(dst, c, flag, *src, nextra);
        free(nextra);
        *dst = '\0';
-       return (dst - start);
+       return (int)(dst - start);
 }
 
 
@@ -289,6 +298,7 @@
        char *start;
        char *nextra = NULL;
        const unsigned char *src = (const unsigned char *)csrc;
+       visfun_t f;
 
        _DIAGASSERT(dst != NULL);
        _DIAGASSERT(src != NULL);
@@ -299,22 +309,14 @@
                return 0;
        }
 
-       if (flag & VIS_HTTPSTYLE) {
-               for (start = dst; len > 0; len--) {
-                       c = *src++;
-                       dst = do_hvis(dst, c, flag,
-                           len > 1 ? *src : '\0', nextra);
-               }
-       } else {
-               for (start = dst; len > 0; len--) {
-                       c = *src++;
-                       dst = do_svis(dst, c, flag,
-                           len > 1 ? *src : '\0', nextra);
-               }
+       f = getvisfun(flag);
+       for (start = dst; len > 0; len--) {
+               c = *src++;
+               dst = (*f)(dst, c, flag, len > 1 ? *src : '\0', nextra);
        }
        free(nextra);
        *dst = '\0';
-       return (dst - start);
+       return (int)(dst - start);
 }
 #endif
 
@@ -327,6 +329,7 @@
 {
        char *extra = NULL;
        unsigned char uc = (unsigned char)c;
+       visfun_t f;
 
        _DIAGASSERT(dst != NULL);
 
@@ -335,10 +338,8 @@
                *dst = '\0';            /* can't create extra, return "" */
                return dst;
        }
-       if (flag & VIS_HTTPSTYLE)
-               dst = do_hvis(dst, uc, flag, nextc, extra);
-       else
-               dst = do_svis(dst, uc, flag, nextc, extra);
+       f = getvisfun(flag);
+       dst = (*f)(dst, uc, flag, nextc, extra);
        free(extra);
        *dst = '\0';
        return dst;

---
Izumi Tsutsui



Home | Main Index | Thread Index | Old Index