Skip to content

Commit

Permalink
runtime: break out system-specific constants into package sys
Browse files Browse the repository at this point in the history
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 <rsc@golang.org>
  • Loading branch information
matloob committed Nov 12, 2015
1 parent b5a0c67 commit 432cb66
Show file tree
Hide file tree
Showing 101 changed files with 1,049 additions and 749 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ src/cmd/cgo/zdefaultcc.go
src/cmd/go/zdefaultcc.go
src/cmd/internal/obj/zbootstrap.go
src/go/doc/headscan
src/runtime/zversion.go
src/runtime/internal/sys/zversion.go
src/unicode/maketables
src/*.*/
test/pass.out
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/racewalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

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

// Only insert racefuncenter/racefuncexit into the following packages.
// Memory accesses in the packages are either uninteresting or will cause false positives.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ var deptab = []struct {
{"cmd/go", []string{
"zdefaultcc.go",
}},
{"runtime", []string{
{"runtime/internal/sys", []string{
"zversion.go",
}},
}
Expand Down
22 changes: 11 additions & 11 deletions src/cmd/dist/buildruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ import (
// mkzversion writes zversion.go:
//
// package runtime
// const defaultGoroot = <goroot>
// const theVersion = <version>
// const goexperiment = <goexperiment>
// const stackGuardMultiplier = <multiplier value>
// const buildVersion = <build version>
// const DefaultGoroot = <goroot>
// const TheVersion = <version>
// const Goexperiment = <goexperiment>
// const StackGuardMultiplier = <multiplier value>
// const BuildVersion = <build version>
//
func mkzversion(dir, file string) {
out := fmt.Sprintf(
"// auto generated by go tool dist\n"+
"\n"+
"package runtime\n"+
"package sys\n"+
"\n"+
"const defaultGoroot = `%s`\n"+
"const theVersion = `%s`\n"+
"const goexperiment = `%s`\n"+
"const stackGuardMultiplier = %d\n\n"+
"var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())
"const DefaultGoroot = `%s`\n"+
"const TheVersion = `%s`\n"+
"const Goexperiment = `%s`\n"+
"const StackGuardMultiplier = %d\n\n"+
"var BuildVersion = TheVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())

writefile(out, file, writeSkipSame)
}
Expand Down
103 changes: 52 additions & 51 deletions src/cmd/dist/deps.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/go/build/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ var pkgDeps = map[string][]string{
// L0 is the lowest level, core, nearly unavoidable packages.
"errors": {},
"io": {"errors", "sync"},
"runtime": {"unsafe", "runtime/internal/atomic"},
"runtime": {"unsafe", "runtime/internal/atomic", "runtime/internal/sys"},
"runtime/internal/sys": {},
"runtime/internal/atomic": {"unsafe"},
"sync": {"runtime", "sync/atomic", "unsafe"},
"sync/atomic": {"unsafe"},
Expand Down
13 changes: 8 additions & 5 deletions src/runtime/alg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

package runtime

import "unsafe"
import (
"runtime/internal/sys"
"unsafe"
)

const (
c0 = uintptr((8-ptrSize)/4*2860486313 + (ptrSize-4)/4*33054211828000289)
c1 = uintptr((8-ptrSize)/4*3267000013 + (ptrSize-4)/4*23344194077549503)
c0 = uintptr((8-sys.PtrSize)/4*2860486313 + (sys.PtrSize-4)/4*33054211828000289)
c1 = uintptr((8-sys.PtrSize)/4*3267000013 + (sys.PtrSize-4)/4*23344194077549503)
)

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

const hashRandomBytes = ptrSize / 4 * 64
const hashRandomBytes = sys.PtrSize / 4 * 64

// used in asm_{386,amd64}.s to seed the hash function
var aeskeysched [hashRandomBytes]byte
Expand All @@ -324,7 +327,7 @@ func init() {
getRandomData(aeskeysched[:])
return
}
getRandomData((*[len(hashkey) * ptrSize]byte)(unsafe.Pointer(&hashkey))[:])
getRandomData((*[len(hashkey) * sys.PtrSize]byte)(unsafe.Pointer(&hashkey))[:])
hashkey[0] |= 1 // make sure these numbers are odd
hashkey[1] |= 1
hashkey[2] |= 1
Expand Down
19 changes: 0 additions & 19 deletions src/runtime/arch_386.go

This file was deleted.

19 changes: 0 additions & 19 deletions src/runtime/arch_amd64.go

This file was deleted.

19 changes: 0 additions & 19 deletions src/runtime/arch_amd64p32.go

This file was deleted.

19 changes: 0 additions & 19 deletions src/runtime/arch_arm.go

This file was deleted.

19 changes: 0 additions & 19 deletions src/runtime/arch_arm64.go

This file was deleted.

19 changes: 0 additions & 19 deletions src/runtime/arch_ppc64.go

This file was deleted.

19 changes: 0 additions & 19 deletions src/runtime/arch_ppc64le.go

This file was deleted.

25 changes: 14 additions & 11 deletions src/runtime/cgocall.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@

package runtime

import "unsafe"
import (
"runtime/internal/sys"
"unsafe"
)

// Call from Go to C.
//go:nosplit
Expand Down Expand Up @@ -220,22 +223,22 @@ func cgocallbackg1() {
case "arm":
// On arm, stack frame is two words and there's a saved LR between
// SP and the stack frame and between the stack frame and the arguments.
cb = (*args)(unsafe.Pointer(sp + 4*ptrSize))
cb = (*args)(unsafe.Pointer(sp + 4*sys.PtrSize))
case "arm64":
// On arm64, stack frame is four words and there's a saved LR between
// SP and the stack frame and between the stack frame and the arguments.
cb = (*args)(unsafe.Pointer(sp + 5*ptrSize))
cb = (*args)(unsafe.Pointer(sp + 5*sys.PtrSize))
case "amd64":
// On amd64, stack frame is one word, plus caller PC.
if framepointer_enabled {
// In this case, there's also saved BP.
cb = (*args)(unsafe.Pointer(sp + 3*ptrSize))
cb = (*args)(unsafe.Pointer(sp + 3*sys.PtrSize))
break
}
cb = (*args)(unsafe.Pointer(sp + 2*ptrSize))
cb = (*args)(unsafe.Pointer(sp + 2*sys.PtrSize))
case "386":
// On 386, stack frame is three words, plus caller PC.
cb = (*args)(unsafe.Pointer(sp + 4*ptrSize))
cb = (*args)(unsafe.Pointer(sp + 4*sys.PtrSize))
case "ppc64", "ppc64le":
// On ppc64, the callback arguments are in the arguments area of
// cgocallback's stack frame. The stack looks like this:
Expand All @@ -252,7 +255,7 @@ func cgocallbackg1() {
// | cgocallback_gofunc +------------------------------+ <- sp + minFrameSize
// | | fixed frame area |
// +--------------------+------------------------------+ <- sp
cb = (*args)(unsafe.Pointer(sp + 2*minFrameSize + 2*ptrSize))
cb = (*args)(unsafe.Pointer(sp + 2*sys.MinFrameSize + 2*sys.PtrSize))
}

// Invoke callback.
Expand Down Expand Up @@ -291,7 +294,7 @@ func unwindm(restore *bool) {
default:
throw("unwindm not implemented")
case "386", "amd64", "arm", "ppc64", "ppc64le":
sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + minFrameSize))
sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + sys.MinFrameSize))
case "arm64":
sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + 16))
}
Expand Down Expand Up @@ -437,7 +440,7 @@ func cgoCheckArg(t *_type, p unsafe.Pointer, indir, top bool) {
if inheap(uintptr(unsafe.Pointer(it))) {
panic(errorString(cgoCheckPointerFail))
}
p = *(*unsafe.Pointer)(unsafe.Pointer(uintptr(p) + ptrSize))
p = *(*unsafe.Pointer)(unsafe.Pointer(uintptr(p) + sys.PtrSize))
if !cgoIsGoPointer(p) {
return
}
Expand Down Expand Up @@ -505,9 +508,9 @@ func cgoCheckUnknownPointer(p unsafe.Pointer) {
return
}
n := span.elemsize
for i := uintptr(0); i < n; i += ptrSize {
for i := uintptr(0); i < n; i += sys.PtrSize {
bits := hbits.bits()
if i >= 2*ptrSize && bits&bitMarked == 0 {
if i >= 2*sys.PtrSize && bits&bitMarked == 0 {
// No more possible pointers.
break
}
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package runtime

import (
"runtime/internal/atomic"
"runtime/internal/sys"
"unsafe"
)

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

type Uintreg uintreg
type Uintreg sys.Uintreg

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

var BigEndian = _BigEndian
var BigEndian = sys.BigEndian

// For benchmarking.

Expand Down Expand Up @@ -156,7 +157,7 @@ func BenchSetType(n int, x interface{}) {
})
}

const PtrSize = ptrSize
const PtrSize = sys.PtrSize

var TestingAssertE2I2GC = &testingAssertE2I2GC
var TestingAssertE2T2GC = &testingAssertE2T2GC
Expand Down
10 changes: 6 additions & 4 deletions src/runtime/extern.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ of the run-time system.
*/
package runtime

import "runtime/internal/sys"

// Caller reports file and line number information about function invocations on
// the calling goroutine's stack. The argument skip is the number of stack frames
// to ascend, with 0 identifying the caller of Caller. (For historical reasons the
Expand Down Expand Up @@ -199,20 +201,20 @@ func GOROOT() string {
if s != "" {
return s
}
return defaultGoroot
return sys.DefaultGoroot
}

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

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

// GOARCH is the running program's architecture target:
// 386, amd64, or arm.
const GOARCH string = theGoarch
const GOARCH string = sys.TheGoarch
Loading

0 comments on commit 432cb66

Please sign in to comment.