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: static variables are not initialised correctly on darwin/amd64 #1559

Closed
rogpeppe opened this issue Feb 28, 2011 · 7 comments
Closed

cgo: static variables are not initialised correctly on darwin/amd64 #1559

rogpeppe opened this issue Feb 28, 2011 · 7 comments

Comments

@rogpeppe
Copy link
Contributor

Unarchive the attached archive and run "gotest".
On my machine this prints,

    0x100002a0001
    0xffffffff00000000
    0xffffffff00000000
    0xffffffff
    0x0
    0x10054ba78
    0x10054f370
    0x0
    0x1437e
    0x6a

where it should print all zeros.

6g macos d9ff478c4ed3+ tip

Attachments:

  1. tstcgo.tgz (580 bytes)
@rogpeppe
Copy link
Contributor Author

Comment 1:

The callback.* files are not required.
If the variables have an explicit initialiser, the problem does not occur.

@rogpeppe
Copy link
Contributor Author

Comment 2:

I tell a lie - in another example, adding an explicit initialiser did not remedy the
problem.

@peterGo
Copy link
Contributor

peterGo commented Feb 28, 2011

Comment 3:

For linux/386 (Ubuntu 10.04) at Go hg id 8d78d5e69093 tip,
/tstcgo$ gotest
rm -f _test/tst-go.nowhere.com/tst.a _gotest_.8
8g -o _gotest_.8  tst.cgo1.go _cgo_gotypes.go tst_test.go
8c -FVw -I/home/peter/go/pkg/linux_386 _cgo_defun.c
8c -FVw _cgo_import.c
rm -f _test/tst-go.nowhere.com/tst.a
gopack grc _test/tst-go.nowhere.com/tst.a _gotest_.8  _cgo_defun.8 _cgo_import.8
callback.o  tst.cgo2.o _cgo_export.o
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
PASS

@peterGo
Copy link
Contributor

peterGo commented Feb 28, 2011

Comment 4:

For linux/386 (Ubuntu 10.04) at Go hg id 8d78d5e69093 tip,
/tstcgo$ gotest
rm -f _test/tst-go.nowhere.com/tst.a _gotest_.8
8g -o _gotest_.8  tst.cgo1.go _cgo_gotypes.go tst_test.go
8c -FVw -I/home/peter/go/pkg/linux_386 _cgo_defun.c
8c -FVw _cgo_import.c
rm -f _test/tst-go.nowhere.com/tst.a
gopack grc _test/tst-go.nowhere.com/tst.a _gotest_.8  _cgo_defun.8 _cgo_import.8
callback.o  tst.cgo2.o _cgo_export.o
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
PASS

@peterGo
Copy link
Contributor

peterGo commented Feb 28, 2011

Comment 5:

For linux/amd64 (Ubuntu 10.04) at Go hg id b5479d8005d6 tip,
tstcgo$ gotest
rm -f _test/tst-go.nowhere.com/tst.a _gotest_.6
CGOPKGPATH=tst-go.nowhere.com cgo --  tst.go 
touch _cgo_run
6g -o _gotest_.6  tst.cgo1.go _cgo_gotypes.go tst_test.go
6c -FVw -I/home/peter/go/pkg/linux_amd64 _cgo_defun.c
gcc -m64 -g -fPIC -O2 -o _cgo_main.o -c   _cgo_main.c
gcc -m64 -g -fPIC -O2 -o callback.o -c   callback.c
gcc -m64 -g -fPIC -O2 -o tst.cgo2.o -c   tst.cgo2.c
gcc -m64 -g -fPIC -O2 -o _cgo_export.o -c   _cgo_export.c
gcc -m64 -g -fPIC -O2 -o _cgo1_.o _cgo_main.o callback.o tst.cgo2.o _cgo_export.o  
cgo -dynimport _cgo1_.o >__cgo_import.c && mv -f __cgo_import.c _cgo_import.c
6c -FVw _cgo_import.c
rm -f _test/tst-go.nowhere.com/tst.a
gopack grc _test/tst-go.nowhere.com/tst.a _gotest_.6  _cgo_defun.6 _cgo_import.6
callback.o  tst.cgo2.o _cgo_export.o
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
    (nil)
PASS

@rsc
Copy link
Contributor

rsc commented Feb 28, 2011

Comment 6:

Owner changed to r...@golang.org.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Apr 7, 2011

Comment 7:

This issue was closed by revision cf3323f.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
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