...

Source file src/cmd/dist/buildruntime.go

     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 defaultGOPPC64 = <goppc64>
    49	//	const defaultGOOS = runtime.GOOS
    50	//	const defaultGOARCH = runtime.GOARCH
    51	//	const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
    52	//	const version = <version>
    53	//	const stackGuardMultiplierDefault = <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		var buf bytes.Buffer
    67		fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n")
    68		fmt.Fprintln(&buf)
    69		fmt.Fprintf(&buf, "package objabi\n")
    70		fmt.Fprintln(&buf)
    71		fmt.Fprintf(&buf, "import \"runtime\"\n")
    72		fmt.Fprintln(&buf)
    73		fmt.Fprintf(&buf, "const defaultGO386 = `%s`\n", go386)
    74		fmt.Fprintf(&buf, "const defaultGOARM = `%s`\n", goarm)
    75		fmt.Fprintf(&buf, "const defaultGOMIPS = `%s`\n", gomips)
    76		fmt.Fprintf(&buf, "const defaultGOMIPS64 = `%s`\n", gomips64)
    77		fmt.Fprintf(&buf, "const defaultGOPPC64 = `%s`\n", goppc64)
    78		fmt.Fprintf(&buf, "const defaultGOOS = runtime.GOOS\n")
    79		fmt.Fprintf(&buf, "const defaultGOARCH = runtime.GOARCH\n")
    80		fmt.Fprintf(&buf, "const defaultGO_EXTLINK_ENABLED = `%s`\n", goextlinkenabled)
    81		fmt.Fprintf(&buf, "const defaultGO_LDSO = `%s`\n", defaultldso)
    82		fmt.Fprintf(&buf, "const version = `%s`\n", findgoversion())
    83		fmt.Fprintf(&buf, "const stackGuardMultiplierDefault = %d\n", stackGuardMultiplierDefault())
    84		fmt.Fprintf(&buf, "const goexperiment = `%s`\n", os.Getenv("GOEXPERIMENT"))
    85	
    86		writefile(buf.String(), file, writeSkipSame)
    87	}
    88	
    89	// stackGuardMultiplierDefault returns a multiplier to apply to the default
    90	// stack guard size. Larger multipliers are used for non-optimized
    91	// builds that have larger stack frames.
    92	func stackGuardMultiplierDefault() int {
    93		for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") {
    94			if s == "-N" {
    95				return 2
    96			}
    97		}
    98		return 1
    99	}
   100	

View as plain text