Open conradoplg opened 6 years ago
/cc @ianlancetaylor @hirochachacha
Maybe
diff --git a/src/cmd/go/internal/work/gccgo.go b/src/cmd/go/internal/work/gccgo.go
index 37a828f592..74d3820a66 100644
--- a/src/cmd/go/internal/work/gccgo.go
+++ b/src/cmd/go/internal/work/gccgo.go
@@ -464,8 +464,11 @@ func (tools gccgoToolchain) cc(b *Builder, a *Action, ofile, cfile string) error
defs = append(defs, "-fsplit-stack")
}
defs = tools.maybePIC(defs)
- return b.run(a, p.Dir, p.ImportPath, nil, envList("CC", cfg.DefaultCC(cfg.Goos, cfg.Goarch)), "-Wall", "-g",
- "-I", a.Objdir, "-I", inc, "-o", ofile, defs, "-c", cfile)
+ return b.run(a, p.Dir, p.ImportPath, nil,
+ envList("CC", cfg.DefaultCC(cfg.Goos, cfg.Goarch)),
+ envList("CGO_CPPFLAGS", ""),
+ envList("CGO_CFLAGS", "-Wall -g"), "-I", a.Objdir, "-I", inc, "-o", ofile, defs, "-c", cfile,
+ )
}
// maybePIC adds -fPIC to the list of arguments if needed..
I don't have a test environment.
That suggestion isn't exactly right, as we should also be using the package local #cgo CFLAGS:
when compiling _cgo_defun.c.
Is there a work around for this? Or just wait for Go1.11?
I think it works to add the options to the CC
environment variable.
The workaround for the CC environment variable does seem to work for me. Any ideas what I'm doing wrong?
root@2fe6f091a637:/mnt# echo $CC
/opt/cross/gcc --sysroot=/opt/fsl-qoriq/2.0/sysroots/ppc64e6500-fsl-linux
root@2fe6f091a637:/mnt# go env
GOARCH="ppc64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/docker-path"
GORACE=""
GOROOT="/home/go"
GOTOOLDIR="/opt/gccgo-cross/usr/libexec/gcc/x86_64-linux/7.3.0"
GCCGO="/opt/gccgo-cross/usr/bin/powerpc64-fsl-linux-gccgo"
CC="/opt/cross/gcc"
GOGCCFLAGS="--sysroot=/opt/fsl-qoriq/2.0/sysroots/ppc64e6500-fsl-linux -fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build376397185=/tmp/go-build -gno-record-gcc-switches"
CXX="/opt/gccgo-cross/usr/bin/powerpc64-fsl-linux-g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2 --sysroot=/opt/fsl-qoriq/2.0/sysroots/ppc64e6500-fsl-linux"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
root@2fe6f091a637:/mnt# go get -x github.com/mattn/go-sqlite3
WORK=/tmp/go-build361126006
mkdir -p $WORK/github.com/mattn/go-sqlite3/_obj/
mkdir -p $WORK/github.com/mattn/
cd /home/docker-path/src/github.com/mattn/go-sqlite3
CGO_LDFLAGS="-g" "-O2" "-ldl" "-lpthread" /opt/gccgo-cross/usr/libexec/gcc/x86_64-linux/7.3.0/cgo -objdir $WORK/github.com/mattn/go-sqlite3/_obj/ -importpath github.com/mattn/go-sqlite3 -gccgo -gccgopkgpath=github.com/mattn/go-sqlite3 -- -I $WORK/github.com/mattn/go-sqlite3/_obj/ -g -O2 --sysroot=/opt/fsl-qoriq/2.0/sysroots/ppc64e6500-fsl-linux -std=gnu99 -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE=1 -DHAVE_USLEEP=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_TRACE_SIZE_LIMIT=15 -DSQLITE_OMIT_DEPRECATED -DSQLITE_DISABLE_INTRINSIC -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -Wno-deprecated-declarations -DHAVE_PREAD64=1 -DHAVE_PWRITE64=1 -I. backup.go callback.go error.go sqlite3.go sqlite3_context.go sqlite3_load_extension.go sqlite3_opt_userauth_omit.go sqlite3_other.go sqlite3_type.go
# github.com/mattn/go-sqlite3
In file included from /home/docker-path/src/github.com/mattn/go-sqlite3/backup.go:14:0:
/opt/fsl-qoriq/2.0/sysroots/ppc64e6500-fsl-linux/usr/include/stdlib.h:30:26: error: no include path in which to search for stdlib.h
# include_next <stdlib.h>
^
root@2fe6f091a637:/mnt#
I haven't tested with newer gccgo versions, but in my original report the whole problem resulted from gccgo not using the flags specified in CC
anymore, just the binary path. Maybe that's a separate bug?
I'm unable to compile
go-sqlite3
withgccgo
for the PowerPC plataform.What version of Go are you using (
go version
)?go version go1.8.3 gccgo (Ubuntu 7.2.0-8ubuntu3) 7.2.0 linux/amd64
Does this issue reproduce with the latest release?
I have not tested with the latest since the above is the highest version available as pre-compiled package in Ubuntu
What operating system and processor architecture are you using (
go env
)?Cross-compiling to ppc with gccgo
C compiler:
What did you do?
Attempt to install go-sqlite3:
GCCGO=powerpc-linux-gnuspe-gccgo CGO_ENABLED=1 GOARCH=ppc CGO_ENABLED=1 go-7 get -x github.com/mattn/go-sqlite3
What did you expect to see?
Package compiling
What did you see instead?
Compilation fails with
The compiler I'm using requires some flags to work, in particular the
--sysroot
flag. This is specified in the CC variable which currently is:The above works with the older
go version go1.4.2 gccgo (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609 linux/amd64
. However, with the version indicated above, the compilation fails because go does not include the flags specified in the CC variable. I managed to work around this by setting CGO_CFLAGS and CGO_LDFLAGS, as can be viewed above. However, I still get a compilation error, because apparently gccgo (or cgo?) is not including the CGO_CFLAGS when compiling_cgo_defun.c
as can be viewed in the verbose output below:Observe that the last compiler invocation did not include the contents of CGO_CFLAGS, preventing
--sysroot
being passed which messes the include path and makes compilation fail.