github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/cmd/dist/buildruntime.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "bytes" 9 "fmt" 10 "os" 11 "strings" 12 ) 13 14 /* 15 * Helpers for building runtime. 16 */ 17 18 // mkzversion writes zversion.go: 19 // 20 // package sys 21 // 22 // const TheVersion = <version> 23 // const Goexperiment = <goexperiment> 24 // const StackGuardMultiplier = <multiplier value> 25 // 26 func mkzversion(dir, file string) { 27 var buf bytes.Buffer 28 fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") 29 fmt.Fprintln(&buf) 30 fmt.Fprintf(&buf, "package sys\n") 31 fmt.Fprintln(&buf) 32 fmt.Fprintf(&buf, "const TheVersion = `%s`\n", findgoversion()) 33 fmt.Fprintf(&buf, "const Goexperiment = `%s`\n", os.Getenv("GOEXPERIMENT")) 34 fmt.Fprintf(&buf, "const StackGuardMultiplier = %d\n", stackGuardMultiplier()) 35 36 writefile(buf.String(), file, writeSkipSame) 37 } 38 39 // mkzbootstrap writes cmd/internal/objabi/zbootstrap.go: 40 // 41 // package objabi 42 // 43 // const defaultGOROOT = <goroot> 44 // const defaultGO386 = <go386> 45 // const defaultGOARM = <goarm> 46 // const defaultGOMIPS = <gomips> 47 // const defaultGOOS = runtime.GOOS 48 // const defaultGOARCH = runtime.GOARCH 49 // const defaultGO_EXTLINK_ENABLED = <goextlinkenabled> 50 // const version = <version> 51 // const stackGuardMultiplier = <multiplier value> 52 // const goexperiment = <goexperiment> 53 // 54 // The use of runtime.GOOS and runtime.GOARCH makes sure that 55 // a cross-compiled compiler expects to compile for its own target 56 // system. That is, if on a Mac you do: 57 // 58 // GOOS=linux GOARCH=ppc64 go build cmd/compile 59 // 60 // the resulting compiler will default to generating linux/ppc64 object files. 61 // This is more useful than having it default to generating objects for the 62 // original target (in this example, a Mac). 63 func mkzbootstrap(file string) { 64 var buf bytes.Buffer 65 fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") 66 fmt.Fprintln(&buf) 67 fmt.Fprintf(&buf, "package objabi\n") 68 fmt.Fprintln(&buf) 69 fmt.Fprintf(&buf, "import \"runtime\"\n") 70 fmt.Fprintln(&buf) 71 fmt.Fprintf(&buf, "const defaultGO386 = `%s`\n", go386) 72 fmt.Fprintf(&buf, "const defaultGOARM = `%s`\n", goarm) 73 fmt.Fprintf(&buf, "const defaultGOMIPS = `%s`\n", gomips) 74 fmt.Fprintf(&buf, "const defaultGOOS = runtime.GOOS\n") 75 fmt.Fprintf(&buf, "const defaultGOARCH = runtime.GOARCH\n") 76 fmt.Fprintf(&buf, "const defaultGO_EXTLINK_ENABLED = `%s`\n", goextlinkenabled) 77 fmt.Fprintf(&buf, "const version = `%s`\n", findgoversion()) 78 fmt.Fprintf(&buf, "const stackGuardMultiplier = %d\n", stackGuardMultiplier()) 79 fmt.Fprintf(&buf, "const goexperiment = `%s`\n", os.Getenv("GOEXPERIMENT")) 80 81 writefile(buf.String(), file, writeSkipSame) 82 } 83 84 // stackGuardMultiplier returns a multiplier to apply to the default 85 // stack guard size. Larger multipliers are used for non-optimized 86 // builds that have larger stack frames. 87 func stackGuardMultiplier() int { 88 for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") { 89 if s == "-N" { 90 return 2 91 } 92 } 93 return 1 94 }