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

cmd/go: linux/386 buildmode=c-shared with gccgo fails: undefined reference to '__stack_chk_fail_local' #13860

Closed
jtsylve opened this issue Jan 7, 2016 · 5 comments

Comments

@jtsylve
Copy link
Contributor

jtsylve commented Jan 7, 2016

What version of Go are you using (go version)?
go version go1.5.1 linux/386 as well as go version go1.6beta1 linux/386
gccgo (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010

What operating system and processor architecture are you using?
Linux ubuntu32 4.2.0-23-generic #28-Ubuntu SMP Sun Dec 27 17:48:35 UTC 2015 i686 i686 i686 GNU/Linux

What did you do?
I'm trying to compile using -buildmode=c-shared and -compiler=gccgo since gc doesn't support c-shared on linux/386 yet.

// test.go
package main

import "C"

//export test_export
func test_export() {}
func main()        {}

go build -compiler=gccgo -buildmode=c-shared -o test.so test.go

What did you expect to see?
A compiled, working shared library

What did you see instead?

# command-line-arguments
ar: `u' modifier ignored since `D' is the default (see `U')
# command-line-arguments
/tmp/go-build634452352/command-line-arguments/_obj/_cgo_defun.c:33: error: undefined reference to '__stack_chk_fail_local'
/tmp/go-build634452352/command-line-arguments/_obj/_cgo_defun.c:37: error: undefined reference to '__stack_chk_fail_local'
/tmp/go-build634452352/command-line-arguments/_obj/_cgo_defun.c:42: error: undefined reference to '__stack_chk_fail_local'
collect2: error: ld returned 1 exit status
@jtsylve
Copy link
Contributor Author

jtsylve commented Jan 7, 2016

I think this may be related to CL https://golang.org/cl/13615, which removed the symbols to partially fix #9327

@ianlancetaylor
Copy link
Contributor

CL 13615 did not affect gccgo, so that's not it.

Could you show the output of go build -compiler=gccgo -buildmode=c-shared -x -o test.so test.go? That is, add a -x option. Thanks.

@ianlancetaylor ianlancetaylor changed the title linux/386 buildmode=c-shared with gccgo fails: undefined reference to '__stack_chk_fail_local' cmd/go: linux/386 buildmode=c-shared with gccgo fails: undefined reference to '__stack_chk_fail_local' Jan 8, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.6Maybe milestone Jan 8, 2016
@ianlancetaylor ianlancetaylor self-assigned this Jan 8, 2016
@jtsylve
Copy link
Contributor Author

jtsylve commented Jan 8, 2016

mkdir -p $WORK/command-line-arguments/_obj/
mkdir -p $WORK/command-line-arguments/_obj/exe/
cd /home/joe/Desktop
CGO_LDFLAGS="-g" "-O2" /home/joe/Downloads/go/pkg/tool/linux_386/cgo -objdir $WORK/command-line-arguments/_obj/ -importpath command-line-arguments -gccgo -exportheader=$WORK/command-line-arguments/_obj/_cgo_install.h -- -I $WORK/command-line-arguments/_obj/ test.go
gcc -Wall -g -I $WORK/command-line-arguments/_obj/ -I /home/joe/Downloads/go/pkg/include -o $WORK/command-line-arguments/_obj/_cgo_defun.o -D GOOS_linux -D GOARCH_386 -m32 -fsplit-stack -fPIC -c $WORK/command-line-arguments/_obj/_cgo_defun.c
gcc -I . -fPIC -m32 -pthread -fmessage-length=0 -I $WORK/command-line-arguments/_obj/ -g -O2 -fsplit-stack -o $WORK/command-line-arguments/_obj/_cgo_main.o -c $WORK/command-line-arguments/_obj/_cgo_main.c
gcc -I . -fPIC -m32 -pthread -fmessage-length=0 -I $WORK/command-line-arguments/_obj/ -g -O2 -fsplit-stack -o $WORK/command-line-arguments/_obj/_cgo_export.o -c $WORK/command-line-arguments/_obj/_cgo_export.c
gcc -I . -fPIC -m32 -pthread -fmessage-length=0 -I $WORK/command-line-arguments/_obj/ -g -O2 -fsplit-stack -o $WORK/command-line-arguments/_obj/test.cgo2.o -c $WORK/command-line-arguments/_obj/test.cgo2.c
gcc -I . -fPIC -m32 -pthread -fmessage-length=0 -o $WORK/command-line-arguments/_obj/_cgo_.o $WORK/command-line-arguments/_obj/_cgo_main.o $WORK/command-line-arguments/_obj/_cgo_export.o $WORK/command-line-arguments/_obj/test.cgo2.o -g -O2
/usr/bin/gccgo -I $WORK -c -g -m32 -fgo-relative-import-path=_/home/joe/Desktop -o $WORK/command-line-arguments/_obj/_go_.o -fPIC $WORK/command-line-arguments/_obj/_cgo_gotypes.go $WORK/command-line-arguments/_obj/test.cgo1.go
ar rc $WORK/libcommand-line-arguments.a $WORK/command-line-arguments/_obj/_go_.o $WORK/command-line-arguments/_obj/_cgo_defun.o $WORK/command-line-arguments/_obj/_cgo_export.o $WORK/command-line-arguments/_obj/test.cgo2.o
cd .
/usr/bin/gccgo -o $WORK/command-line-arguments/_obj/exe/a.out $WORK/command-line-arguments/_obj/_go_.o $WORK/command-line-arguments/_obj/_cgo_defun.o $WORK/command-line-arguments/_obj/_cgo_export.o $WORK/command-line-arguments/_obj/test.cgo2.o -Wl,-( -m32 -Wl,--whole-archive -Wl,--no-whole-archive -Wl,-) -shared -nostdlib -Wl,--whole-archive -lgolibbegin -Wl,--no-whole-archive -lgo -lgcc_s -lgcc -fPIC
# command-line-arguments
/tmp/go-build459779134/command-line-arguments/_obj/_cgo_defun.c:33: error: undefined reference to '__stack_chk_fail_local'
/tmp/go-build459779134/command-line-arguments/_obj/_cgo_defun.c:37: error: undefined reference to '__stack_chk_fail_local'
/tmp/go-build459779134/command-line-arguments/_obj/_cgo_defun.c:42: error: undefined reference to '__stack_chk_fail_local'
/tmp/go-build459779134/command-line-arguments/_obj/_cgo_defun.c:72: error: undefined reference to '__stack_chk_fail_local'
collect2: error: ld returned 1 exit status```

@OneOfOne
Copy link
Contributor

This seems like a stack-protector issue from an old gcc, does passing -fno-stack-protector -D_FORTIFY_SOURCE=0 -lssp to gcc fix the issue?

@gopherbot
Copy link

CL https://golang.org/cl/18592 mentions this issue.

@golang golang locked and limited conversation to collaborators Jan 13, 2017
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