summaryrefslogtreecommitdiff
path: root/src/cmd/dist
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2014-06-19 09:22:53 +0200
committerMichael Stapelberg <stapelberg@debian.org>2014-06-19 09:22:53 +0200
commit8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch)
tree4449f2036cccf162e8417cc5841a35815b3e7ac5 /src/cmd/dist
parentc8bf49ef8a92e2337b69c14b9b88396efe498600 (diff)
downloadgolang-upstream/1.3.tar.gz
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'src/cmd/dist')
-rw-r--r--src/cmd/dist/a.h5
-rw-r--r--src/cmd/dist/arm.c12
-rw-r--r--src/cmd/dist/build.c267
-rw-r--r--src/cmd/dist/buildgc.c10
-rw-r--r--src/cmd/dist/buildgo.c2
-rw-r--r--src/cmd/dist/buildruntime.c98
-rw-r--r--src/cmd/dist/goc2c.c116
-rw-r--r--src/cmd/dist/unix.c9
-rw-r--r--src/cmd/dist/windows.c22
9 files changed, 287 insertions, 254 deletions
diff --git a/src/cmd/dist/a.h b/src/cmd/dist/a.h
index 9de93180f..6222e5060 100644
--- a/src/cmd/dist/a.h
+++ b/src/cmd/dist/a.h
@@ -75,7 +75,8 @@ extern char *goroot_final;
extern char *goextlinkenabled;
extern char *goversion;
extern char *defaultcc;
-extern char *defaultcxx;
+extern char *defaultcxxtarget;
+extern char *defaultcctarget;
extern char *workdir;
extern char *tooldir;
extern char *slash;
@@ -93,7 +94,7 @@ void cmdversion(int, char**);
// buildgc.c
void gcopnames(char*, char*);
-void mkenam(char*, char*);
+void mkanames(char*, char*);
// buildruntime.c
void mkzasm(char*, char*);
diff --git a/src/cmd/dist/arm.c b/src/cmd/dist/arm.c
index dafc5c1c2..52a621c5d 100644
--- a/src/cmd/dist/arm.c
+++ b/src/cmd/dist/arm.c
@@ -17,16 +17,8 @@ static void useVFPv1(void);
char *
xgetgoarm(void)
{
-#if defined(__NetBSD__) || defined(__FreeBSD__)
- // NetBSD has buggy support for VFPv2 (incorrect inexact,
- // denormial, and NaN handling). When GOARM=6, some of our
- // math tests fails on Raspberry Pi.
- // Thus we return "5" here for safety, the user is free
- // to override.
- // Note: using GOARM=6 with cgo can trigger a kernel assertion
- // failure and crash NetBSD/evbarm kernel.
- // FreeBSD also have broken VFP support, so disable VFP also
- // on FreeBSD.
+#if defined(__FreeBSD__)
+ // FreeBSD has broken VFP support
return "5";
#endif
if(xtryexecfunc(useVFPv3))
diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c
index e6e5f0cf7..6884e0aae 100644
--- a/src/cmd/dist/build.c
+++ b/src/cmd/dist/build.c
@@ -27,22 +27,27 @@ char *gochar;
char *goversion;
char *slash; // / for unix, \ for windows
char *defaultcc;
-char *defaultcxx;
+char *defaultcflags;
+char *defaultldflags;
+char *defaultcxxtarget;
+char *defaultcctarget;
bool rebuildall;
bool defaultclang;
static bool shouldbuild(char*, char*);
static void copy(char*, char*, int);
+static void dopack(char*, char*, char**, int);
static char *findgoversion(void);
// The known architecture letters.
-static char *gochars = "568";
+static char *gochars = "5668";
// The known architectures.
static char *okgoarch[] = {
// same order as gochars
"arm",
"amd64",
+ "amd64p32",
"386",
};
@@ -51,7 +56,9 @@ static char *okgoos[] = {
"darwin",
"dragonfly",
"linux",
+ "solaris",
"freebsd",
+ "nacl",
"netbsd",
"openbsd",
"plan9",
@@ -164,14 +171,29 @@ init(void)
}
defaultcc = btake(&b);
- xgetenv(&b, "CXX");
+ xgetenv(&b, "CFLAGS");
+ defaultcflags = btake(&b);
+
+ xgetenv(&b, "LDFLAGS");
+ defaultldflags = btake(&b);
+
+ xgetenv(&b, "CC_FOR_TARGET");
if(b.len == 0) {
- if(defaultclang)
- bprintf(&b, "clang++");
- else
- bprintf(&b, "g++");
+ bprintf(&b, defaultcc);
}
- defaultcxx = btake(&b);
+ defaultcctarget = btake(&b);
+
+ xgetenv(&b, "CXX_FOR_TARGET");
+ if(b.len == 0) {
+ xgetenv(&b, "CXX");
+ if(b.len == 0) {
+ if(defaultclang)
+ bprintf(&b, "clang++");
+ else
+ bprintf(&b, "g++");
+ }
+ }
+ defaultcxxtarget = btake(&b);
xsetenv("GOROOT", goroot);
xsetenv("GOARCH", goarch);
@@ -268,9 +290,8 @@ findgoversion(void)
p = tags.p[i];
if(streq(p, "+"))
nrev++;
- // NOTE: Can reenable the /* */ code when we want to
- // start reporting versions named 'weekly' again.
- if(/*hasprefix(p, "weekly.") ||*/ hasprefix(p, "go")) {
+ // Only show the beta tag for the exact revision.
+ if(hasprefix(p, "go") && (!contains(p, "beta") || nrev == 0)) {
tag = xstrdup(p);
// If this tag matches the current checkout
// exactly (no "+" yet), don't show extra
@@ -344,7 +365,8 @@ static char *oldtool[] = {
// Unreleased directories (relative to $GOROOT) that should
// not be in release branches.
static char *unreleased[] = {
- "src/cmd/prof",
+ "src/cmd/link",
+ "src/pkg/debug/goobj",
"src/pkg/old",
};
@@ -414,7 +436,7 @@ setup(void)
}
// For release, make sure excluded things are excluded.
- if(hasprefix(goversion, "release.") || hasprefix(goversion, "go")) {
+ if(hasprefix(goversion, "release.") || (hasprefix(goversion, "go") && !contains(goversion, "beta"))) {
for(i=0; i<nelem(unreleased); i++)
if(isdir(bpathf(&b, "%s/%s", goroot, unreleased[i])))
fatal("%s should not exist in release build", bstr(&b));
@@ -435,7 +457,6 @@ static char *proto_gccargs[] = {
"-Wstrict-prototypes",
"-Wextra",
"-Wunused",
- "-Wuninitialized",
"-Wno-sign-compare",
"-Wno-missing-braces",
"-Wno-parentheses",
@@ -447,6 +468,15 @@ static char *proto_gccargs[] = {
"-fno-common",
"-ggdb",
"-pipe",
+};
+
+// gccargs2 is the second part of gccargs.
+// it is used if the environment isn't defining CFLAGS.
+static char *proto_gccargs2[] = {
+ // on older versions of GCC, -Wuninitialized is not supported
+ // without -O, so put it here together with -O settings in case
+ // the user's $CFLAGS doesn't include -O.
+ "-Wuninitialized",
#if defined(__NetBSD__) && defined(__arm__)
// GCC 4.5.4 (NetBSD nb1 20120916) on ARM is known to mis-optimize gc/mparith3.c
// Fix available at http://patchwork.ozlabs.org/patch/64562/.
@@ -456,7 +486,7 @@ static char *proto_gccargs[] = {
#endif
};
-static Vec gccargs;
+static Vec gccargs, ldargs;
// deptab lists changes to the default dependencies for a given prefix.
// deps ending in /* read the whole directory; deps beginning with -
@@ -480,18 +510,17 @@ static struct {
"$GOROOT/include/libc.h",
"$GOROOT/include/bio.h",
}},
- {"libmach", {
+ {"liblink", {
"$GOROOT/include/u.h",
"$GOROOT/include/utf.h",
"$GOROOT/include/fmt.h",
"$GOROOT/include/libc.h",
"$GOROOT/include/bio.h",
"$GOROOT/include/ar.h",
- "$GOROOT/include/bootexec.h",
- "$GOROOT/include/mach.h",
- "$GOROOT/include/ureg_amd64.h",
- "$GOROOT/include/ureg_arm.h",
- "$GOROOT/include/ureg_x86.h",
+ "$GOROOT/include/link.h",
+ "anames5.c",
+ "anames6.c",
+ "anames8.c",
}},
{"cmd/cc", {
"-pgen.c",
@@ -500,6 +529,7 @@ static struct {
{"cmd/gc", {
"-cplx.c",
"-pgen.c",
+ "-plive.c",
"-popt.c",
"-y1.tab.c", // makefile dreg
"opnames.h",
@@ -507,64 +537,58 @@ static struct {
{"cmd/5c", {
"../cc/pgen.c",
"../cc/pswt.c",
- "../5l/enam.c",
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/libcc.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libcc.a",
}},
{"cmd/6c", {
"../cc/pgen.c",
"../cc/pswt.c",
- "../6l/enam.c",
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/libcc.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libcc.a",
}},
{"cmd/8c", {
"../cc/pgen.c",
"../cc/pswt.c",
- "../8l/enam.c",
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/libcc.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libcc.a",
}},
{"cmd/5g", {
"../gc/cplx.c",
"../gc/pgen.c",
+ "../gc/plive.c",
"../gc/popt.c",
"../gc/popt.h",
- "../5l/enam.c",
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/libgc.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libgc.a",
}},
{"cmd/6g", {
"../gc/cplx.c",
"../gc/pgen.c",
+ "../gc/plive.c",
"../gc/popt.c",
"../gc/popt.h",
- "../6l/enam.c",
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/libgc.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libgc.a",
}},
{"cmd/8g", {
"../gc/cplx.c",
"../gc/pgen.c",
+ "../gc/plive.c",
"../gc/popt.c",
"../gc/popt.h",
- "../8l/enam.c",
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/libgc.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libgc.a",
}},
{"cmd/5l", {
"../ld/*",
- "enam.c",
}},
{"cmd/6l", {
"../ld/*",
- "enam.c",
}},
{"cmd/8l", {
"../ld/*",
- "enam.c",
}},
{"cmd/go", {
"zdefaultcc.go",
}},
{"cmd/", {
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/libmach.a",
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/libbio.a",
- "$GOROOT/pkg/obj/$GOOS_$GOARCH/lib9.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/liblink.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libbio.a",
+ "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/lib9.a",
}},
{"pkg/runtime", {
"zaexperiment.h", // must sort above zasm
@@ -592,7 +616,9 @@ static struct {
void (*gen)(char*, char*);
} gentab[] = {
{"opnames.h", gcopnames},
- {"enam.c", mkenam},
+ {"anames5.c", mkanames},
+ {"anames6.c", mkanames},
+ {"anames8.c", mkanames},
{"zasm_", mkzasm},
{"zdefaultcc.go", mkzdefaultcc},
{"zsys_", mkzsys},
@@ -601,6 +627,9 @@ static struct {
{"zruntime_defs_", mkzruntimedefs},
{"zversion.go", mkzversion},
{"zaexperiment.h", mkzexperiment},
+
+ // not generated anymore, but delete the file if we see it
+ {"enam.c", nil},
};
// install installs the library, package, or binary associated with dir,
@@ -609,11 +638,11 @@ static void
install(char *dir)
{
char *name, *p, *elem, *prefix, *exe;
- bool islib, ispkg, isgo, stale;
+ bool islib, ispkg, isgo, stale, ispackcmd;
Buf b, b1, path;
Vec compile, files, link, go, missing, clean, lib, extra;
Time ttarg, t;
- int i, j, k, n, doclean, targ, usecpp;
+ int i, j, k, n, doclean, targ;
if(vflag) {
if(!streq(goos, gohostos) || !streq(goarch, gohostarch))
@@ -646,30 +675,33 @@ install(char *dir)
goto out;
}
- // For release, cmd/prof is not included.
- if((streq(dir, "cmd/prof")) && !isdir(bstr(&path))) {
- if(vflag > 1)
- errprintf("skipping %s - does not exist\n", dir);
- goto out;
- }
-
// set up gcc command line on first run.
if(gccargs.len == 0) {
- bprintf(&b, "%s", defaultcc);
+ bprintf(&b, "%s %s", defaultcc, defaultcflags);
splitfields(&gccargs, bstr(&b));
for(i=0; i<nelem(proto_gccargs); i++)
vadd(&gccargs, proto_gccargs[i]);
+ if(defaultcflags[0] == '\0') {
+ for(i=0; i<nelem(proto_gccargs2); i++)
+ vadd(&gccargs, proto_gccargs2[i]);
+ }
if(contains(gccargs.p[0], "clang")) {
// disable ASCII art in clang errors, if possible
vadd(&gccargs, "-fno-caret-diagnostics");
// clang is too smart about unused command-line arguments
vadd(&gccargs, "-Qunused-arguments");
}
+ // disable word wrapping in error messages
+ vadd(&gccargs, "-fmessage-length=0");
if(streq(gohostos, "darwin")) {
// golang.org/issue/5261
vadd(&gccargs, "-mmacosx-version-min=10.6");
}
}
+ if(ldargs.len == 0 && defaultldflags[0] != '\0') {
+ bprintf(&b, "%s", defaultldflags);
+ splitfields(&ldargs, bstr(&b));
+ }
islib = hasprefix(dir, "lib") || streq(dir, "cmd/cc") || streq(dir, "cmd/gc");
ispkg = hasprefix(dir, "pkg");
@@ -681,6 +713,7 @@ install(char *dir)
// Start final link command line.
// Note: code below knows that link.p[targ] is the target.
+ ispackcmd = 0;
if(islib) {
// C library.
vadd(&link, "ar");
@@ -695,8 +728,8 @@ install(char *dir)
vadd(&link, bpathf(&b, "%s/pkg/obj/%s_%s/%s%s.a", goroot, gohostos, gohostarch, prefix, name));
} else if(ispkg) {
// Go library (package).
- vadd(&link, bpathf(&b, "%s/pack", tooldir));
- vadd(&link, "grc");
+ ispackcmd = 1;
+ vadd(&link, "pack"); // program name - unused here, but all the other cases record one
p = bprintf(&b, "%s/pkg/%s_%s/%s", goroot, goos, goarch, dir+4);
*xstrrchr(p, '/') = '\0';
xmkdirall(p);
@@ -712,7 +745,7 @@ install(char *dir)
targ = link.len;
vadd(&link, bpathf(&b, "%s/%s%s", tooldir, elem, exe));
} else {
- // C command. Use gccargs.
+ // C command. Use gccargs and ldargs.
if(streq(gohostos, "plan9")) {
vadd(&link, bprintf(&b, "%sl", gohostchar));
vadd(&link, "-o");
@@ -720,6 +753,7 @@ install(char *dir)
vadd(&link, bpathf(&b, "%s/%s", tooldir, name));
} else {
vcopy(&link, gccargs.p, gccargs.len);
+ vcopy(&link, ldargs.p, ldargs.len);
if(sflag)
vadd(&link, "-static");
vadd(&link, "-o");
@@ -754,17 +788,18 @@ install(char *dir)
files.len = n;
for(i=0; i<nelem(deptab); i++) {
- if(hasprefix(dir, deptab[i].prefix)) {
+ if(streq(dir, deptab[i].prefix) ||
+ (hassuffix(deptab[i].prefix, "/") && hasprefix(dir, deptab[i].prefix))) {
for(j=0; (p=deptab[i].dep[j])!=nil; j++) {
breset(&b1);
bwritestr(&b1, p);
bsubst(&b1, "$GOROOT", goroot);
bsubst(&b1, "$GOOS", goos);
bsubst(&b1, "$GOARCH", goarch);
+ bsubst(&b1, "$GOHOSTOS", gohostos);
+ bsubst(&b1, "$GOHOSTARCH", gohostarch);
p = bstr(&b1);
if(hassuffix(p, ".a")) {
- if(streq(gohostos, "plan9") && hassuffix(p, "libbio.a"))
- continue;
vadd(&lib, bpathf(&b, "%s", p));
continue;
}
@@ -865,6 +900,8 @@ install(char *dir)
p = files.p[i];
elem = lastelem(p);
for(j=0; j<nelem(gentab); j++) {
+ if(gentab[j].gen == nil)
+ continue;
if(hasprefix(elem, gentab[j].nameprefix)) {
if(vflag > 1)
errprintf("generate %s\n", p);
@@ -916,20 +953,6 @@ install(char *dir)
goto nobuild;
}
- // The files generated by GNU Bison use macros that aren't
- // supported by the Plan 9 compilers so we have to use the
- // external preprocessor when compiling.
- usecpp = 0;
- if(streq(gohostos, "plan9")) {
- for(i=0; i<files.len; i++) {
- p = files.p[i];
- if(hassuffix(p, "y.tab.c") || hassuffix(p, "y.tab.h")){
- usecpp = 1;
- break;
- }
- }
- }
-
// Compile the files.
for(i=0; i<files.len; i++) {
if(!hassuffix(files.p[i], ".c") && !hassuffix(files.p[i], ".s"))
@@ -941,13 +964,12 @@ install(char *dir)
// C library or tool.
if(streq(gohostos, "plan9")) {
vadd(&compile, bprintf(&b, "%sc", gohostchar));
- vadd(&compile, "-FTVw");
- if(usecpp)
- vadd(&compile, "-Bp+");
+ vadd(&compile, "-FTVwp");
+ vadd(&compile, "-DPLAN9");
+ vadd(&compile, "-D__STDC__=1");
+ vadd(&compile, "-D__SIZE_TYPE__=ulong"); // for GNU Bison
vadd(&compile, bpathf(&b, "-I%s/include/plan9", goroot));
vadd(&compile, bpathf(&b, "-I%s/include/plan9/%s", goroot, gohostarch));
- // Work around Plan 9 C compiler's handling of #include with .. path.
- vadd(&compile, bpathf(&b, "-I%s/src/cmd/ld", goroot));
} else {
vcopy(&compile, gccargs.p, gccargs.len);
vadd(&compile, "-c");
@@ -955,13 +977,15 @@ install(char *dir)
vadd(&compile, "-m64");
else if(streq(gohostarch, "386"))
vadd(&compile, "-m32");
- if(streq(dir, "lib9"))
- vadd(&compile, "-DPLAN9PORT");
vadd(&compile, "-I");
vadd(&compile, bpathf(&b, "%s/include", goroot));
}
+ if(streq(dir, "lib9"))
+ vadd(&compile, "-DPLAN9PORT");
+
+
vadd(&compile, "-I");
vadd(&compile, bstr(&path));
@@ -1048,11 +1072,13 @@ install(char *dir)
vreset(&compile);
vadd(&compile, bpathf(&b, "%s/%sg", tooldir, gochar));
- bpathf(&b, "%s/_go_.%s", workdir, gochar);
+ bpathf(&b, "%s/_go_.a", workdir);
+ vadd(&compile, "-pack");
vadd(&compile, "-o");
vadd(&compile, bstr(&b));
vadd(&clean, bstr(&b));
- vadd(&link, bstr(&b));
+ if(!ispackcmd)
+ vadd(&link, bstr(&b));
vadd(&compile, "-p");
if(hasprefix(dir, "pkg/"))
@@ -1066,6 +1092,12 @@ install(char *dir)
vcopy(&compile, go.p, go.len);
runv(nil, bstr(&path), CheckExit, &compile);
+
+ if(ispackcmd) {
+ xremove(link.p[targ]);
+ dopack(link.p[targ], bstr(&b), &link.p[targ+1], link.len - (targ+1));
+ goto nobuild;
+ }
}
if(!islib && !isgo) {
@@ -1138,21 +1170,6 @@ shouldbuild(char *file, char *dir)
int i, j, ret;
Buf b;
Vec lines, fields;
-
- // On Plan 9, most of the libraries are already present.
- // The main exception is libmach which has been modified
- // in various places to support Go object files.
- if(streq(gohostos, "plan9")) {
- if(streq(dir, "lib9")) {
- name = lastelem(file);
- if(streq(name, "goos.c") || streq(name, "flag.c"))
- return 1;
- if(!contains(name, "plan9"))
- return 0;
- }
- if(streq(dir, "libbio"))
- return 0;
- }
// Check file name for GOOS or GOARCH.
name = lastelem(file);
@@ -1238,20 +1255,56 @@ copy(char *dst, char *src, int exec)
bfree(&b);
}
+// dopack copies the package src to dst,
+// appending the files listed in extra.
+// The archive format is the traditional Unix ar format.
+static void
+dopack(char *dst, char *src, char **extra, int nextra)
+{
+ int i;
+ char c, *p, *q;
+ Buf b, bdst;
+
+ binit(&b);
+ binit(&bdst);
+
+ readfile(&bdst, src);
+ for(i=0; i<nextra; i++) {
+ readfile(&b, extra[i]);
+ // find last path element for archive member name
+ p = xstrrchr(extra[i], '/');
+ if(p)
+ p++;
+ q = xstrrchr(extra[i], '\\');
+ if(q) {
+ q++;
+ if(p == nil || q > p)
+ p = q;
+ }
+ if(p == nil)
+ p = extra[i];
+ bwritef(&bdst, "%-16.16s%-12d%-6d%-6d%-8o%-10d`\n", p, 0, 0, 0, 0644, b.len);
+ bwriteb(&bdst, &b);
+ if(b.len&1) {
+ c = 0;
+ bwrite(&bdst, &c, 1);
+ }
+ }
+
+ writefile(&bdst, dst, 0);
+
+ bfree(&b);
+ bfree(&bdst);
+}
+
// buildorder records the order of builds for the 'go bootstrap' command.
static char *buildorder[] = {
"lib9",
"libbio",
- "libmach",
+ "liblink",
"misc/pprof",
- "cmd/addr2line",
- "cmd/nm",
- "cmd/objdump",
- "cmd/pack",
- "cmd/prof",
-
"cmd/cc", // must be before c
"cmd/gc", // must be before g
"cmd/%sl", // must be before a, c, g
@@ -1323,17 +1376,12 @@ static char *cleantab[] = {
"cmd/8c",
"cmd/8g",
"cmd/8l",
- "cmd/addr2line",
"cmd/cc",
"cmd/gc",
- "cmd/go",
- "cmd/nm",
- "cmd/objdump",
- "cmd/pack",
- "cmd/prof",
+ "cmd/go",
"lib9",
"libbio",
- "libmach",
+ "liblink",
"pkg/bufio",
"pkg/bytes",
"pkg/container/heap",
@@ -1388,8 +1436,6 @@ clean(void)
vinit(&dir);
for(i=0; i<nelem(cleantab); i++) {
- if((streq(cleantab[i], "cmd/prof")) && !isdir(cleantab[i]))
- continue;
bpathf(&path, "%s/src/%s", goroot, cleantab[i]);
xreaddir(&dir, bstr(&path));
// Remove generated files.
@@ -1488,6 +1534,7 @@ cmdenv(int argc, char **argv)
usage();
xprintf(format, "CC", defaultcc);
+ xprintf(format, "CC_FOR_TARGET", defaultcctarget);
xprintf(format, "GOROOT", goroot);
xprintf(format, "GOBIN", gobin);
xprintf(format, "GOARCH", goarch);
diff --git a/src/cmd/dist/buildgc.c b/src/cmd/dist/buildgc.c
index 03a797f2c..1f0625daa 100644
--- a/src/cmd/dist/buildgc.c
+++ b/src/cmd/dist/buildgc.c
@@ -63,10 +63,10 @@ gcopnames(char *dir, char *file)
vfree(&fields);
}
-// mkenam reads [568].out.h and writes enam.c
+// mkanames reads [568].out.h and writes anames[568].c
// The format is much the same as the Go opcodes above.
void
-mkenam(char *dir, char *file)
+mkanames(char *dir, char *file)
{
int i, ch;
Buf in, b, out;
@@ -78,11 +78,11 @@ mkenam(char *dir, char *file)
binit(&out);
vinit(&lines);
- ch = dir[xstrlen(dir)-2];
- bprintf(&b, "%s/../%cl/%c.out.h", dir, ch, ch);
+ ch = file[xstrlen(file)-3];
+ bprintf(&b, "%s/../cmd/%cl/%c.out.h", dir, ch, ch);
readfile(&in, bstr(&b));
splitlines(&lines, bstr(&in));
- bwritestr(&out, "char* anames[] = {\n");
+ bprintf(&out, "char* anames%c[] = {\n", ch);
for(i=0; i<lines.len; i++) {
if(hasprefix(lines.p[i], "\tA")) {
p = xstrstr(lines.p[i], ",");
diff --git a/src/cmd/dist/buildgo.c b/src/cmd/dist/buildgo.c
index a340252bc..41208fac5 100644
--- a/src/cmd/dist/buildgo.c
+++ b/src/cmd/dist/buildgo.c
@@ -31,7 +31,7 @@ mkzdefaultcc(char *dir, char *file)
"\n"
"const defaultCC = `%s`\n"
"const defaultCXX = `%s`\n",
- defaultcc, defaultcxx);
+ defaultcctarget, defaultcxxtarget);
writefile(&out, file, 0);
diff --git a/src/cmd/dist/buildruntime.c b/src/cmd/dist/buildruntime.c
index e6e309d92..ba5993b2f 100644
--- a/src/cmd/dist/buildruntime.c
+++ b/src/cmd/dist/buildruntime.c
@@ -127,83 +127,22 @@ static struct {
char *goos;
char *hdr;
} zasmhdr[] = {
- {"386", "windows",
- "#define get_tls(r) MOVL 0x14(FS), r\n"
- "#define g(r) 0(r)\n"
- "#define m(r) 4(r)\n"
- },
- {"386", "plan9",
- "// Plan 9 does not have per-process segment descriptors with\n"
- "// which to do thread-local storage. Instead, we will use a\n"
- "// fixed offset from the per-process TOS struct address for\n"
- "// the local storage. Since the process ID is contained in the\n"
- "// TOS struct, we specify an offset for that here as well.\n"
- "#define get_tls(r) MOVL _tos(SB), r \n"
- "#define g(r) -8(r)\n"
- "#define m(r) -4(r)\n"
- "#define procid(r) 48(r)\n"
- },
- {"386", "linux",
- "// On Linux systems, what we call 0(GS) and 4(GS) for g and m\n"
- "// turn into %gs:-8 and %gs:-4 (using gcc syntax to denote\n"
- "// what the machine sees as opposed to 8l input).\n"
- "// 8l rewrites 0(GS) and 4(GS) into these.\n"
- "//\n"
- "// On Linux Xen, it is not allowed to use %gs:-8 and %gs:-4\n"
- "// directly. Instead, we have to store %gs:0 into a temporary\n"
- "// register and then use -8(%reg) and -4(%reg). This kind\n"
- "// of addressing is correct even when not running Xen.\n"
- "//\n"
- "// 8l can rewrite MOVL 0(GS), CX into the appropriate pair\n"
- "// of mov instructions, using CX as the intermediate register\n"
- "// (safe because CX is about to be written to anyway).\n"
- "// But 8l cannot handle other instructions, like storing into 0(GS),\n"
- "// which is where these macros come into play.\n"
- "// get_tls sets up the temporary and then g and r use it.\n"
- "//\n"
- "// Another wrinkle is that get_tls needs to read from %gs:0,\n"
- "// but in 8l input it's called 8(GS), because 8l is going to\n"
- "// subtract 8 from all the offsets, as described above.\n"
- "//\n"
- "// The final wrinkle is that when generating an ELF .o file for\n"
- "// external linking mode, we need to be able to relocate the\n"
- "// -8(r) and -4(r) instructions. Tag them with an extra (GS*1)\n"
- "// that is ignored by the linker except for that identification.\n"
- "#define get_tls(r) MOVL 8(GS), r\n"
- "#define g(r) -8(r)(GS*1)\n"
- "#define m(r) -4(r)(GS*1)\n"
- },
{"386", "",
- "#define get_tls(r)\n"
- "#define g(r) 0(GS)\n"
- "#define m(r) 4(GS)\n"
- },
-
- {"amd64", "windows",
- "#define get_tls(r) MOVQ 0x28(GS), r\n"
- "#define g(r) 0(r)\n"
- "#define m(r) 8(r)\n"
+ "#define get_tls(r) MOVL TLS, r\n"
+ "#define g(r) 0(r)(TLS*1)\n"
+ "#define m(r) 4(r)(TLS*1)\n"
},
- {"amd64", "plan9",
- "#define get_tls(r)\n"
- "#define g(r) 0(GS)\n"
- "#define m(r) 8(GS)\n"
- "#define procid(r) 16(GS)\n"
- },
- // The TLS accessors here are defined here to use initial exec model.
- // If the linker is not outputting a shared library, it will reduce
- // the TLS accessors to the local exec model, effectively removing
- // get_tls().
- {"amd64", "linux",
- "#define get_tls(r) MOVQ runtime·tlsgm(SB), r\n"
- "#define g(r) 0(r)(GS*1)\n"
- "#define m(r) 8(r)(GS*1)\n"
+ {"amd64p32", "",
+ "#define get_tls(r) MOVL TLS, r\n"
+ "#define g(r) 0(r)(TLS*1)\n"
+ "#define m(r) 4(r)(TLS*1)\n"
},
{"amd64", "",
- "#define get_tls(r)\n"
- "#define g(r) 0(GS)\n"
- "#define m(r) 8(GS)\n"
+ "#define get_tls(r) MOVQ TLS, r\n"
+ "#define g(r) 0(r)(TLS*1)\n"
+ "#define m(r) 8(r)(TLS*1)\n"
},
+
{"arm", "",
"#define LR R14\n"
},
@@ -243,7 +182,8 @@ mkzasm(char *dir, char *file)
ok:
// Run 6c -D GOOS_goos -D GOARCH_goarch -I workdir -a -n -o workdir/proc.acid proc.c
- // to get acid [sic] output.
+ // to get acid [sic] output. Run once without the -a -o workdir/proc.acid in order to
+ // report compilation failures (the -o redirects all messages, unfortunately).
vreset(&argv);
vadd(&argv, bpathf(&b, "%s/%sc", tooldir, gochar));
vadd(&argv, "-D");
@@ -252,8 +192,8 @@ ok:
vadd(&argv, bprintf(&b, "GOARCH_%s", goarch));
vadd(&argv, "-I");
vadd(&argv, bprintf(&b, "%s", workdir));
- vadd(&argv, "-a");
vadd(&argv, "-n");
+ vadd(&argv, "-a");
vadd(&argv, "-o");
vadd(&argv, bpathf(&b, "%s/proc.acid", workdir));
vadd(&argv, "proc.c");
@@ -284,8 +224,8 @@ ok:
aggr = "p";
else if(streq(fields.p[1], "Gobuf"))
aggr = "gobuf";
- else if(streq(fields.p[1], "WinCall"))
- aggr = "wincall";
+ else if(streq(fields.p[1], "LibCall"))
+ aggr = "libcall";
else if(streq(fields.p[1], "WinCallbackContext"))
aggr = "cbctxt";
else if(streq(fields.p[1], "SEH"))
@@ -329,7 +269,7 @@ ok:
vfree(&fields);
}
-// mkzsys writes zsys_$GOOS_$GOARCH.h,
+// mkzsys writes zsys_$GOOS_$GOARCH.s,
// which contains arch or os specific asm code.
//
void
@@ -365,10 +305,8 @@ mkzsys(char *dir, char *file)
}
static char *runtimedefs[] = {
+ "defs.c",
"proc.c",
- "iface.c",
- "hashmap.c",
- "chan.c",
"parfor.c",
};
diff --git a/src/cmd/dist/goc2c.c b/src/cmd/dist/goc2c.c
index f0fa04335..38627657e 100644
--- a/src/cmd/dist/goc2c.c
+++ b/src/cmd/dist/goc2c.c
@@ -85,11 +85,15 @@ enum {
String,
Slice,
Eface,
+ Complex128,
+ Float32,
+ Float64,
};
static struct {
char *name;
int size;
+ int rnd; // alignment
} type_table[] = {
/*
* variable sized first, for easy replacement.
@@ -105,6 +109,7 @@ static struct {
{"String", 8},
{"Slice", 12},
{"Eface", 8},
+ {"Complex128", 16},
/* fixed size */
{"float32", 4},
@@ -130,7 +135,7 @@ int structround = 4;
static void
bad_eof(void)
{
- fatal("%s:%ud: unexpected EOF\n", file, lineno);
+ fatal("%s:%d: unexpected EOF\n", file, lineno);
}
/* Free a list of parameters. */
@@ -295,9 +300,9 @@ read_package(void)
token = read_token_no_eof();
if (token == nil)
- fatal("%s:%ud: no token\n", file, lineno);
+ fatal("%s:%d: no token\n", file, lineno);
if (!streq(token, "package")) {
- fatal("%s:%ud: expected \"package\", got \"%s\"\n",
+ fatal("%s:%d: expected \"package\", got \"%s\"\n",
file, lineno, token);
}
return read_token_no_eof();
@@ -307,6 +312,9 @@ read_package(void)
static void
read_preprocessor_lines(void)
{
+ int first;
+
+ first = 1;
while (1) {
int c;
@@ -317,6 +325,10 @@ read_preprocessor_lines(void)
xungetc();
break;
}
+ if(first) {
+ first = 0;
+ xputchar('\n');
+ }
xputchar(c);
do {
c = getchar_update_lineno();
@@ -365,17 +377,24 @@ read_type(void)
/* Return the size of the given type. */
static int
-type_size(char *p)
+type_size(char *p, int *rnd)
{
int i;
- if(p[xstrlen(p)-1] == '*')
+ if(p[xstrlen(p)-1] == '*') {
+ *rnd = type_table[Uintptr].rnd;
return type_table[Uintptr].size;
+ }
+
+ if(streq(p, "Iface"))
+ p = "Eface";
for(i=0; type_table[i].name; i++)
- if(streq(type_table[i].name, p))
+ if(streq(type_table[i].name, p)) {
+ *rnd = type_table[i].rnd;
return type_table[i].size;
- fatal("%s:%ud: unknown type %s\n", file, lineno, p);
+ }
+ fatal("%s:%d: unknown type %s\n", file, lineno, p);
return 0;
}
@@ -398,18 +417,22 @@ read_params(int *poffset)
while (1) {
p = xmalloc(sizeof(struct params));
p->name = token;
- p->type = read_type();
p->next = nil;
*pp = p;
pp = &p->next;
- size = type_size(p->type);
- rnd = size;
- if(rnd > structround)
- rnd = structround;
- if(offset%rnd)
- offset += rnd - offset%rnd;
- offset += size;
+ if(streq(token, "...")) {
+ p->type = xstrdup("");
+ } else {
+ p->type = read_type();
+ rnd = 0;
+ size = type_size(p->type, &rnd);
+ if(rnd > structround)
+ rnd = structround;
+ if(offset%rnd)
+ offset += rnd - offset%rnd;
+ offset += size;
+ }
token = read_token_no_eof();
if (!streq(token, ","))
@@ -418,7 +441,7 @@ read_params(int *poffset)
}
}
if (!streq(token, ")")) {
- fatal("%s:%ud: expected '('\n",
+ fatal("%s:%d: expected '('\n",
file, lineno);
}
if (poffset != nil)
@@ -438,6 +461,7 @@ read_func_header(char **name, struct params **params, int *paramwid, struct para
lastline = -1;
while (1) {
+ read_preprocessor_lines();
token = read_token();
if (token == nil)
return 0;
@@ -460,7 +484,7 @@ read_func_header(char **name, struct params **params, int *paramwid, struct para
token = read_token();
if (token == nil || !streq(token, "(")) {
- fatal("%s:%ud: expected \"(\"\n",
+ fatal("%s:%d: expected \"(\"\n",
file, lineno);
}
*params = read_params(paramwid);
@@ -473,7 +497,7 @@ read_func_header(char **name, struct params **params, int *paramwid, struct para
token = read_token();
}
if (token == nil || !streq(token, "{")) {
- fatal("%s:%ud: expected \"{\"\n",
+ fatal("%s:%d: expected \"{\"\n",
file, lineno);
}
return 1;
@@ -500,8 +524,13 @@ write_6g_func_header(char *package, char *name, struct params *params,
int paramwid, struct params *rets)
{
int first, n;
+ struct params *p;
+
+ bwritef(output, "void\n");
+ if(!contains(name, "·"))
+ bwritef(output, "%s·", package);
+ bwritef(output, "%s(", name);
- bwritef(output, "void\n%s·%s(", package, name);
first = 1;
write_params(params, &first);
@@ -518,6 +547,24 @@ write_6g_func_header(char *package, char *name, struct params *params,
write_params(rets, &first);
bwritef(output, ")\n{\n");
+
+ for (p = rets; p != nil; p = p->next) {
+ if(streq(p->name, "..."))
+ continue;
+ if(streq(p->type, "Slice"))
+ bwritef(output, "\t%s.array = 0;\n\t%s.len = 0;\n\t%s.cap = 0;\n", p->name, p->name, p->name);
+ else if(streq(p->type, "String"))
+ bwritef(output, "\t%s.str = 0;\n\t%s.len = 0;\n", p->name, p->name);
+ else if(streq(p->type, "Eface"))
+ bwritef(output, "\t%s.type = 0;\n\t%s.data = 0;\n", p->name, p->name);
+ else if(streq(p->type, "Iface"))
+ bwritef(output, "\t%s.tab = 0;\n\t%s.data = 0;\n", p->name, p->name);
+ else if(streq(p->type, "Complex128"))
+ bwritef(output, "\t%s.real = 0;\n\t%s.imag = 0;\n", p->name, p->name);
+ else
+ bwritef(output, "\t%s = 0;\n", p->name);
+ bwritef(output, "\tFLUSH(&%s);\n", p->name);
+ }
}
/* Write a 6g function trailer. */
@@ -527,7 +574,8 @@ write_6g_func_trailer(struct params *rets)
struct params *p;
for (p = rets; p != nil; p = p->next)
- bwritef(output, "\tFLUSH(&%s);\n", p->name);
+ if(!streq(p->name, "..."))
+ bwritef(output, "\tFLUSH(&%s);\n", p->name);
bwritef(output, "}\n");
}
@@ -726,6 +774,7 @@ process_file(void)
void
goc2c(char *goc, char *c)
{
+ int i;
Buf in, out;
binit(&in);
@@ -739,13 +788,15 @@ goc2c(char *goc, char *c)
if(!gcc) {
if(streq(goarch, "amd64")) {
type_table[Uintptr].size = 8;
- type_table[Eface].size = 8+8;
- type_table[String].size = 16;
if(use64bitint) {
type_table[Int].size = 8;
- type_table[Uint].size = 8;
+ } else {
+ type_table[Int].size = 4;
}
- type_table[Slice].size = 8+2*type_table[Int].size;
+ structround = 8;
+ } else if(streq(goarch, "amd64p32")) {
+ type_table[Uintptr].size = 4;
+ type_table[Int].size = 4;
structround = 8;
} else {
// NOTE: These are set in the initializer,
@@ -753,13 +804,22 @@ goc2c(char *goc, char *c)
// previous invocation of goc2c, so we have
// to restore them.
type_table[Uintptr].size = 4;
- type_table[String].size = 8;
- type_table[Slice].size = 16;
- type_table[Eface].size = 4+4;
type_table[Int].size = 4;
- type_table[Uint].size = 4;
structround = 4;
}
+
+ type_table[Uint].size = type_table[Int].size;
+ type_table[Slice].size = type_table[Uintptr].size+2*type_table[Int].size;
+ type_table[Eface].size = 2*type_table[Uintptr].size;
+ type_table[String].size = 2*type_table[Uintptr].size;
+
+ for(i=0; i<nelem(type_table); i++)
+ type_table[i].rnd = type_table[i].size;
+
+ type_table[String].rnd = type_table[Uintptr].rnd;
+ type_table[Slice].rnd = type_table[Uintptr].rnd;
+ type_table[Eface].rnd = type_table[Uintptr].rnd;
+ type_table[Complex128].rnd = type_table[Float64].rnd;
}
bprintf(&out, "// auto generated by go tool dist\n// goos=%s goarch=%s\n\n", goos, goarch);
diff --git a/src/cmd/dist/unix.c b/src/cmd/dist/unix.c
index fa388e058..8b943a2d9 100644
--- a/src/cmd/dist/unix.c
+++ b/src/cmd/dist/unix.c
@@ -24,6 +24,7 @@
#include <errno.h>
#include <stdarg.h>
#include <setjmp.h>
+#include <signal.h>
// bprintf replaces the buffer with the result of the printf formatting
// and returns a pointer to the NUL-terminated buffer contents.
@@ -686,6 +687,14 @@ main(int argc, char **argv)
gohostos = "openbsd";
#elif defined(__NetBSD__)
gohostos = "netbsd";
+#elif defined(__sun) && defined(__SVR4)
+ gohostos = "solaris";
+ // Even on 64-bit platform, solaris uname -m prints i86pc.
+ run(&b, nil, 0, "isainfo", "-n", nil);
+ if(contains(bstr(&b), "amd64"))
+ gohostarch = "amd64";
+ if(contains(bstr(&b), "i386"))
+ gohostarch = "386";
#else
fatal("unknown operating system");
#endif
diff --git a/src/cmd/dist/windows.c b/src/cmd/dist/windows.c
index 7d03989b2..2839c4bc5 100644
--- a/src/cmd/dist/windows.c
+++ b/src/cmd/dist/windows.c
@@ -840,34 +840,20 @@ void
xprintf(char *fmt, ...)
{
va_list arg;
- char *p;
- DWORD n, w;
-
+
va_start(arg, fmt);
- n = vsnprintf(NULL, 0, fmt, arg);
- p = xmalloc(n+1);
- vsnprintf(p, n+1, fmt, arg);
+ vprintf(fmt, arg);
va_end(arg);
- w = 0;
- WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), p, n, &w, 0);
- xfree(p);
}
void
errprintf(char *fmt, ...)
{
va_list arg;
- char *p;
- DWORD n, w;
-
+
va_start(arg, fmt);
- n = vsnprintf(NULL, 0, fmt, arg);
- p = xmalloc(n+1);
- vsnprintf(p, n+1, fmt, arg);
+ vfprintf(stderr, fmt, arg);
va_end(arg);
- w = 0;
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), p, n, &w, 0);
- xfree(p);
}
int