From 8d0c44921bdf00fe84651380bf52f8f6524a1abd Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Fri, 23 Mar 2018 07:20:22 +0000 Subject: [PATCH] goruntime: split bootstrap symbols into conditionally compiled files Due to some changes in the runtime init functions between go 1.7 and later versions (e.g. runtime.modulesInit() defined after go 1.7), the kernel code that bootstraps the go runtime had to be split into separate files which are conditionally compiled using +build flags. --- src/gopheros/kernel/goruntime/bootstrap.go | 23 +------------- .../kernel/goruntime/bootstrap_go17.go | 30 +++++++++++++++++++ .../kernel/goruntime/bootstrap_go18+.go | 28 +++++++++++++++++ 3 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 src/gopheros/kernel/goruntime/bootstrap_go17.go create mode 100644 src/gopheros/kernel/goruntime/bootstrap_go18+.go diff --git a/src/gopheros/kernel/goruntime/bootstrap.go b/src/gopheros/kernel/goruntime/bootstrap.go index e51fedc..4bdd5bd 100644 --- a/src/gopheros/kernel/goruntime/bootstrap.go +++ b/src/gopheros/kernel/goruntime/bootstrap.go @@ -27,27 +27,6 @@ var ( prngSeed = 0xdeadc0de ) -//go:linkname algInit runtime.alginit -func algInit() - -//go:linkname modulesInit runtime.modulesinit -func modulesInit() - -//go:linkname typeLinksInit runtime.typelinksinit -func typeLinksInit() - -//go:linkname itabsInit runtime.itabsinit -func itabsInit() - -//go:linkname mallocInit runtime.mallocinit -func mallocInit() - -//go:linkname mSysStatInc runtime.mSysStatInc -func mSysStatInc(*uint64, uintptr) - -//go:linkname procResize runtime.procresize -func procResize(int32) uintptr - // initGoPackages is an alias to main.init which recursively calls the init() // methods in all imported packages. Unless this function is called, things like // package errors will not be properly initialized causing various problems when @@ -184,7 +163,7 @@ func getRandomData(r []byte) { func Init() *kernel.Error { mallocInitFn() algInitFn() // setup hash implementation for map keys - modulesInitFn() // provides activeModules + modulesInitFn() // provides activeModules (go 1.8+) typeLinksInitFn() // uses maps, activeModules itabsInitFn() // uses activeModules diff --git a/src/gopheros/kernel/goruntime/bootstrap_go17.go b/src/gopheros/kernel/goruntime/bootstrap_go17.go new file mode 100644 index 0000000..6022c01 --- /dev/null +++ b/src/gopheros/kernel/goruntime/bootstrap_go17.go @@ -0,0 +1,30 @@ +// +build go1.7,!go1.8 + +package goruntime + +import ( + _ "unsafe" // required for go:linkname +) + +//go:linkname algInit runtime.alginit +func algInit() + +//go:linkname typeLinksInit runtime.typelinksinit +func typeLinksInit() + +//go:linkname itabsInit runtime.itabsinit +func itabsInit() + +//go:linkname mallocInit runtime.mallocinit +func mallocInit() + +//go:linkname mSysStatInc runtime.mSysStatInc +func mSysStatInc(*uint64, uintptr) + +//go:linkname procResize runtime.procresize +func procResize(int32) uintptr + +// modulesInit is defined on go1.8 so just declare an empty +// stub for go 1.7 to keep the compiler happy. +func modulesInit() { +} diff --git a/src/gopheros/kernel/goruntime/bootstrap_go18+.go b/src/gopheros/kernel/goruntime/bootstrap_go18+.go new file mode 100644 index 0000000..90eaaf2 --- /dev/null +++ b/src/gopheros/kernel/goruntime/bootstrap_go18+.go @@ -0,0 +1,28 @@ +// +build go1.8 + +package goruntime + +import ( + _ "unsafe" // required for go:linkname +) + +//go:linkname algInit runtime.alginit +func algInit() + +//go:linkname modulesInit runtime.modulesinit +func modulesInit() + +//go:linkname typeLinksInit runtime.typelinksinit +func typeLinksInit() + +//go:linkname itabsInit runtime.itabsinit +func itabsInit() + +//go:linkname mallocInit runtime.mallocinit +func mallocInit() + +//go:linkname mSysStatInc runtime.mSysStatInc +func mSysStatInc(*uint64, uintptr) + +//go:linkname procResize runtime.procresize +func procResize(int32) uintptr