在調(diào)試Golang代碼時(shí),在${GOPATH}/src/runtime/proc.go
中看到
//go:linkname main_main main.main
func main_main()
于是乎自晰,//go:linkname
到底是什么?
這里確實(shí)沒(méi)有比較好的搜索入口,不知道大家是怎么檢索一些Golang Inside Feature的用法說(shuō)明?歡迎在評(píng)論區(qū)交流
通過(guò)查閱相關(guān)信息凝果,在標(biāo)準(zhǔn)庫(kù)的文檔說(shuō)明中找到
//go:linkname localname [importpath.name]
The //go:linkname directive conventionally precedes the var or func declaration named by “l(fā)ocalname“, though its position does not change its effect. This directive determines the object-file symbol used for a Go var or func declaration, allowing two Go symbols to alias the same object-file symbol, thereby enabling one package to access a symbol in another package even when this would violate the usual encapsulation of unexported declarations, or even type safety. For that reason, it is only enabled in files that have imported "unsafe".
但不推薦使用,這種行為是破壞Go Module的依賴關(guān)系睦尽,會(huì)使得包的獨(dú)立性喪失器净。
更多相關(guān)材料: