github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/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 "fmt" 9 "os" 10 "strings" 11 ) 12 13 /* 14 * Helpers for building runtime. 15 */ 16 17 // mkzversion writes zversion.go: 18 // 19 // package sys 20 // const DefaultGoroot = <goroot> 21 // const TheVersion = <version> 22 // const Goexperiment = <goexperiment> 23 // const StackGuardMultiplier = <multiplier value> 24 // 25 func mkzversion(dir, file string) { 26 // FIXME: We need large stacks until we can link in the runtime, 27 // to avoid needing to ever call runtime.morestack. 28 // The + 20 * GoarchRiscv should be removed. 29 out := fmt.Sprintf( 30 "// auto generated by go tool dist\n"+ 31 "\n"+ 32 "package sys\n"+ 33 "\n"+ 34 "const DefaultGoroot = `%s`\n"+ 35 "const TheVersion = `%s`\n"+ 36 "const Goexperiment = `%s`\n"+ 37 "const StackGuardMultiplier = %d + 20 * GoarchRiscv\n\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier()) 38 39 writefile(out, file, writeSkipSame) 40 } 41 42 // mkzbootstrap writes cmd/internal/obj/zbootstrap.go: 43 // 44 // package obj 45 // 46 // const defaultGOROOT = <goroot> 47 // const defaultGO386 = <go386> 48 // const defaultGOARM = <goarm> 49 // const defaultGOOS = runtime.GOOS 50 // const defaultGOARCH = runtime.GOARCH 51 // const defaultGO_EXTLINK_ENABLED = <goextlinkenabled> 52 // const version = <version> 53 // const stackGuardMultiplier = <multiplier value> 54 // const goexperiment = <goexperiment> 55 // 56 // The use of runtime.GOOS and runtime.GOARCH makes sure that 57 // a cross-compiled compiler expects to compile for its own target 58 // system. That is, if on a Mac you do: 59 // 60 // GOOS=linux GOARCH=ppc64 go build cmd/compile 61 // 62 // the resulting compiler will default to generating linux/ppc64 object files. 63 // This is more useful than having it default to generating objects for the 64 // original target (in this example, a Mac). 65 func mkzbootstrap(file string) { 66 out := fmt.Sprintf( 67 "// auto generated by go tool dist\n"+ 68 "\n"+ 69 "package obj\n"+ 70 "\n"+ 71 "import \"runtime\"\n"+ 72 "\n"+ 73 "const defaultGOROOT = `%s`\n"+ 74 "const defaultGO386 = `%s`\n"+ 75 "const defaultGOARM = `%s`\n"+ 76 "const defaultGOOS = runtime.GOOS\n"+ 77 "const defaultGOARCH = runtime.GOARCH\n"+ 78 "const defaultGO_EXTLINK_ENABLED = `%s`\n"+ 79 "const version = `%s`\n"+ 80 "const stackGuardMultiplier = %d\n"+ 81 "const goexperiment = `%s`\n", 82 goroot_final, go386, goarm, goextlinkenabled, findgoversion(), stackGuardMultiplier(), os.Getenv("GOEXPERIMENT")) 83 84 writefile(out, file, writeSkipSame) 85 } 86 87 // stackGuardMultiplier returns a multiplier to apply to the default 88 // stack guard size. Larger multipliers are used for non-optimized 89 // builds that have larger stack frames. 90 func stackGuardMultiplier() int { 91 for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") { 92 if s == "-N" { 93 return 2 94 } 95 } 96 return 1 97 }