Skip to content

Commit 432cb66

Browse files
committed
runtime: break out system-specific constants into package sys
runtime/internal/sys will hold system-, architecture- and config- specific constants. Updates #11647 Change-Id: I6db29c312556087a42e8d2bdd9af40d157c56b54 Reviewed-on: https://go-review.googlesource.com/16817 Reviewed-by: Russ Cox <[email protected]>
1 parent b5a0c67 commit 432cb66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1049
-749
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ src/cmd/cgo/zdefaultcc.go
2929
src/cmd/go/zdefaultcc.go
3030
src/cmd/internal/obj/zbootstrap.go
3131
src/go/doc/headscan
32-
src/runtime/zversion.go
32+
src/runtime/internal/sys/zversion.go
3333
src/unicode/maketables
3434
src/*.*/
3535
test/pass.out

src/cmd/compile/internal/gc/racewalk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
// Do not instrument the following packages at all,
3333
// at best instrumentation would cause infinite recursion.
34-
var omit_pkgs = []string{"runtime/internal/atomic", "runtime", "runtime/race", "runtime/msan"}
34+
var omit_pkgs = []string{"runtime/internal/atomic", "runtime/internal/sys", "runtime", "runtime/race", "runtime/msan"}
3535

3636
// Only insert racefuncenter/racefuncexit into the following packages.
3737
// Memory accesses in the packages are either uninteresting or will cause false positives.

