Skip to content

Commit

Permalink
cmd/compile: define func value symbols at declaration
Browse files Browse the repository at this point in the history
This is mostly Russ's https://golang.org/cl/12145 but with some extra fixes to
account for the fact that function declarations without implementations now
break shared libraries, and including my test case.

Fixes golang#11480.

Change-Id: Iabdc2934a0378e5025e4e7affadb535eaef2c8f1
Reviewed-on: https://go-review.googlesource.com/12340
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
mwhudson authored and ianlancetaylor committed Jul 20, 2015
1 parent 4db0746 commit 1125cd4
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 9 deletions.
10 changes: 10 additions & 0 deletions misc/cgo/testshared/src/dep/asm.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2014 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.

//+build !gccgo

#include "textflag.h"

TEXT ·ImplementedInAsm(SB),NOSPLIT,$0-0
RET
5 changes: 5 additions & 0 deletions misc/cgo/testshared/src/dep/gccgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//+build gccgo

package dep

func ImplementedInAsm() {}
5 changes: 5 additions & 0 deletions misc/cgo/testshared/src/dep/stubs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//+build !gccgo

package dep

func ImplementedInAsm()
7 changes: 6 additions & 1 deletion misc/cgo/testshared/src/exe/exe.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package main

import "dep"
import (
"dep"
"runtime"
)

func main() {
defer dep.ImplementedInAsm()
runtime.GC()
dep.V = dep.F() + 1
}
1 change: 1 addition & 0 deletions src/cmd/compile/internal/gc/closure.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func makeclosure(func_ *Node) *Node {
xfunc.Func.Nname.Name.Funcdepth = func_.Func.Depth
xfunc.Func.Depth = func_.Func.Depth
xfunc.Func.Endlineno = func_.Func.Endlineno
makefuncsym(xfunc.Func.Nname.Sym)

xfunc.Nbody = func_.Nbody
xfunc.Func.Dcl = concat(func_.Func.Dcl, xfunc.Func.Dcl)
Expand Down
25 changes: 19 additions & 6 deletions src/cmd/compile/internal/gc/dcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ func funchdr(n *Node) {
Fatal("funchdr: dclcontext")
}

if importpkg == nil && n.Func.Nname != nil {
makefuncsym(n.Func.Nname.Sym)
}

dclcontext = PAUTO
markdcl()
Funcdepth++
Expand Down Expand Up @@ -1489,12 +1493,21 @@ func funcsym(s *Sym) *Sym {
}

s1 := Pkglookup(s.Name+"·f", s.Pkg)
if s1.Def == nil {
s1.Def = newfuncname(s1)
s1.Def.Func.Shortname = newname(s)
funcsyms = list(funcsyms, s1.Def)
}
s.Fsym = s1

return s1
}

func makefuncsym(s *Sym) {
if isblanksym(s) {
return
}
if compiling_runtime != 0 && s.Name == "getg" {
// runtime.getg() is not a real function and so does
// not get a funcsym.
return
}
s1 := funcsym(s)
s1.Def = newfuncname(s1)
s1.Def.Func.Shortname = newname(s)
funcsyms = list(funcsyms, s1.Def)
}
1 change: 0 additions & 1 deletion src/runtime/debug/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ func setMaxThreads(int) int

// Implemented in package runtime.
func readGCStats(*[]time.Duration)
func enableGC(bool) bool
func freeOSMemory()
1 change: 0 additions & 1 deletion src/runtime/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ func time_now() (sec int64, nsec int32)

// in asm_*.s
// not called directly; definitions here supply type information for traceback.
func call16(fn, arg unsafe.Pointer, n, retoffset uint32)
func call32(fn, arg unsafe.Pointer, n, retoffset uint32)
func call64(fn, arg unsafe.Pointer, n, retoffset uint32)
func call128(fn, arg unsafe.Pointer, n, retoffset uint32)
Expand Down
14 changes: 14 additions & 0 deletions src/runtime/stubs32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2015 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.

// +build 386 arm amd64p32

package runtime

import "unsafe"

// Declarations for runtime services implemented in C or assembly that
// are only present on 32 bit systems.

func call16(fn, arg unsafe.Pointer, n, retoffset uint32)

0 comments on commit 1125cd4

Please sign in to comment.