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

x/sys/unix: does not support building on Solaris with gccgo #49161

Open
bearx3f opened this issue Oct 26, 2021 · 8 comments
Open

x/sys/unix: does not support building on Solaris with gccgo #49161

bearx3f opened this issue Oct 26, 2021 · 8 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bearx3f
Copy link

bearx3f commented Oct 26, 2021

What version of Go are you using (go version)?

$ 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

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)?

go env Output
$ 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"

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
$ go build -compiler gccgo -trimpath -gccgoflags="-O3 -Wall -s -static-libgo -Wl,-dy -lnsl -lsocket -lrt" test-xcc/cmd/test3
package main

import "github.com/gin-gonic/gin"

func main() {
	r := gin.Default()
	r.Run(":80")
}

What did you expect to see?

successfully compile without any warning or errors

What did you see instead?

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);
      |               ^~~~~~~

and when run

$ GIN_MODE=release ./test3
SIGSYS: bad system call
PC=0x1001f12f4 m=0 sigcode=32767

goroutine 1 [syscall]:
__sighndlr
        :0
_syscall
        :0

and sometime i got this

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
@gopherbot gopherbot added this to the Gccgo milestone Oct 26, 2021
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 26, 2021
@ianlancetaylor
Copy link
Contributor

This doesn't seem to be a bug in gccgo itself.

The build of golang.org/x/sys/unix is getting the warning because the C file isn't including the right header file; I guess it should be including <sys/syscall.h>. The warning by itself shouldn't be a problem, though. The program then appears to crash when it calls unix.Syscall, crashing because it is trying to make a bad system call. But I don't know why the program is calling unix.Syscall; do you? Try running it under the debugger; you may get a better stack trace.

@ianlancetaylor ianlancetaylor changed the title gccgo: cross compiling with GCC11.2 build unusable binary x/sys/unix: cross build to Solaris with GCC11.2 builds unusable binary Oct 26, 2021
@ianlancetaylor ianlancetaylor modified the milestones: Gccgo, Unreleased Oct 26, 2021
@bearx3f
Copy link
Author

bearx3f commented Oct 27, 2021

Thank you for your response

look like github.com/mattn/go-isatty is the one who call unix.Syscall

Reading symbols from ./bin/test3...
(gdb) r
Starting program: /export/home/oracle/test/bin/test3
[Thread debugging using libthread_db enabled]
[New Thread 1 (LWP 1)]
[New LWP    2        ]
[New LWP    3        ]
[New LWP    4        ]
[New LWP    5        ]
GOOS solaris
GOARCH sparc64
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[New Thread 2 (LWP 2)]
[New Thread 3        ]
[New Thread 4        ]
[New Thread 5 (LWP 5)]

Thread 2 received signal SIGSYS, Bad system call.
[Switching to Thread 1 (LWP 1)]
0xffffffff58de2d54 in syscall () from /lib/64/libc.so.1
(gdb) bt
#0  0xffffffff58de2d54 in syscall () from /lib/64/libc.so.1
#1  0x00000001001f1b04 in golang_0org_1x_1sys_1unix.realSyscall (trap=16, a1=1, a2=21505, a3=824638662240, a4=0, a5=0, a6=0, a7=0, a8=0, a9=0)
    at ./vendor/golang.org/x/sys/unix/gccgo_c.c:34
#2  0x00000001001bc0a4 in golang_0org_1x_1sys_1unix.Syscall (trap=16, a1=1, a2=21505, a3=824638662240) at fdset.go:28
#3  0x00000001001d5ce8 in golang_0org_1x_1sys_1unix.ioctl (fd=1, req=21505, arg=824638662240) at zptrace_x86_linux.go:42
#4  0x00000001001bd544 in golang_0org_1x_1sys_1unix.IoctlGetTermios (fd=1, req=21505) at ifreq_linux.go:73
#5  0x00000001000425fc in github_0com_1mattn_1go_x2disatty.IsTerminal (fd=1) at ./vendor/github.com/mattn/go-isatty/doc.go:11
#6  0x000000010001a3f8 in github_0com_1gin_x2dgonic_1gin.LoggerWithConfig (conf=...) at gin.go:220
#7  0x0000000100019ef0 in github_0com_1gin_x2dgonic_1gin.Logger () at gin.go:184
#8  0x0000000100013800 in github_0com_1gin_x2dgonic_1gin.Default () at fs.go:183
#9  0x0000000100004368 in main.main () at ./cmd/test3/main.go:13

@ianlancetaylor
Copy link
Contributor

Something is wrong. A build for Solaris should not be running any code in zptrace_x86_linux.go.

When you run your go build command, try setting GOOS=solaris in the environment. That will tell the go command that you are building a cross-compiler.

@bearx3f
Copy link
Author

bearx3f commented Oct 28, 2021

I got this after when compiled with GOOS=solaris

I think GOARCH and target of gccgo (sparcv9-sun-solaris2.11) are conflicts

$ go build -compiler gccgo -o bin/$APP -trimpath -gccgoflags="-g1 -O0 -Wall -static-libgo" test-xcc/cmd/$APP
# golang.org/x/sys/unix
vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go:171:3: error: procAccess is not a function; '//go:linkname' is only supported for functions
  171 | //go:linkname procAccess libc_access
      |   ^
vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go:172:3: error: procAdjtime is not a function; '//go:linkname' is only supported for functions
  172 | //go:linkname procAdjtime libc_adjtime
      |   ^
vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go:173:3: error: procChdir is not a function; '//go:linkname' is only supported for functions
  173 | //go:linkname procChdir libc_chdir
      |   ^
----- snipped (many more) -----

go env after GOOS=solaris

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="solaris"
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.17.2"
GCCGO="/usr/local/bin/gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/builds/booboo/sparcv9-sun-solaris2.11-xcc-toolchain-test/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3649007841=/tmp/go-build -gno-record-gcc-switches"

@bearx3f bearx3f changed the title x/sys/unix: cross build to Solaris with GCC11.2 builds unusable binary x/sys/unix: cross build to Solaris on Sparc64 with GCC11.2 builds unusable binary Oct 28, 2021
@ianlancetaylor
Copy link
Contributor

Setting GOOS to match the gccgo target is required.

What you've discovered is that golang.org/x/sys/unix does not support Solaris when using gccgo. That is a bug that needs to be addressed in golang.org/x/sys/unix.

@ianlancetaylor ianlancetaylor changed the title x/sys/unix: cross build to Solaris on Sparc64 with GCC11.2 builds unusable binary x/sys/unix: does not support building on Solaris with gccgo Oct 29, 2021
@bearx3f
Copy link
Author

bearx3f commented Oct 30, 2021

I looking forward to this bug to be fix

Thanks

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
@sfzfs
Copy link

sfzfs commented Aug 20, 2022

hi, I experienced the same problem when I tried to use golang.org/x/sys under Solaris; is there any update on this bug? Thanks.

=======
package main
import (
"fmt"
"golang.org/x/sys/unix"
)
func main(){
name := "./test.log"
fd, err := unix.Open(name, unix.O_CREAT|unix.O_RDWR|unix.O_CLOEXEC, 0)
if err != nil {
fmt.Println("Open failed: %v", err)
}
defer unix.Close(fd)
flock := unix.Flock_t{
Type: unix.F_RDLCK,
Start: 0, Len: 0, Whence: 1,
}
if err := unix.FcntlFlock(uintptr(fd), unix.F_GETLK, &flock); err != nil {
fmt.Println("FcntlFlock failed: %v", err)
}
}

==========
$go build syscall.go

golang.org/x/sys/unix

../../go/pkg/mod/golang.org/x/sys@v0.0.0-20201029020603-3518587229cd/unix/zsyscall_solaris_amd64.go:162:3: error: procAccess is not a function; ‘//go:linkname’ is only supported for functions
162 | //go:linkname procAccess libc_access
| ^
../../go/pkg/mod/golang.org/x/sys@v0.0.0-20201029020603-3518587229cd/unix/zsyscall_solaris_amd64.go:163:3: error: procAdjtime is not a function; ‘//go:linkname’ is only supported for functions
163 | //go:linkname procAdjtime libc_adjtime
| ^
.....

$uname -m -o -p -i
i86pc i386 i86pc Solaris

$gccgo --version
gccgo (GCC) 11.3.0

$go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/builds/shifezha/.cache/go-build"
GOENV="/home/shifezha/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="solaris"
GOINSECURE=""
GOMODCACHE="/builds/shifezha/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="solaris"
GOPATH="/builds/shifezha/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/gcc/11"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/gcc/11/lib/gcc/x86_64-pc-solaris2.11/11.3.0"
GOVCS=""
GOVERSION="go1.16.5 gccgo (GCC) 11.3.0"
GCCGO="/usr/gcc/11/bin/gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/builds/shifezha/test/unixsyscall/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-build1559705635=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

@bearx3f
Copy link
Author

bearx3f commented Apr 27, 2023

@ianlancetaylor
I really want this gonna work
Are there any potential workarounds or solutions available to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

5 participants