go build reports relocation target not defined for ABI0 (but is defined for ABIInternal)

975 views
Skip to first unread message

Zhang Chao

unread,
Sep 9, 2019, 11:09:53 AM9/9/19
to golang-nuts
Hello!

I'm trying to write a tiny go program with a SayHello function written by assembly.
When I build it, the go build command giving me an error message:

# bar
main.asmSayHello: relocation target runtime.printstring not defined for ABI0 (but is defined for ABIInternal)

Here are the codes.

main.go:

package main

func main() { asmSayHello() }

func asmSayHello()

and main_amd64.s:

#include "textflag.h"
#include "funcdata.h"

// "Hello, World\n"
DATA text<>+0(SB)/8,$"Hello Wo"
DATA text<>+8(SB)/8,$"rld!\n"
GLOBL text<>(SB),NOPTR,$16

// func asmSayHello()
TEXT ·asmSayHello(SB), $16-0
    NO_LOCAL_POINTERS
    MOVQ $text<>+0(SB), AX
    MOVQ AX, (SP)
    MOVQ $16, 8(SP)
    CALL runtime·printstring(SB)
    RET

The go facility version information:

# go version
go version go1.12.5 linux/amd64

Anyone who can help me to solve this weird problem (at least for me :) )?

Ian Lance Taylor

unread,
Sep 9, 2019, 10:55:00 PM9/9/19
to Zhang Chao, golang-nuts
You are trying to reach into the runtime package to run an internal
function. That isn't permitted. It's never been permitted, although
it used to work. Now it doesn't work.

For more information see
https://github.com/golang/proposal/blob/master/design/27539-internal-abi.md#compatibility
.

Ian

Zhang Chao

unread,
Sep 9, 2019, 10:56:58 PM9/9/19
to golang-nuts
Hello!

Thanks for your interpretation. So is there any workaround?

Ian Lance Taylor

unread,
Sep 10, 2019, 12:31:08 AM9/10/19
to Zhang Chao, golang-nuts
On Mon, Sep 9, 2019 at 7:57 PM Zhang Chao <zcha...@gmail.com> wrote:
>
> Thanks for your interpretation. So is there any workaround?

Don't try to call an internal runtime package function. Call a Go
function defined in your own package that calls the print builtin.

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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9d2517e2-0992-4631-a4dc-e854433423a4%40googlegroups.com.

Zhang Chao

unread,
Sep 16, 2019, 10:17:25 PM9/16/19
to golang-nuts
Hello!

OK, thank you. Actually I just do some exercises for learning Go assembly.
> To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages