commit 674bc69c366f3f66a75e2635293420f6be910146
parent 58d70bdbf77c676eaa9806a80c2208d81715c065
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 28 Jun 2020 21:23:44 +0200
cc1: Fix order of initialization
After joining all the different versions of cc1 the order of
initialization was wrong and the execution of cc1 generated a segfault
because types were initialized in iarch(). Types were needed in several
initialization functions because they were emitting types definitions.
Diffstat:
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/src/cmd/cc/cc1/amd64-sysv.c b/src/cmd/cc/cc1/amd64-sysv.c
@@ -196,7 +196,8 @@ amd64_sysv(void)
},
};
- arch.va_list_type = *mktype(va_type, ARY, 1, NULL);
+ sizettype = &arch.sizettype;
+ arch.va_list_type = *mktype(&arch.va_type, ARY, 1, NULL);
arch.pvoidtype.type = &arch.chartype;
arch.valid_va_list = local_valid_va_list;
arch.zero.type = inttype;
diff --git a/src/cmd/cc/cc1/arm64-sysv.c b/src/cmd/cc/cc1/arm64-sysv.c
@@ -196,7 +196,8 @@ arm64_sysv(void)
},
};
- arch.va_list_type = *mktype(va_type, ARY, 1, NULL);
+ sizettype = &arch.sizettype;
+ arch.va_list_type = *mktype(&arch.va_type, ARY, 1, NULL);
arch.pvoidtype.type = &arch.chartype;
arch.valid_va_list = local_valid_va_list;
arch.zero.type = inttype;
diff --git a/src/cmd/cc/cc1/main.c b/src/cmd/cc/cc1/main.c
@@ -13,7 +13,6 @@ char *argv0, *infile;
int warnings;
jmp_buf recover;
-static struct items uflags;
int onlycpp, onlyheader;
@@ -44,18 +43,14 @@ int
main(int argc, char *argv[])
{
int i;
-
- ilex();
- icpp();
- icode();
- ibuilts();
+ static struct items uflags, dflags, iflags;
ARGBEGIN {
case 'a':
architecture = EARGF(usage());
break;
case 'D':
- defmacro(EARGF(usage()));
+ newitem(&dflags, EARGF(usage()));
break;
case 'M':
onlyheader = 1;
@@ -64,7 +59,7 @@ main(int argc, char *argv[])
onlycpp = 1;
break;
case 'I':
- incdir(EARGF(usage()));
+ newitem(&iflags, EARGF(usage()));
break;
case 'U':
newitem(&uflags, EARGF(usage()));
@@ -82,17 +77,24 @@ main(int argc, char *argv[])
if (argc > 1)
usage();
+ icode();
+ iarch();
+ ilex();
+ icpp();
+ ibuilts();
+
+ for (i = 0; i < iflags.n; ++i)
+ incdir(iflags.s[i]);
+
+ for (i = 0; i < dflags.n; ++i)
+ defmacro(dflags.s[i]);
+
for (i = 0; i < uflags.n; ++i)
undefmacro(uflags.s[i]);
infile = (*argv) ? *argv : "<stdin>";
addinput(*argv, NULL, NULL);
- /*
- * we cannot initialize arch until we have an
- * output stream, because we maybe want to emit new types
- */
- iarch();
if (onlycpp || onlyheader) {
outcpp();
} else {