Repository: go
Issue: x/sys/unix: does not support building on Solaris with gccgo
Labels: NeedsInvestigation,compiler/runtime

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/sparcv9-sun-solaris2.11/11.2.0/lto-wrapper
Target: sparcv9-sun-solaris2.11
Configured with: /usr/src/gcc/configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=sparcv9-sun-solaris2.11 --with-sysroot=/sysroot/sparcv9-sun-solaris2.11 --with-gnu-as --with-gnu-ld --with-static-standard-libraries --disable-documentation --disable-libgcj --disable-multilib --disable-shared --enable-stage1-languages=c --enable-languages=c,c++,go -v
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC) 

$ gccgo -v
Using built-in specs.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/sparcv9-sun-solaris2.11/11.2.0/lto-wrapper
Target: sparcv9-sun-solaris2.11
Configured with: /usr/src/gcc/configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=sparcv9-sun-solaris2.11 --with-sysroot=/sysroot/sparcv9-sun-solaris2.11 --with-gnu-as --with-gnu-ld --with-static-standard-libraries --disable-documentation --disable-libgcj --disable-multilib --disable-shared --enable-stage1-languages=c --enable-languages=c,c++,go -v
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC) 

$ go version
go version go1.16.3 linux/amd64
</pre>

### Does this issue reproduce with the latest release?
yes

latest gccgo is 11.2.0


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="/usr/local/bin/gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/builds/app/gravitron2/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4161522405=/tmp/go-build -gno-record-gcc-switches"
</pre></details>

### What did you do?
using github.com/gin-gonic/gin
and cross compile with gccgo 11.2.0 
- host amd64
- target sparcv9-sun-solaris2.11

<pre>
$ go build -compiler gccgo -trimpath -gccgoflags="-O3 -Wall -s -static-libgo -Wl,-dy -lnsl -lsocket -lrt" test-xcc/cmd/test3
</pre>

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->

<pre>
package main

import "github.com/gin-gonic/gin"

func main() {
	r := gin.Default()
	r.Run(":80")
}
</pre>



### What did you expect to see?
successfully compile without any warning or errors


### What did you see instead?
<pre>
go: downloading github.com/gin-gonic/gin v1.7.4
go: downloading github.com/gin-contrib/sse v0.1.0
go: downloading github.com/mattn/go-isatty v0.0.14
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/ugorji/go v1.2.6
go: downloading github.com/go-playground/validator/v10 v10.9.0
go: downloading github.com/golang/protobuf v1.5.2
go: downloading golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359
go: downloading github.com/ugorji/go/codec v1.2.6
go: downloading github.com/leodido/go-urn v1.2.1
go: downloading github.com/go-playground/universal-translator v0.18.0
go: downloading golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
go: downloading golang.org/x/text v0.3.7
go: downloading google.golang.org/protobuf v1.27.1
go: downloading github.com/go-playground/locales v0.14.0
# golang.org/x/sys/unix
/go/pkg/mod/golang.org/x/sys@v0.0.0-20211025201205-69cdffdb9359/unix/gccgo_c.c: In function 'gccgoRealSyscall':
/go/pkg/mod/golang.org/x/sys@v0.0.0-20211025201205-69cdffdb9359/unix/gccgo_c.c:33:15: warning: implicit declaration of function 'syscall' [-Wimplicit-function-declaration]
   33 |         r.r = syscall(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9);
      |               ^~~~~~~
</pre>

and when run 

<pre>
$ GIN_MODE=release ./test3
SIGSYS: bad system call
PC=0x1001f12f4 m=0 sigcode=32767

goroutine 1 [syscall]:
__sighndlr
        :0
_syscall
        :0
</pre>

and sometime i got this

<pre>
SIGSYS: bad system call
PC=0x0 m=0 sigcode=32767

goroutine 1 [syscall]:
syscall
        :0
golang_0org_1x_1sys_1unix.realSyscall
        /go/pkg/mod/golang.org/x/sys@v0.0.0-20211025201205-69cdffdb9359/unix/gccgo_c.c:33
</pre>