SmartOS (solaris) fails to build the backend

I am with gcc49, go-1.8.3.

With v4.4.1 or master branch, when go run build.go setup, it fails AS IF:

[root@a21b8418-2528-c8d0-8c8a-a72fee9e6054 ~/golang/src/]# go install -v -x -work ./pkg/cmd/grafana-server/
mkdir -p $WORK/
mkdir -p $WORK/
cd /root/golang/src/
/opt/local/go/pkg/tool/solaris_amd64/compile -o $WORK/ -trimpath $WORK -p main -complete -buildid d5e028340af1bba6ca4ec55952a8ec12e37b0219 -importmap -D _/root/golang/src/ -I $WORK -I /root/golang/pkg/solaris_amd64 -pack ./main.go ./server.go
cd .
/opt/local/go/pkg/tool/solaris_amd64/link -o $WORK/ -L $WORK -L /root/golang/pkg/solaris_amd64 -extld=gcc -buildmode=exe -buildid=d5e028340af1bba6ca4ec55952a8ec12e37b0219 $WORK/
/opt/local/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
Undefined                       first referenced
 symbol                             in file
__stack_chk_fail                    /tmp/go-link-322194758/000002.o
__stack_chk_guard                   /tmp/go-link-322194758/000002.o
ld: fatal: symbol referencing errors. No output written to $WORK/
collect2: error: ld returned 1 exit status

Grafana has a C dependency due to including sqlite and that would seem to be the problem here. Looks like something in the toolchain is not right.

Does it work if you skip go run build.go setup and just run this instead: go run build.go build

I know nothing about Solaris/SmartOS but maybe setting the go flag -cgo-enabled=0 might work?

Cross-compiling from a Linux machine might be an option too.

thanks for your reply.

I have tried both:

go run build.go build
no dice, the same result.

go run -cgo-enabled=0 build.go build:
flag provided but not defined: -cgo-enabled

I dont know golang, please correct me if the flag is not correctly added.

I just ran into this problem too, the fix seems easy. The linker needs to have the -fstack-protector flag passed.

diff --git a/build.go b/build.go
index 1c61c72d5..3bba16775 100644
--- a/build.go
+++ b/build.go
@@ -413,6 +413,7 @@ func build(binaryName, pkg string, tags []string) {
 func ldflags() string {
        var b bytes.Buffer
+       b.WriteString(" -extldflags '-fstack-protector'")
        b.WriteString(fmt.Sprintf(" -X main.version=%s", version))
        b.WriteString(fmt.Sprintf(" -X main.commit=%s", getGitSha()))
        b.WriteString(fmt.Sprintf(" -X main.buildstamp=%d", buildStamp()))
1 Like