-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ch3.1: Broken under Go 1.12 (relocation target runtime.printstring not defined for ABI0 (but is defined for ABIInternal)) #427
Comments
main.go package main
var helloworld = "你好, 世界"
func main() main.s:
|
这是第一节内容,目的是展示怎么自定义main函数。可以绕过变化到部分。 Go部分可以改成如下格式: package main
import "fmt"
var helloworld = "你好, 世界"
func println(s string) {
fmt.Println(s)
}
func main() 然后汇编部分: TEXT ·main(SB), $16-0
MOVQ ·helloworld+0(SB), AX; MOVQ AX, 0(SP)
MOVQ ·helloworld+8(SB), BX; MOVQ BX, 8(SP)
CALL ·println(SB)
RET 在汇编实现中,main函数调用自定义到println函数实现打印。 |
Go 部分 main.go package main
var helloWorld = "Hello, 世界"
func output(s string) {
println(s)
}
func main() 汇编部分 main_amd64.s TEXT ·main(SB), $16-0
MOVQ ·helloWorld+0(SB), AX
MOVQ AX, 0(SP)
MOVQ ·helloWorld+8(SB), BX
MOVQ BX, 8(SP)
CALL ·output(SB)
RET 也许更简单一点 ~ |
go1.14提示 missing function body 代码如下:main3.go import ( var helloWorld = "你好, 世界" 汇编文件 main3_amd64.s |
go run 执行会报错, build 后再运行就可以了。 |
参考 compatibility section 这样写: main.gopackage main
import _ "unsafe"
//go:linkname printnl runtime.printnl
func printnl()
//go:linkname printstring runtime.printstring
func printstring(s string)
var helloWorld = "你好,世界"
func main() main_amd64.sTEXT ·main(SB), $16-0
MOVQ ·helloWorld+0(SB), AX
MOVQ AX, 0(SP)
MOVQ ·helloWorld+8(SB), BX
MOVQ BX, 8(SP)
CALL runtime·printstring(SB)
CALL runtime·printnl(SB)
RET |
为什么直接CALL方法(
求解答 |
runtime的内部函数不给调用了,哪怕是汇编代码。 |
大大,这个事情我了解过。但是和上面的问题没有对应起来哦。 但是中转一下就可以了,不知道什么原理?下面的代码是OK的
|
rsc的反馈表达了官方对内部api的态度。外部包尽量避免,负责后面被禁止也是有可能的。 |
https://github.com/golang/proposal/blob/master/design/27539-internal-abi.md
The text was updated successfully, but these errors were encountered: