tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

export and extern not working

Open jclab-joseph opened this issue 2 years ago • 9 comments

package main

import (
	"fmt"
)

func main() {
	fmt.Println("ptr: ", ptr)
}


//export test
func test(a int) {
	fmt.Println("tets ", a)
}


//go:extern test
var ptr uintptr

Result:

function declaration may only have a unique !dbg attachment
ptr @test.4
error: verification error after compiling package command-line-arguments

I want to get a pointer to an exported function without the syscall package.

I am implementing scheduler.threads for contribute. There is a need for a way to obtain a function pointer without circular references due to syscall in internal/task.

jclab-joseph avatar Dec 14 '23 12:12 jclab-joseph

What version of tinygo are you using and how are you compiling this?

fgsch avatar Dec 14 '23 13:12 fgsch

@fgsch tinygo version 0.31.0-dev linux/amd64 (using go version go1.21.3 and LLVM version 15.0.7)

jclab-joseph avatar Dec 14 '23 14:12 jclab-joseph

Right, but what command line are you using to compile this?

fgsch avatar Dec 14 '23 22:12 fgsch

No other options. tinygo run main.go. The same goes in play.tinygo.org.

jclab-joseph avatar Dec 14 '23 23:12 jclab-joseph

Works here with:

tinygo version 0.30.0 darwin/amd64 (using go version go1.21.5 and LLVM version 16.0.1)

under macos Sonoma.

Can you repro with 0.30.0?

fgsch avatar Dec 17 '23 23:12 fgsch

There was a typo error in the code. Could you please try again?

Same error in tinygo version 0.30.0 linux/amd64 (using go version go1.21.3 and LLVM version 16.0.1).

$ tinygo version
tinygo version 0.30.0 linux/amd64 (using go version go1.21.3 and LLVM version 16.0.1)
$ tinygo run main.go
function declaration may only have a unique !dbg attachment
ptr @test.2
error: verification error after compiling package command-line-arguments

jclab-joseph avatar Dec 18 '23 00:12 jclab-joseph

Ah, yes. I can reproduce it 👍

fgsch avatar Dec 18 '23 15:12 fgsch

I'm a bit confused though, you are exporting different symbols with the same name. This is not going to work.

fgsch avatar Dec 18 '23 15:12 fgsch

When I saw that a C function was imported with go:extern, I thought it would be possible since it has the same role.

Any ideas on how to get an exported function pointer without a syscall import dependency?

https://github.com/tinygo-org/tinygo/pull/4047 Currently I need to use asm because this problem.

jclab-joseph avatar Dec 18 '23 22:12 jclab-joseph