how do you compie and link a go main with an assembly code file?

307 views
Skip to first unread message

Peter Riemenschneider

unread,
Oct 9, 2023, 12:02:27 PM10/9/23
to golang-nuts
I tried to recreate the simplest example:

testAdd.go:
package main

func main () {
_ = add(3,5)
}

addAsm.s:

TEXT    main.add(SB), NOSPLIT|NOFRAME|ABIInternal, $0-16

ADDQ    BX, AX

RET

I can compile the first program with: go tool compile testAdd.go
I can run the assembler: go tool asm addAsm.s

I have two object files testAdd.o and addASm.o 
but linking the two file with the run time fails: go tool link testAdd.o
rutime.a not found.

I looked all over the internet, but this time I cannot find a hint of how to combine an assmbly written file with a go program to generate an executable.  The examples are all old (prior to go 1.18 when stack function calls have been replaced by register calls)

any help is very much appreciated,
regards,
peter

Jan Mercl

unread,
Oct 9, 2023, 12:19:45 PM10/9/23
to Peter Riemenschneider, golang-nuts
On Mon, Oct 9, 2023 at 6:02 PM Peter Riemenschneider <pri...@gmail.com> wrote:

Just '$ go build' as usual, but one must declare the asm function:
https://go.dev/play/p/KySqFvCVz_T
Reply all
Reply to author
Forward
0 new messages