Syms map[string]*Sym
}
+// isRuntime reports whether p is package runtime.
+func (p *Pkg) isRuntime() bool {
+ if compiling_runtime && p == localpkg {
+ return true
+ }
+ return p.Path == "runtime"
+}
+
// Sym represents an object name. Most commonly, this is a Go identifier naming
// an object declared within a package, but Syms are also used to name internal
// synthesized objects.
var itablinkpkg *Pkg // fake package for runtime itab entries
-var Runtimepkg *Pkg // package runtime
+var Runtimepkg *Pkg // fake package runtime
var racepkg *Pkg // package runtime/race
unsafepkg = mkpkg("unsafe")
unsafepkg.Name = "unsafe"
- // real package, referred to by generated runtime calls
- Runtimepkg = mkpkg("runtime")
+ // Pseudo-package that contains the compiler's builtin
+ // declarations for package runtime. These are declared in a
+ // separate package to avoid conflicts with package runtime's
+ // actual declarations, which may differ intentionally but
+ // insignificantly.
+ Runtimepkg = mkpkg("go.runtime")
Runtimepkg.Name = "runtime"
+ Runtimepkg.Prefix = "runtime"
// pseudo-packages used in symbol tables
itabpkg = mkpkg("go.itab")
if t.Results().NumFields() == 1 {
n.Type = l.Type.Results().Field(0).Type
- if n.Op == OCALLFUNC && n.Left.Op == ONAME && (compiling_runtime || n.Left.Sym.Pkg == Runtimepkg) && n.Left.Sym.Name == "getg" {
+ if n.Op == OCALLFUNC && n.Left.Op == ONAME && n.Left.Sym.Pkg.isRuntime() && n.Left.Sym.Name == "getg" {
// Emit code for runtime.getg() directly instead of calling function.
// Most such rewrites (for example the similar one for math.Sqrt) should be done in walk,
// so that the ordering pass can make sure to preserve the semantics of the original code
on = substArgTypes(on, n.Type) // any-1
} else if isInt[et] {
if et == TUINT64 {
- if (t.Sym.Pkg == Runtimepkg || compiling_runtime) && t.Sym.Name == "hex" {
+ if t.Sym.Pkg.isRuntime() && t.Sym.Name == "hex" {
on = syslook("printhex")
} else {
on = syslook("printuint")
import "runtime"
func main() {
- runtime.printbool(true) // ERROR "unexported"
+ runtime.printbool(true) // ERROR "unexported" "undefined"
}