[BusyBox] [PATCH] workaround GCC problem in ash.c 1.0.0-pre2 and -pre3

Junio C Hamano junkio at cox.net
Tue Sep 16 19:09:04 UTC 2003


This is essentially the same patch as I posted last week but
rediffed to make sure it applies to what is in the CVS.  I have
polled people who reported similar problem on the list since
-pre2 came out and asked them to see if the patch works around
their compilation problem.  So far, I got positive responses
from both of the two people who asked the question this month
(they work on mips64 and arm/xscale respectively) and also from
one person who asked the question last month (works on gentoo
sparc).  Obviously the patch fixes the problem for myself as
well (mips32).

The construct certain vintages of GCC (the one I have trouble
with is 3.2.3) have trouble with looks like the following:

    static struct st a;
    static struct st *p = &a;
    struct st { int foo; };
    static void init(void) { a.foo = 0; } 

The file shell/ash.c as shipped in -pre2 and -pre3 contains a
similar construct, and these compilers fail with an error
message like this:

    shell/ash.c:1681: Internal compiler error in int_mode_for_mode, at
    stor-layout.c:290

The problem disappears if we move the struct declaration up to
let the compiler know the shape of the struct before the first
definition uses it, like this:

    struct st { int foo; }; /* this has been moved up */
    static struct st a;
    static struct st *p = &a;
    static void init(void) { a.foo = 0; } 

The attached patch moves struct declarations to work around this
particular problem in shell/ash.c, and does nothing else.
Specifically, this does not disable inlines like suggested by
some on the list, so it does not hurt people with working
compilers; as reported on the list, disabling inlines did not
help for these compilers anyway.

In other words, for non-buggy compilers the change introduced by
this patch is a no-op, and for those unfortunate enough to be
stuck with such a compiler, it is a difference between not being
able to compile and being able to build and test.

Please apply.


--- a/shell/ash.c	2003-09-01 19:36:17.000000000 -0700
+++ b/shell/ash.c	2003-09-12 10:40:21.000000000 -0700
@@ -550,6 +550,29 @@
 
 /* next character in input buffer */
 static char *parsenextc;                /* copy of parsefile->nextc */
+
+struct strpush {
+	struct strpush *prev;   /* preceding string on stack */
+	char *prevstring;
+	int prevnleft;
+#ifdef CONFIG_ASH_ALIAS
+	struct alias *ap;       /* if push was associated with an alias */
+#endif
+	char *string;           /* remember the string since it may change */
+};
+
+struct parsefile {
+	struct parsefile *prev; /* preceding file on stack */
+	int linno;              /* current line */
+	int fd;                 /* file descriptor (or -1 if string) */
+	int nleft;              /* number of chars left in this line */
+	int lleft;              /* number of chars left in this buffer */
+	char *nextc;            /* next char in buffer */
+	char *buf;              /* input buffer */
+	struct strpush *strpush; /* for pushing strings at this level */
+	struct strpush basestrpush; /* so pushing one is fast */
+};
+
 static struct parsefile basepf;         /* top level input file */
 static char basebuf[IBUFSIZ];           /* buffer for top level input file */
 static struct parsefile *parsefile = &basepf;  /* current input file */
@@ -1573,28 +1596,6 @@
 
 static int loopnest;            /* current loop nesting level */
 
-struct strpush {
-	struct strpush *prev;   /* preceding string on stack */
-	char *prevstring;
-	int prevnleft;
-#ifdef CONFIG_ASH_ALIAS
-	struct alias *ap;       /* if push was associated with an alias */
-#endif
-	char *string;           /* remember the string since it may change */
-};
-
-struct parsefile {
-	struct parsefile *prev; /* preceding file on stack */
-	int linno;              /* current line */
-	int fd;                 /* file descriptor (or -1 if string) */
-	int nleft;              /* number of chars left in this line */
-	int lleft;              /* number of chars left in this buffer */
-	char *nextc;            /* next char in buffer */
-	char *buf;              /* input buffer */
-	struct strpush *strpush; /* for pushing strings at this level */
-	struct strpush basestrpush; /* so pushing one is fast */
-};
-
 /*
  * The parsefile structure pointed to by the global variable parsefile
  * contains information about the current file being read.






More information about the busybox mailing list