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

cgo call to glfw3 segfaults on darwin_amd64 #4868

Closed
gordonklaus opened this issue Feb 21, 2013 · 9 comments
Closed

cgo call to glfw3 segfaults on darwin_amd64 #4868

gordonklaus opened this issue Feb 21, 2013 · 9 comments
Milestone

Comments

@gordonklaus
Copy link
Contributor

Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:

Run "go version" and compare against
http://golang.org/doc/devel/release.html  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

Thanks.

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1.  Build and install glfw3.  (http://sourceforge.net/p/glfw/code/)
2.  Run this program:
package main

/*
#cgo         LDFLAGS: -lglfw3
#cgo  darwin  CFLAGS: -I/usr/local/include
#cgo  darwin LDFLAGS: -L/usr/local/lib -framework Cocoa -framework OpenGL -framework
IOKit
#include <GL/glfw3.h>
*/
import "C"
import (
    "runtime"
)

func main() {
    runtime.LockOSThread()
    C.glfwInit()
}

What is the expected output?
nothing

What do you see instead?
SIGSEGV: segmentation violation
PC=0x0
signal arrived during cgo execution

main._Cfunc_glfwInit(0x2070, 0xfddf)
    code.google.com/p/gordon-go/glfw/_obj/_cgo_defun.c:42 +0x2f
main.main()
    code.google.com/p/gordon-go/glfw/_obj/glfw.cgo1.go:17 +0x21
rax     0x20b4
rbx     0x330f80
rcx     0x330f80
rdx     0x330f18
rdi     0x330f80
rsi     0x4b188
rbp     0x7fff5fbff660
rsp     0x7fff5fbff648
r8      0x110071b8
r9      0xc20002b000
r10     0x179fd1ee8e0
r11     0x80522124
r12     0x4a256da918f4
r13     0x4a25367a9a90
r14     0x12e4dc48318fdc00
r15     0x0
rip     0x0
rflags  0x10206
cs      0x27
fs      0x0
gs      0x0


Which compiler are you using (5g, 6g, 8g, gccgo)?
go install on amd64, so 6g

Which operating system are you using?
Mac OS X 10.6

Which version are you using?  (run 'go version')
go version devel +c6c6c4b3061f Wed Feb 20 13:38:19 2013 -0800 darwin/amd64

Please provide any additional information below.
glfw 2.7 works fine, but not 3.0.

If I change glfwInit() to glfwSetErrorCallback(nil) I get a similar result:
SIGSEGV: segmentation violation
PC=0x0
signal arrived during cgo execution

main._Cfunc_glfwSetErrorCallback(0x0, 0xfddf)
    code.google.com/p/gordon-go/glfw/_obj/_cgo_defun.c:42 +0x2f
main.main()
    code.google.com/p/gordon-go/glfw/_obj/glfw.cgo1.go:17 +0x29
rax     0x20b4
rbx     0x330f80
rcx     0x330f80
rdx     0x330f18
rdi     0x0
rsi     0x4b188
rbp     0x4f620
rsp     0x7fff5fbff668
r8      0x110071b8
r9      0xc20002b000
r10     0x1b68921e104
r11     0x80522124
r12     0x4aa2a8bb2df9
r13     0x4aa279bdb850
r14     0x12e4dcc574dc6000
r15     0x0
rip     0x0
rflags  0x10202
cs      0x27
fs      0x0
gs      0x0

so it's not something specific to glfwInit()
@alberts
Copy link
Contributor

alberts commented Feb 21, 2013

Comment 1:

Smells like this:
https://groups.google.com/d/topic/golang-dev/NKt0XfyFd7E/discussion

@alberts
Copy link
Contributor

alberts commented Feb 21, 2013

Comment 2:

you might want to try again with tip with this change or later:
http://code.google.com/p/go/source/detail?r=43cc2ef77ca6da9cec755588e2c6653a1c96e5dd

@gordonklaus
Copy link
Contributor Author

Comment 3:

same thing with tip:  go version devel +fbb1de9bc379 Thu Feb 21 15:55:40
2013 -0800 darwin/amd64
I don't know if it's useful to you, but I include the output just in case:
SIGSEGV: segmentation violation
PC=0x0
signal arrived during cgo execution
main._Cfunc_glfwSetErrorCallback(0x0)
code.google.com/p/gordon-go/glfw/_obj/_cgo_defun.c:42 +0x2f
main.main()
code.google.com/p/gordon-go/glfw/_obj/glfw.cgo1.go:17 +0x29
goroutine 0 [syscall]:
rax     0x20b4
rbx     0x330f80
rcx     0x330f80
rdx     0x330f18
rdi     0x0
rsi     0x501c8
rbp     0x54660
rsp     0x7fff5fbff668
r8      0x110071b8
r9      0xc200032000
r10     0xfa8d627d94
r11     0x80522124
r12     0x55a23ca63110
r13     0x55a22027f728
r14     0x12e50020bf6d2e00
r15     0x0
rip     0x0
rflags  0x10202
cs      0x27
fs      0x0
gs      0x0
Please let me know if there is anything I can do to help, provide more
information, etc.

@gordonklaus
Copy link
Contributor Author

Comment 4:

FWIW, this code doesn't even build on 1.0.3.  I get this error:
glfw.a(glfw.cgo2.o)(__TEXT/__text): glfwSetErrorCallback: not defined

@gordonklaus
Copy link
Contributor Author

Comment 5:

Sorry for the noise.  It turns out my problem was that I had only a
statically linked libglfw.  I didn't know that cgo can't handle static libs
lacking -fPIC, etc.  (And it took me quite a while to figure it out,
especially with "Go links statically" branded into my brain.)
Maybe this should be documented at http://golang.org/cmd/cgo/ ?  Perhaps
CGO could fail descriptively?  Actually, I think it does fail in an earlier
version, but only with "undefined symbol" or something.
So my trouble is past, but I guess you've still got trouble in that I was
able to (successfully?) link against libglfw.a but failed to call into it.

@rsc
Copy link
Contributor

rsc commented Feb 25, 2013

Comment 6:

Thanks for letting us know. If all goes as planned, cgo will work with static libraries
for Go 1.1, and we won't need to add any notes to the docs. :-)

Status changed to Retracted.

@gopherbot
Copy link

Comment 7 by charliehorse55@overclocked.net:

This issue is still present in go 1.1.1, and should be reopened.

@gopherbot
Copy link

Comment 8 by ryan.rohrer:

I can verify this is still an issue in 1.1.1, and I too would like to see it reopened.

@gopherbot
Copy link

Comment 9 by loic.nageleisen:

The bug has been replicated here:
go-gl/glfw#41 (comment)
It affects the official Go pkg installer, but homebrew's built from source version works
just fine.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants