github.com/zxy12/go_duplicate_112_new@v0.0.0-20200807091221-747231827200/src/cmd/dist/build_runtime.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 StackGuardMultiplierDefault = %d\n", stackGuardMultiplierDefault()) 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 defaultGOMIPS64 = <gomips64> 48 // const defaultGOOS = runtime.GOOS 49 // const defaultGOARCH = runtime.GOARCH 50 // const defaultGO_EXTLINK_ENABLED = <goextlinkenabled> 51 // const version = <version> 52 // const stackGuardMultiplierDefault = <multiplier value> 53 // const goexperiment = <goexperiment> 54 // 55 // The use of runtime.GOOS and runtime.GOARCH makes sure that 56 // a cross-compiled compiler expects to compile for its own target 57 // system. That is, if on a Mac you do: 58 // 59 // GOOS=linux GOARCH=ppc64 go build cmd/compile 60 // 61 // the resulting compiler will default to generating linux/ppc64 object files. 62 // This is more useful than having it default to generating objects for the 63 // original target (in this example, a Mac). 64 func mkzbootstrap(file string) { 65 var buf bytes.Buffer 66 fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n") 67 fmt.Fprintln(&buf) 68 fmt.Fprintf(&buf, "package objabi\n") 69 fmt.Fprintln(&buf) 70 fmt.Fprintf(&buf, "import \"runtime\"\n") 71 fmt.Fprintln(&buf) 72 fmt.Fprintf(&buf, "const defaultGO386 = `%s`\n", go386) 73 fmt.Fprintf(&buf, "const defaultGOARM = `%s`\n", goarm) 74 fmt.Fprintf(&buf, "const defaultGOMIPS = `%s`\n", gomips) 75 fmt.Fprintf(&buf, "const defaultGOMIPS64 = `%s`\n", gomips64) 76 fmt.Fprintf(&buf, "const defaultGOOS = runtime.GOOS\n") 77 fmt.Fprintf(&buf, "const defaultGOARCH = runtime.GOARCH\n") 78 fmt.Fprintf(&buf, "const defaultGO_EXTLINK_ENABLED = `%s`\n", goextlinkenabled) 79 fmt.Fprintf(&buf, "const version = `%s`\n", findgoversion()) 80 fmt.Fprintf(&buf, "const stackGuardMultiplierDefault = %d\n", stackGuardMultiplierDefault()) 81 fmt.Fprintf(&buf, "const goexperiment = `%s`\n", os.Getenv("GOEXPERIMENT")) 82 83 writefile(buf.String(), file, writeSkipSame) 84 } 85 86 // stackGuardMultiplierDefault returns a multiplier to apply to the default 87 // stack guard size. Larger multipliers are used for non-optimized 88 // builds that have larger stack frames. 89 func stackGuardMultiplierDefault() int { 90 for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") { 91 if s == "-N" { 92 return 2 93 } 94 } 95 return 1 96 }