src/cmd/dist/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ var deptab = []struct {
463463
{"cmd/go", []string{
464464
"zdefaultcc.go",
465465
}},
466-
{"runtime", []string{
466+
{"runtime/internal/sys", []string{
467467
"zversion.go",
468468
}},
469469
}

src/cmd/dist/buildruntime.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ import (
1717
// mkzversion writes zversion.go:
1818
//
1919
// package runtime
20-
// const defaultGoroot = <goroot>
21-
// const theVersion = <version>
22-
// const goexperiment = <goexperiment>
23-
// const stackGuardMultiplier = <multiplier value>
24-
// const buildVersion = <build version>
20+
// const DefaultGoroot = <goroot>
21+
// const TheVersion = <version>
22+
// const Goexperiment = <goexperiment>
23+
// const StackGuardMultiplier = <multiplier value>
24+
// const BuildVersion = <build version>
2525
//
2626
func mkzversion(dir, file string) {
2727
out := fmt.Sprintf(
2828
"// auto generated by go tool dist\n"+
2929
"\n"+
30-
"package runtime\n"+
30+
"package sys\n"+
3131
"\n"+
32-
"const defaultGoroot = `%s`\n"+
33-
"const theVersion = `%s`\n"+
34-
"const goexperiment = `%s`\n"+
35-
"const stackGuardMultiplier = %d\n\n"+
36-
"var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())
32+
"const DefaultGoroot = `%s`\n"+
33+
"const TheVersion = `%s`\n"+
34+
"const Goexperiment = `%s`\n"+
35+
"const StackGuardMultiplier = %d\n\n"+
36+
"var BuildVersion = TheVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())
3737

3838
writefile(out, file, writeSkipSame)
3939
}

src/cmd/dist/deps.go

Lines changed: 52 additions & 51 deletions
Large diffs are not rendered by default.

src/go/build/deps_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ var pkgDeps = map[string][]string{
3636
// L0 is the lowest level, core, nearly unavoidable packages.
3737
"errors": {},
3838
"io": {"errors", "sync"},
39-
"runtime": {"unsafe", "runtime/internal/atomic"},
39+
"runtime": {"unsafe", "runtime/internal/atomic", "runtime/internal/sys"},
40+
"runtime/internal/sys": {},
4041
"runtime/internal/atomic": {"unsafe"},
4142
"sync": {"runtime", "sync/atomic", "unsafe"},
4243
"sync/atomic": {"unsafe"},

src/runtime/alg.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
package runtime
66

7-
import "unsafe"
7+
import (
8+
"runtime/internal/sys"
9+
"unsafe"
10+
)
811

912
const (
10-
c0 = uintptr((8-ptrSize)/4*2860486313 + (ptrSize-4)/4*33054211828000289)
11-
c1 = uintptr((8-ptrSize)/4*3267000013 + (ptrSize-4)/4*23344194077549503)
13+
c0 = uintptr((8-sys.PtrSize)/4*2860486313 + (sys.PtrSize-4)/4*33054211828000289)
14+
c1 = uintptr((8-sys.PtrSize)/4*3267000013 + (sys.PtrSize-4)/4*23344194077549503)
1215
)
1316

1417
// type algorithms - known to compiler
@@ -301,7 +304,7 @@ func memclrBytes(b []byte) {
301304
memclr(s.array, uintptr(s.len))
302305
}
303306

304-
const hashRandomBytes = ptrSize / 4 * 64
307+
const hashRandomBytes = sys.PtrSize / 4 * 64
305308

306309
// used in asm_{386,amd64}.s to seed the hash function
307310
var aeskeysched [hashRandomBytes]byte
@@ -324,7 +327,7 @@ func init() {
324327
getRandomData(aeskeysched[:])
325328
return
326329
}
327-
getRandomData((*[len(hashkey) * ptrSize]byte)(unsafe.Pointer(&hashkey))[:])
330+
getRandomData((*[len(hashkey) * sys.PtrSize]byte)(unsafe.Pointer(&hashkey))[:])
328331
hashkey[0] |= 1 // make sure these numbers are odd
329332
hashkey[1] |= 1
330333
hashkey[2] |= 1

src/runtime/arch_386.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/runtime/arch_amd64.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/runtime/arch_amd64p32.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/runtime/arch_arm.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/runtime/arch_arm64.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/runtime/arch_ppc64.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/runtime/arch_ppc64le.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/runtime/cgocall.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@
7979

8080
package runtime
8181

82-
import "unsafe"
82+
import (
83+
"runtime/internal/sys"
84+
"unsafe"
85+
)
8386

8487
// Call from Go to C.
8588
//go:nosplit
@@ -220,22 +223,22 @@ func cgocallbackg1() {
220223
case "arm":
221224
// On arm, stack frame is two words and there's a saved LR between
222225
// SP and the stack frame and between the stack frame and the arguments.
223-
cb = (*args)(unsafe.Pointer(sp + 4*ptrSize))
226+
cb = (*args)(unsafe.Pointer(sp + 4*sys.PtrSize))
224227
case "arm64":
225228
// On arm64, stack frame is four words and there's a saved LR between
226229
// SP and the stack frame and between the stack frame and the arguments.
227-
cb = (*args)(unsafe.Pointer(sp + 5*ptrSize))
230+
cb = (*args)(unsafe.Pointer(sp + 5*sys.PtrSize))
228231
case "amd64":
229232
// On amd64, stack frame is one word, plus caller PC.
230233
if framepointer_enabled {
231234
// In this case, there's also saved BP.
232-
cb = (*args)(unsafe.Pointer(sp + 3*ptrSize))
235+
cb = (*args)(unsafe.Pointer(sp + 3*sys.PtrSize))
233236
break
234237
}
235-
cb = (*args)(unsafe.Pointer(sp + 2*ptrSize))
238+
cb = (*args)(unsafe.Pointer(sp + 2*sys.PtrSize))
236239
case "386":
237240
// On 386, stack frame is three words, plus caller PC.
238-
cb = (*args)(unsafe.Pointer(sp + 4*ptrSize))
241+
cb = (*args)(unsafe.Pointer(sp + 4*sys.PtrSize))
239242
case "ppc64", "ppc64le":
240243
// On ppc64, the callback arguments are in the arguments area of
241244
// cgocallback's stack frame. The stack looks like this:
@@ -252,7 +255,7 @@ func cgocallbackg1() {
252255
// | cgocallback_gofunc +------------------------------+ <- sp + minFrameSize
253256
// | | fixed frame area |
254257
// +--------------------+------------------------------+ <- sp
255-
cb = (*args)(unsafe.Pointer(sp + 2*minFrameSize + 2*ptrSize))
258+
cb = (*args)(unsafe.Pointer(sp + 2*sys.MinFrameSize + 2*sys.PtrSize))
256259
}
257260

258261
// Invoke callback.
@@ -291,7 +294,7 @@ func unwindm(restore *bool) {
291294
default:
292295
throw("unwindm not implemented")
293296
case "386", "amd64", "arm", "ppc64", "ppc64le":
294-
sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + minFrameSize))
297+
sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + sys.MinFrameSize))
295298
case "arm64":
296299
sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + 16))
297300
}
@@ -437,7 +440,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool) {
437440
if inheap(uintptr(unsafe.Pointer(it))) {
438441
panic(errorString(cgoCheckPointerFail))
439442
}
440-
p = *(*unsafe.Pointer)(unsafe.Pointer(uintptr(p) + ptrSize))
443+
p = *(*unsafe.Pointer)(unsafe.Pointer(uintptr(p) + sys.PtrSize))
441444
if !cgoIsGoPointer(p) {
442445
return
443446
}
@@ -505,9 +508,9 @@ func cgoCheckUnknownPointer(p unsafe.Pointer) {
505508
return
506509
}
507510
n := span.elemsize
508-
for i := uintptr(0); i < n; i += ptrSize {
511+
for i := uintptr(0); i < n; i += sys.PtrSize {
509512
bits := hbits.bits()
510-
if i >= 2*ptrSize && bits&bitMarked == 0 {
513+
if i >= 2*sys.PtrSize && bits&bitMarked == 0 {
511514
// No more possible pointers.
512515
break
513516
}

src/runtime/export_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package runtime
88

99
import (
1010
"runtime/internal/atomic"
11+
"runtime/internal/sys"
1112
"unsafe"
1213
)
1314

@@ -115,7 +116,7 @@ func GostringW(w []uint16) (s string) {
115116
var Gostringnocopy = gostringnocopy
116117
var Maxstring = &maxstring
117118

118-
type Uintreg uintreg
119+
type Uintreg sys.Uintreg
119120

120121
var Open = open
121122
var Close = closefd
@@ -125,7 +126,7 @@ var Write = write
125126
func Envs() []string { return envs }
126127
func SetEnvs(e []string) { envs = e }
127128

128-
var BigEndian = _BigEndian
129+
var BigEndian = sys.BigEndian
129130

130131
// For benchmarking.
131132

@@ -156,7 +157,7 @@ func BenchSetType(n int, x interface{}) {
156157
})
157158
}
158159

159-
const PtrSize = ptrSize
160+
const PtrSize = sys.PtrSize
160161

161162
var TestingAssertE2I2GC = &testingAssertE2I2GC
162163
var TestingAssertE2T2GC = &testingAssertE2T2GC

src/runtime/extern.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ of the run-time system.
130130
*/
131131
package runtime
132132

133+
import "runtime/internal/sys"
134+
133135
// Caller reports file and line number information about function invocations on
134136
// the calling goroutine's stack. The argument skip is the number of stack frames
135137
// to ascend, with 0 identifying the caller of Caller. (For historical reasons the
@@ -199,20 +201,20 @@ func GOROOT() string {
199201
if s != "" {
200202
return s
201203
}
202-
return defaultGoroot
204+
return sys.DefaultGoroot
203205
}
204206

205207
// Version returns the Go tree's version string.
206208
// It is either the commit hash and date at the time of the build or,
207209
// when possible, a release tag like "go1.3".
208210
func Version() string {
209-
return theVersion
211+
return sys.TheVersion
210212
}
211213

212214
// GOOS is the running program's operating system target:
213215
// one of darwin, freebsd, linux, and so on.
214-
const GOOS string = theGoos
216+
const GOOS string = sys.TheGoos
215217

216218
// GOARCH is the running program's architecture target:
217219
// 386, amd64, or arm.
218-
const GOARCH string = theGoarch
220+
const GOARCH string = sys.TheGoarch

0 commit comments

Comments
 (0)