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

runtime/cgo: support Handle even when CGO_ENABLED=0 #64663

Open
eliasnaur opened this issue Dec 11, 2023 · 3 comments
Open

runtime/cgo: support Handle even when CGO_ENABLED=0 #64663

eliasnaur opened this issue Dec 11, 2023 · 3 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@eliasnaur
Copy link
Contributor

eliasnaur commented Dec 11, 2023

Go version

go1.21.0

What operating system and processor architecture are you using (go env)?

Windows

What did you do?

Run the program

package main

import "runtime/cgo"

func main() {
	println(cgo.NewHandle(new(int)))
}

on Windows (GOOS=windows).

What did you expect to see?

No error.

What did you see instead?

runtime.cgo_yield: relocation target _cgo_yield not defined
_cgo_init: relocation target x_cgo_init not defined
_cgo_thread_start: relocation target x_cgo_thread_start not defined
_cgo_pthread_key_created: relocation target x_cgo_pthread_key_created not defined
_crosscall2_ptr: relocation target x_crosscall2_ptr not defined
_cgo_bindm: relocation target x_cgo_bindm not defined
_cgo_notify_runtime_init_done: relocation target x_cgo_notify_runtime_init_done not defined
_cgo_getstackbound: relocation target x_cgo_getstackbound not defined

This issue may be fixed by forcing CGO_ENABLED=1 when using cgo.NewHandle, but I think that's the short-sighted fix. cgo.Handle is also useful for storing context when using the syscall facility for calling native code.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 11, 2023
@prattmic prattmic added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 12, 2023
@prattmic
Copy link
Member

cc @golang/runtime

@prattmic prattmic added this to the Backlog milestone Dec 12, 2023
@prattmic
Copy link
Member

I wonder if we should have an equivalent cgo.Handle in package syscall for use there? (Alas, the name syscall.Handle is already taken on Windows)

@cherrymui
Copy link
Member

Just importing the runtime/cgo package causes the same failure, without using Handle.

package main

import _ "runtime/cgo"

func main() {}

If we want to fix this, we need to guard things in runtime/cgo that interacts with C with cgo build tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

5 participants