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: global variables cause segfault #5099

Closed
alberts opened this issue Mar 21, 2013 · 12 comments
Closed

cgo: global variables cause segfault #5099

alberts opened this issue Mar 21, 2013 · 12 comments

Comments

@alberts
Copy link
Contributor

alberts commented Mar 21, 2013

What steps will reproduce the problem?

foo.go:

package foo

//#cgo linux LDFLAGS: -lfoo
//typedef int Word32;
//extern const Word32 CODECLIB_MAJOR_VERSION_NUMBER;
//extern const Word32 CODECLIB_MINOR_VERSION_NUMBER;
//extern const Word32 CODECLIB_BUILD_VERSION_NUMBER;
import "C"

var (
        MajorVersion = C.CODECLIB_MAJOR_VERSION_NUMBER
        MinorVersion = C.CODECLIB_MINOR_VERSION_NUMBER
        BuildVersion = C.CODECLIB_BUILD_VERSION_NUMBER
)

foo_test.go:

package foo
import "testing"
func TestEverything(t *testing.T) {
    println(MajorVersion)
}

What is the expected output?

13

What do you see instead?

segfault

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

linux

Which version are you using?  (run 'go version')

tip

Please provide any additional information below.

Fedora 16 x86-64

gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)

GNU ld version 2.21.53.0.1-6.fc16 20110716

foo is a third party library that I can't attach here. Could probably send it to someone
if they need it to debug this.

hg bisect says:

The first bad revision is:
changeset:   15835:97cbf15abc2c
user:        Russ Cox <rsc@golang.org>
date:        Tue Mar 19 15:45:42 2013 -0400
summary:     cmd/ld: replace -hostobj with -linkmode

revision 97cbf15abc2c
@alberts
Copy link
Contributor Author

alberts commented Mar 21, 2013

Comment 1:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x430518]
goroutine 1 [running]:
foo.init()
    foo/_test/foo.cgo1.go:9 +0x48
main.init()
    foo/_test/_testmain.go:18 +0x3b

@alberts
Copy link
Contributor Author

alberts commented Mar 21, 2013

Comment 2:

latest tip I tested with was revision 2cc9547000b0. still has the issue.

@minux
Copy link
Member

minux commented Mar 21, 2013

Comment 3:

what if you write a simple shared object that only contains those three global variables?
if we fix this issue, we will need a small test case for misc/cgo/test.

@alberts
Copy link
Contributor Author

alberts commented Mar 21, 2013

Comment 4:

will see if I can cook something up quickly

@alberts
Copy link
Contributor Author

alberts commented Mar 21, 2013

Comment 5:

attached a tarball. seems pretty simple.

Attachments:

  1. foo.tar.gz (2502 bytes)

@alberts
Copy link
Contributor Author

alberts commented Mar 25, 2013

Comment 6:

linkmode=external|auto works. linkmode=internal doesn't.
revision 97cbf15abc2c makes some mention of something being disabled.
However, as far as I understand, this sample should work even with linkmode=internal?

@rsc
Copy link
Contributor

rsc commented Mar 25, 2013

Comment 7:

If it works in external mode, then I'm not too worried. Internal mode only needs to
handle the things in the standard library (net, os/user, crypto/x509). Everything else
is unsupported in that mode.

@alberts
Copy link
Contributor Author

alberts commented Mar 26, 2013

Comment 8:

It doesn't switch to external mode automatically though. Is that still coming? Thanks.

@eliasnaur
Copy link
Contributor

Comment 9:

TLS support was added, so afaik external mode should be enabled by default now.

@remyoudompheng
Copy link
Contributor

Comment 10:

fullung: please check that this is fixed by revision b27b1ff18f39.

@alberts
Copy link
Contributor Author

alberts commented Apr 22, 2013

Comment 11:

looks fixed

@ianlancetaylor
Copy link
Contributor

Comment 12:

Status changed to Fixed.

@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

7 participants