ref: a8e2e90fa44baacd3339cdfcb927e3c24ad89190
parent: 9ce516646c110093add983caff3fb939b431fd3e
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Jun 28 17:23:44 EDT 2020
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.
--- a/src/cmd/cc/cc1/amd64-sysv.c
+++ b/src/cmd/cc/cc1/amd64-sysv.c
@@ -196,7 +196,8 @@
},
};
- 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;
--- a/src/cmd/cc/cc1/arm64-sysv.c
+++ b/src/cmd/cc/cc1/arm64-sysv.c
@@ -196,7 +196,8 @@
},
};
- 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;
--- a/src/cmd/cc/cc1/main.c
+++ b/src/cmd/cc/cc1/main.c
@@ -13,7 +13,6 @@
int warnings;
jmp_buf recover;
-static struct items uflags;
int onlycpp, onlyheader;
@@ -44,18 +43,14 @@
main(int argc, char *argv[])
{
int i;
+ static struct items uflags, dflags, iflags;
- ilex();
- icpp();
- icode();
- ibuilts();
-
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 @@
onlycpp = 1;
break;
case 'I':
- incdir(EARGF(usage()));
+ newitem(&iflags, EARGF(usage()));
break;
case 'U':
newitem(&uflags, EARGF(usage()));
@@ -82,6 +77,18 @@
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]);
@@ -88,11 +95,6 @@
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 {