Skip to content
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

//go:linkname doesn't work for already defined functions #4185

Closed
akvlad opened this issue Mar 11, 2024 · 4 comments
Closed

//go:linkname doesn't work for already defined functions #4185

akvlad opened this issue Mar 11, 2024 · 4 comments

Comments

@akvlad
Copy link

akvlad commented Mar 11, 2024

Hello everyone.

I have a small test code

package main

import (
	"sync"
	_ "unsafe"
)

//go:linkname get sync.(*Pool).Get
func get(p *sync.Pool) any {
	panic("GET POOL")
}

func main() {
	print("1\n")
	p := sync.Pool{}
	a := p.Get()
	_ = a
}

go run main.go works as expected: it panics

~/tinygo/tinygo-v0.31.2/bin/tinygo build -target wasm -o test.wasm test.go
node wasm_exec.js test.wasm
this doesn't panic.

Is there a way to make this linkname directive working?

@akvlad akvlad changed the title //go:linkname doesn't work for already defuned functions //go:linkname doesn't work for already defined functions Mar 11, 2024
@aykevl
Copy link
Member

aykevl commented Mar 12, 2024

I'm surprised this works in the Go toolchain. Generally it's not possible to replace a function defined in another package, at least not in TinyGo. Why are you doing this?

@akvlad
Copy link
Author

akvlad commented Mar 12, 2024

I'm experimenting with some tiny-go GC approaches. Apparently it touches another internal aspects and I prefer not to fork the entire project, but make an extension to it.

@aykevl
Copy link
Member

aykevl commented Mar 12, 2024

If you want to modify this, you really should modify TinyGo directly. Any other approach will likely lead to issues because TinyGo wasn't designed to be extended like this.

@akvlad
Copy link
Author

akvlad commented Mar 12, 2024

Ok. Thanks for the information.
Feel free to close the issue then.

@aykevl aykevl closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants