-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
gollvm: can't find some C std pthread_xxx functions #45424
Comments
Is there a reason why you don't add "-lpthread" to your cgo linker flags? e.g. #cgo LDFLAGS: -L./ -lpthread That is the normal thing to do when linking C code that uses functions from the pthread library. |
The main reason I dropped -lpthread" here is that the code in issue can be compiled successfully by original Go compiler. In fact, I have tried to add "-lpthread" to #cgo,and add it to args when compiling middle files with llvm-goc manually
It seems more difficult... |
Ok, this part looks actionable. I'll send a CL, thanks. For the pthread issue, I think this is arising due to differences in the cgo implementations for the main go compiler and gccgo/gollvm. In particular it looks as though we get "-lpthread" vua https://go.googlesource.com/go/+/1c9e587b90172e7654db897d8c938ffc665e1673/src/runtime/cgo/cgo.go#19 which is not part of the gofrontend version of cgo. I'll ask around about this. |
Change https://golang.org/cl/308450 mentions this issue: |
The gccgo driver program automatically adds |
Appreciate your help. The latest version works well with such scenario. |
From what I am seeing gccgo shows the same behavior:
It's true that libgo.so depends on libpthread, but this doesn't help resolve the reference to pthread_join at link time. |
Ah, interesting. Thanks. So perhaps the question is whether we should always link against |
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I wrote a cgo demo which call pthread std functions and tried to compile it with gollvm
Here is a link on play.golang- https://play.golang.org/p/PiaY0AIGprl
Though the code can't run on play.golang for some reason...
What did you expect to see?
Compile succeed with gollvm
What did you see instead?
An error caused by an undefined reference occured
In addition to this function, there are some other functions that also have this error:
pthread_once
,pthread_mutexattr_init
,pthread_mutexattr_settype
,pthread_key_create
,pthread_getspecific
,pthread_mutexattr_destroy
...Some extra observations
These functions above seems different between
pthread_create
which can be referenced normallyThe text was updated successfully, but these errors were encountered: