1
0
mirror of https://github.com/golang/go synced 2024-10-04 20:21:22 -06:00
go/misc/cgo
Russ Cox e5c105033a cmd/gc: disable link-time copying of un-Go-initialized globals
If you write:

        var x = 3

then the compiler arranges for x to be initialized in the linker
with an actual 3 from the data segment, rather than putting
x in the bss and emitting init-time "x = 3" assignment code.

If you write:

        var y = x
        var x = 3

then the compiler is clever and treats this the same as if
the code said 'y = 3': they both end up in the data segment
with no init-time assignments.

If you write

        var y = x
        var x int

then the compiler was treating this the same as if the
code said 'x = 0', making both x and y zero and avoiding
any init-time assignment.

This copying optimization to avoid init-time assignment of y
is incorrect if 'var x int' doesn't mean 'x = 0' but instead means
'x is initialized in C or assembly code'. The program ends up
with 'y = 0' instead of 'y = the value specified for x in that other code'.

Disable the propagation if there is no initializer for x.

This comes up in some uses of cgo, because cgo generates
Go globals that are initialized in accompanying C files.

Fixes #7665.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/93200044
2014-05-09 16:03:44 -04:00
..
errors cmd/cgo: enforce typing of 0-sized types 2014-03-27 20:23:16 +00:00
gmp misc/cgo/gmp: fix typo. 2013-03-30 19:02:14 +08:00
life misc/cgo: prepare for 64-bit ints 2012-09-24 14:58:45 -04:00
stdio misc/cgo/stdio: make it work on Windows and also test it 2012-09-20 00:27:23 +08:00
test cmd/gc: disable link-time copying of un-Go-initialized globals 2014-05-09 16:03:44 -04:00
testasan runtime: more flexible heap memory mapping on 64-bits 2013-06-12 18:47:16 +04:00
testcdefs misc/cgo/testcdefs: rm correct file in test.bash 2013-12-10 12:06:24 +11:00
testso misc/cgo/testso: don't use TLS variables on Darwin and OpenBSD. 2014-02-23 20:37:43 -05:00
testtls misc/cgo/testtls: make test less flaky 2014-01-21 19:44:51 -05:00