I edited my code to import test/pri in test/pub:

pri/a.go:

package pri 


import (
    "fmt"
)
const (
    Dummy = 1 
)
func rua() int64 {
    fmt.Println("rua in pri")
    return int64(1)
}

pub/b.go:

package pub 


import (
    "unsafe"
    pri "test/pri"
)


var _ = unsafe.Sizeof(0)
var _ = pri.Dummy


//go:noescape
//go:linkname rua pri.rua
func rua() int64


func Rua() int64 {
    return rua()
}

But this still don't work.  

# command-line-arguments
test/pub.Rua: pri.rua: not defined
test/pub.Rua: undefined: pri.rua

Besides, this package 
<https://github.com/aristanetworks/goarista/blob/46272bfb1c042fc2825d312fe33d494e9d13dd6b/atime/nanotime.go>
 doesn't 
import "runtime" at all, but it can use "runtime.nanotime" in go:linkname.


在 2017年1月20日星期五 UTC+8下午1:34:43,Ian Lance Taylor写道:
>
> On Wed, Jan 18, 2017 at 6:55 PM, Cholerae Hu <chole...@gmail.com 
> <javascript:>> wrote: 
> > I'm trying to play with go:linkname, and I wrote a demo for this. 
> > 
> > directory structure: 
> > 
> > [test]$ tree 
> > . 
> > ├── main.go 
> > ├── pri 
> > │   └── a.go 
> > └── pub 
> >     ├── issue15006.s 
> >     └── b.go 
> > 
> > a.go: 
> > 
> > package pri 
> > 
> > 
> > import ( 
> >     "fmt" 
> > ) 
> > func rua() int64 { 
> >     fmt.Println("rua in pri") 
> >     return 1 
> > } 
> > 
> > b.go: 
> > 
> > package pub 
> > 
> > 
> > import ( 
> >     "unsafe" 
> > ) 
> > 
> > 
> > var _ = unsafe.Sizeof(0) 
> > 
> > 
> > //go:noescape 
> > //go:linkname rua test/pri.rua 
> > func rua() int64 
> > 
> > 
> > func Rua() int64 { 
> >     return rua() 
> > } 
> > 
> > main.go: 
> > 
> > package main 
> > 
> > 
> > import ( 
> >     "test/pub" 
> > ) 
> > 
> > 
> > func main() { 
> >     println(pub.Rua()) 
> > } 
> > 
> > issue15006.s is a workaround for issue 15006 and it's totally empty. 
> > 
> > Than I ran `go run main.go` and got an error: 
> > 
> > # command-line-arguments 
> > test/pub.Rua: test/pri.rua: not defined 
> > test/pub.Rua: undefined: test/pri.rua 
> > 
> > So what's wrong with this demo? 
>
> Nothing in your program imports test/pri.  go:linkname only changes 
> the name used for a symbol.  It doesn't cause a package to be 
> imported. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to