https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65134
--- Comment #5 from boger at us dot ibm.com --- (In reply to Tatsushi Inagaki from comment #0) > Created attachment 34813 [details] > Example to reproduce the constructor problem > > Gccgo ignores a C-function with the "constructor" attribute in a > subdirectory. In the attached example, gc executes a C-function init() in > sub.go before a Go function main(), but gccgo does not: > > ~/example$ export GOPATH=$(pwd) > ~/example$ /usr/local/go/bin/go version > go version go1.4.2 linux/amd64 > ~/example$ /usr/local/go/bin/go run src/main/main.go > Hello from constructor > Hello from main > > ~/example$ export LD_LIBRARY_PATH=/usr/local/gccgo/lib64:$LD_LIBRARY_PATH > ~/example$ /usr/local/gccgo/bin/go version > go version gccgo (GCC) 5.0.0 20150115 (experimental) linux/amd64 > ~/example$ /usr/local/gccgo/bin/go run src/main/main.go > Hello from main > > ~/example$ > > It seems this difference is due to that gccgo cannot detect a function with > the constructor attribute in an archived objects created in a subdirectory. > Is there any workaround to avoid this problem? Just to clarify this -- are you saying the problem that the gccgo linker is smart enough to determine that the function is not being used so it is discarded, but with gc it is not? So this is a difference in behavior but not actually a bug?