From: Russ Cox Date: Tue, 11 Nov 2014 06:29:05 +0000 (-0500) Subject: [dev.cc] cmd/dist: adjust for build process without cmd/cc X-Git-Tag: go1.5beta1~2688^2~82 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0d49f7b5fcbf5d5efad05dd4416574127bdd9dfd;p=gostls13.git [dev.cc] cmd/dist: adjust for build process without cmd/cc [This CL is part of the removal of C code from package runtime. See golang.org/s/dev.cc for an overview.] - Remove references to C compiler directories. - Remove generation of special header files. - Remove generation of Go source files from C declarations. - Compile Go sources before rest of package (was after), so that Go compiler can write go_asm.h for use in assembly. - Move TLS information from cmd/dist (was embedding in output) to src/runtime/go_tls.h, which it can be maintained directly. LGTM=r R=r, dave CC=austin, golang-codereviews, iant, khr https://golang.org/cl/172960043 --- diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c index d638ae4ebe..62dec05394 100644 --- a/src/cmd/dist/build.c +++ b/src/cmd/dist/build.c @@ -522,10 +522,6 @@ static struct { "anames6.c", "anames8.c", }}, - {"cmd/cc", { - "-pgen.c", - "-pswt.c", - }}, {"cmd/gc", { "-cplx.c", "-pgen.c", @@ -534,21 +530,6 @@ static struct { "-y1.tab.c", // makefile dreg "opnames.h", }}, - {"cmd/5c", { - "../cc/pgen.c", - "../cc/pswt.c", - "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libcc.a", - }}, - {"cmd/6c", { - "../cc/pgen.c", - "../cc/pswt.c", - "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libcc.a", - }}, - {"cmd/8c", { - "../cc/pgen.c", - "../cc/pswt.c", - "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/libcc.a", - }}, {"cmd/5g", { "../gc/cplx.c", "../gc/pgen.c", @@ -591,12 +572,10 @@ static struct { "$GOROOT/pkg/obj/$GOHOSTOS_$GOHOSTARCH/lib9.a", }}, {"runtime", { - "zaexperiment.h", // must sort above zasm - "zasm_$GOOS_$GOARCH.h", + "zaexperiment.h", "zsys_$GOOS_$GOARCH.s", "zgoarch_$GOARCH.go", "zgoos_$GOOS.go", - "zruntime_defs_$GOOS_$GOARCH.go", "zversion.go", }}, }; @@ -618,12 +597,10 @@ static struct { {"anames5.c", mkanames}, {"anames6.c", mkanames}, {"anames8.c", mkanames}, - {"zasm_", mkzasm}, {"zdefaultcc.go", mkzdefaultcc}, {"zsys_", mkzsys}, {"zgoarch_", mkzgoarch}, {"zgoos_", mkzgoos}, - {"zruntime_defs_", mkzruntimedefs}, {"zversion.go", mkzversion}, {"zaexperiment.h", mkzexperiment}, @@ -638,7 +615,7 @@ install(char *dir) { char *name, *p, *elem, *prefix, *exe; bool islib, ispkg, isgo, stale, ispackcmd; - Buf b, b1, path, final_path, final_name; + Buf b, b1, path, final_path, final_name, archive; Vec compile, files, link, go, missing, clean, lib, extra; Time ttarg, t; int i, j, k, n, doclean, targ; @@ -655,6 +632,7 @@ install(char *dir) binit(&path); binit(&final_path); binit(&final_name); + binit(&archive); vinit(&compile); vinit(&files); vinit(&link); @@ -698,7 +676,7 @@ install(char *dir) splitfields(&ldargs, bstr(&b)); } - islib = hasprefix(dir, "lib") || streq(dir, "cmd/cc") || streq(dir, "cmd/gc"); + islib = hasprefix(dir, "lib") || streq(dir, "cmd/gc"); ispkg = !islib && !hasprefix(dir, "cmd/"); isgo = ispkg || streq(dir, "cmd/go") || streq(dir, "cmd/cgo"); @@ -877,17 +855,6 @@ install(char *dir) // For package runtime, copy some files into the work space. if(streq(dir, "runtime")) { - copyfile(bpathf(&b, "%s/arch_GOARCH.h", workdir), - bpathf(&b1, "%s/arch_%s.h", bstr(&path), goarch), 0); - copyfile(bpathf(&b, "%s/defs_GOOS_GOARCH.h", workdir), - bpathf(&b1, "%s/defs_%s_%s.h", bstr(&path), goos, goarch), 0); - p = bpathf(&b1, "%s/signal_%s_%s.h", bstr(&path), goos, goarch); - if(isfile(p)) - copyfile(bpathf(&b, "%s/signal_GOOS_GOARCH.h", workdir), p, 0); - copyfile(bpathf(&b, "%s/os_GOOS.h", workdir), - bpathf(&b1, "%s/os_%s.h", bstr(&path), goos), 0); - copyfile(bpathf(&b, "%s/signals_GOOS.h", workdir), - bpathf(&b1, "%s/signals_%s.h", bstr(&path), goos), 0); copyfile(bpathf(&b, "%s/pkg/%s_%s/textflag.h", goroot, goos, goarch), bpathf(&b1, "%s/src/cmd/ld/textflag.h", goroot), 0); copyfile(bpathf(&b, "%s/pkg/%s_%s/funcdata.h", goroot, goos, goarch), @@ -921,14 +888,6 @@ install(char *dir) built:; } - // One more copy for package runtime. - // The last batch was required for the generators. - // This one is generated. - if(streq(dir, "runtime")) { - copyfile(bpathf(&b, "%s/zasm_GOOS_GOARCH.h", workdir), - bpathf(&b1, "%s/zasm_%s_%s.h", bstr(&path), goos, goarch), 0); - } - if((!streq(goos, gohostos) || !streq(goarch, gohostarch)) && isgo) { // We've generated the right files; the go command can do the build. if(vflag > 1) @@ -936,6 +895,42 @@ install(char *dir) goto nobuild; } + if(isgo) { + // The next loop will compile individual non-Go files. + // Hand the Go files to the compiler en masse. + // For package runtime, this writes go_asm.h, which + // the assembly files will need. + vreset(&compile); + vadd(&compile, bpathf(&b, "%s/%sg", tooldir, gochar)); + + bpathf(&b, "%s/_go_.a", workdir); + vadd(&compile, "-pack"); + vadd(&compile, "-o"); + vadd(&compile, bstr(&b)); + vadd(&clean, bstr(&b)); + if(!ispackcmd) + vadd(&link, bstr(&b)); + else + bwriteb(&archive, &b); + + vadd(&compile, "-p"); + if(hasprefix(dir, "cmd/")) + vadd(&compile, "main"); + else + vadd(&compile, dir); + + if(streq(dir, "runtime")) { + vadd(&compile, "-+"); + vadd(&compile, "-asmhdr"); + bpathf(&b1, "%s/go_asm.h", workdir); + vadd(&compile, bstr(&b1)); + } + + vcopy(&compile, go.p, go.len); + + runv(nil, bstr(&path), CheckExit, &compile); + } + // Compile the files. for(i=0; i= 2) { - n = fields.len; - p = fields.p[n-1]; - if(p[xstrlen(p)-1] == ';') - p[xstrlen(p)-1] = '\0'; - bwritestr(&out, bprintf(&b, "#define %s_%s %s\n", aggr, fields.p[n-1], fields.p[n-2])); - } - if(fields.len == 3 && streq(fields.p[1], "=")) { // generated from enumerated constants - p = fields.p[2]; - if(p[xstrlen(p)-1] == ';') - p[xstrlen(p)-1] = '\0'; - bwritestr(&out, bprintf(&b, "#define const_%s %s\n", fields.p[0], p)); - } - } - - // Some #defines that are used for .c files. - if(streq(goos, "windows")) { - bwritestr(&out, bprintf(&b, "#define cb_max %d\n", MAXWINCB)); - } - - xgetenv(&exp, "GOEXPERIMENT"); - bwritestr(&out, bprintf(&b, "#define GOEXPERIMENT \"%s\"\n", bstr(&exp))); - - // Write both to file and to workdir/zasm_GOOS_GOARCH.h. - writefile(&out, file, 0); - writefile(&out, bprintf(&b, "%s/zasm_GOOS_GOARCH.h", workdir), 0); - - bfree(&in); - bfree(&b); - bfree(&b1); - bfree(&out); - bfree(&exp); - vfree(&argv); - vfree(&lines); - vfree(&fields); -} - // mkzsys writes zsys_$GOOS_$GOARCH.s, // which contains arch or os specific asm code. // @@ -326,143 +167,3 @@ mkzsys(char *dir, char *file) bfree(&out); } - -static char *runtimedefs[] = { - "defs.c", - "malloc.c", - "mcache.c", - "mgc0.c", - "proc.c", - "parfor.c", - "stack.c", -}; - -// mkzruntimedefs writes zruntime_defs_$GOOS_$GOARCH.h, -// which contains Go struct definitions equivalent to the C ones. -// Mostly we just write the output of 6c -q to the file. -// However, we run it on multiple files, so we have to delete -// the duplicated definitions, and we don't care about the funcs, -// so we delete those too. -// -void -mkzruntimedefs(char *dir, char *file) -{ - int i, skip; - char *p; - Buf in, b, b1, out; - Vec argv, lines, fields, seen; - - binit(&in); - binit(&b); - binit(&b1); - binit(&out); - vinit(&argv); - vinit(&lines); - vinit(&fields); - vinit(&seen); - - bwritestr(&out, "// auto generated by go tool dist\n" - "\n"); - - if(streq(goos, "linux")) { - bwritestr(&out, "// +build !android\n\n"); - } - - bwritestr(&out, - "package runtime\n" - "import \"unsafe\"\n" - "var _ unsafe.Pointer\n" - "\n" - ); - - // Do not emit definitions for these. - vadd(&seen, "true"); - vadd(&seen, "false"); - vadd(&seen, "raceenabled"); - vadd(&seen, "allgs"); - - // Run 6c -D GOOS_goos -D GOARCH_goarch -I workdir -q -n -o workdir/runtimedefs - // on each of the runtimedefs C files. - vadd(&argv, bpathf(&b, "%s/%sc", tooldir, gochar)); - vadd(&argv, "-D"); - vadd(&argv, bprintf(&b, "GOOS_%s", goos)); - vadd(&argv, "-D"); - vadd(&argv, bprintf(&b, "GOARCH_%s", goarch)); - vadd(&argv, "-I"); - vadd(&argv, bprintf(&b, "%s", workdir)); - vadd(&argv, "-I"); - vadd(&argv, bprintf(&b, "%s/pkg/%s_%s", goroot, goos, goarch)); - vadd(&argv, "-q"); - vadd(&argv, "-n"); - vadd(&argv, "-o"); - vadd(&argv, bpathf(&b, "%s/runtimedefs", workdir)); - vadd(&argv, ""); - p = argv.p[argv.len-1]; - for(i=0; i= 0) { - if(streq(fields.p[fields.len-1], "{")) - skip = 1; // skip until } - continue; - } - vadd(&seen, fields.p[1]); - } - - // Const lines are printed in original case (usually upper). Add a leading _ as needed. - if(hasprefix(p, "const ")) { - if('A' <= p[6] && p[6] <= 'Z') - bwritestr(&out, "const _"); - else - bwritestr(&out, "const "); - bwritestr(&out, p+6); - continue; - } - - if(skip) { - if(hasprefix(p, "}")) - skip = 0; - continue; - } - - bwritestr(&out, p); - } - - // Some windows specific const. - if(streq(goos, "windows")) { - bwritestr(&out, bprintf(&b, "const cb_max = %d\n", MAXWINCB)); - } - - writefile(&out, file, 0); - - bfree(&in); - bfree(&b); - bfree(&b1); - bfree(&out); - vfree(&argv); - vfree(&lines); - vfree(&fields); - vfree(&seen); -} diff --git a/src/runtime/defs.c b/src/runtime/defs.c deleted file mode 100644 index b0a9b20d7f..0000000000 --- a/src/runtime/defs.c +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// This file is compiled by cmd/dist to obtain debug information -// about the given header files. - -#include "runtime.h" -#include "arch_GOARCH.h" -#include "malloc.h" -#include "type.h" -#include "race.h" -#include "chan.h" -#include "defs_GOOS_GOARCH.h" -#include "os_GOOS.h" diff --git a/src/runtime/go_tls.h b/src/runtime/go_tls.h new file mode 100644 index 0000000000..6a707cf1e8 --- /dev/null +++ b/src/runtime/go_tls.h @@ -0,0 +1,22 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifdef GOARCH_arm +#define LR R14 +#endif + +#ifdef GOARCH_amd64 +#define get_tls(r) MOVQ TLS, r +#define g(r) 0(r)(TLS*1) +#endif + +#ifdef GOARCH_amd64p32 +#define get_tls(r) MOVL TLS, r +#define g(r) 0(r)(TLS*1) +#endif + +#ifdef GOARCH_386 +#define get_tls(r) MOVL TLS, r +#define g(r) 0(r)(TLS*1) +#endif