aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/dist/buildruntime.go
blob: 6e802219babc5e5cdf40f6358519b3ee0b6e18fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2012 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.

package main

import (
	"fmt"
	"os"
	"strings"
)

/*
 * Helpers for building runtime.
 */

// mkzversion writes zversion.go:
//
//	package sys
//	const DefaultGoroot = <goroot>
//	const TheVersion = <version>
//	const Goexperiment = <goexperiment>
//	const StackGuardMultiplier = <multiplier value>
//
func mkzversion(dir, file string) {
	out := fmt.Sprintf(
		"// auto generated by go tool dist\n"+
			"\n"+
			"package sys\n"+
			"\n"+
			"const DefaultGoroot = `%s`\n"+
			"const TheVersion = `%s`\n"+
			"const Goexperiment = `%s`\n"+
			"const StackGuardMultiplier = %d\n\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())

	writefile(out, file, writeSkipSame)
}

// mkzbootstrap writes cmd/internal/obj/zbootstrap.go:
//
//	package obj
//
//	const defaultGOROOT = <goroot>
//	const defaultGO386 = <go386>
//	const defaultGOARM = <goarm>
//	const defaultGOOS = runtime.GOOS
//	const defaultGOARCH = runtime.GOARCH
//	const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
//	const version = <version>
//	const stackGuardMultiplier = <multiplier value>
//	const goexperiment = <goexperiment>
//
// The use of runtime.GOOS and runtime.GOARCH makes sure that
// a cross-compiled compiler expects to compile for its own target
// system. That is, if on a Mac you do:
//
//	GOOS=linux GOARCH=ppc64 go build cmd/compile
//
// the resulting compiler will default to generating linux/ppc64 object files.
// This is more useful than having it default to generating objects for the
// original target (in this example, a Mac).
func mkzbootstrap(file string) {
	out := fmt.Sprintf(
		"// auto generated by go tool dist\n"+
			"\n"+
			"package obj\n"+
			"\n"+
			"import \"runtime\"\n"+
			"\n"+
			"const defaultGOROOT = `%s`\n"+
			"const defaultGO386 = `%s`\n"+
			"const defaultGOARM = `%s`\n"+
			"const defaultGOOS = runtime.GOOS\n"+
			"const defaultGOARCH = runtime.GOARCH\n"+
			"const defaultGO_EXTLINK_ENABLED = `%s`\n"+
			"const version = `%s`\n"+
			"const stackGuardMultiplier = %d\n"+
			"const goexperiment = `%s`\n",
		goroot_final, go386, goarm, goextlinkenabled, findgoversion(), stackGuardMultiplier(), os.Getenv("GOEXPERIMENT"))

	writefile(out, file, writeSkipSame)
}

// stackGuardMultiplier returns a multiplier to apply to the default
// stack guard size.  Larger multipliers are used for non-optimized
// builds that have larger stack frames.
func stackGuardMultiplier() int {
	for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") {
		if s == "-N" {
			return 2
		}
	}
	return 1
}