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/cgo: crash when building github.com/timob/jnigi on Windows #26517

Closed
gooid opened this issue Jul 21, 2018 · 15 comments
Closed

cmd/cgo: crash when building github.com/timob/jnigi on Windows #26517

gooid opened this issue Jul 21, 2018 · 15 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows release-blocker
Milestone

Comments

@gooid
Copy link

gooid commented Jul 21, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11beta2 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPROXY=
set GORACE=
set GOROOT=d:\GoLang\go1.11beta2
set GOTMPDIR=
set GOTOOLDIR=d:\GoLang\go1.11beta2\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=B:\TEMP\go-build108520490=/tmp/go-build -gno-record-
gcc-switches

What did you do?

d:\GoLang\go1.11beta2\src\vendor>go get github.com/timob/jnigi
# github.com/timob/jnigi
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x51b1c1]

goroutine 1 [running]:
go/printer.(*printer).expr1(0xc000283520, 0x0, 0x0, 0x0, 0x1)
        d:/GoLang/go1.11beta2/src/go/printer/nodes.go:732 +0x41
go/printer.(*printer).expr(0xc000283520, 0x0, 0x0)
        d:/GoLang/go1.11beta2/src/go/printer/nodes.go:992 +0x58
go/printer.(*printer).expr1(0xc000283520, 0x622500, 0xc00021ca60, 0x0, 0x1)
        d:/GoLang/go1.11beta2/src/go/printer/nodes.go:764 +0xed6
go/printer.(*printer).expr(0xc000283520, 0x622500, 0xc00021ca60)
        d:/GoLang/go1.11beta2/src/go/printer/nodes.go:992 +0x58
go/printer.(*printer).printNode(0xc000283520, 0x5b96a0, 0xc00021ca60, 0xc0001f0960, 0x0)
        d:/GoLang/go1.11beta2/src/go/printer/printer.go:1128 +0x356
go/printer.(*Config).fprint(0x72d830, 0x61fc80, 0xc0003d82a0, 0xc00001c200, 0x5b96a0, 0xc00021ca60, 0xc000306330, 0xc000
2ac001, 0xc0003d82a0)
        d:/GoLang/go1.11beta2/src/go/printer/printer.go:1293 +0x177
go/printer.(*Config).Fprint(0x72d830, 0x61fc80, 0xc0003d82a0, 0xc00001c200, 0x5b96a0, 0xc00021ca60, 0x1, 0x1b)
        d:/GoLang/go1.11beta2/src/go/printer/printer.go:1351 +0x79
main.(*Package).writeDefs(0xc000080100)
        d:/GoLang/go1.11beta2/src/cmd/cgo/out.go:116 +0xbf2
main.main()
        d:/GoLang/go1.11beta2/src/cmd/cgo/main.go:347 +0xb09

@ysmolski
Copy link
Member

ysmolski commented Jul 21, 2018

Here what happens on tip on darwin:

% go get -v -x github.com/timob/jnigi
WORK=/var/folders/km/50gy6_q557v6_7vxbf9b29v00000gn/T/go-build665698633
github.com/timob/jnigi
mkdir -p $WORK/b001/
cd /Users/thorn/go/src/github.com/timob/jnigi
CGO_LDFLAGS='"-g" "-O2" "-ldl"' /Users/thorn/golang/pkg/tool/darwin_amd64/cgo -objdir $WORK/b001/ -importpath github.com/timob/jnigi -- -I $WORK/b001/ -g -O2 -I/Library/Java/Home/include -I/Library/Java/Home/include/darwin ./cinit.go ./cmem.go ./cwrapper.go ./darwin.go
# github.com/timob/jnigi
../../go/src/github.com/timob/jnigi/cinit.go:8:9: fatal error: 'jni.h' file not found
#include<jni.h>
        ^
1 error generated.

@ysmolski ysmolski added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 21, 2018
@gooid
Copy link
Author

gooid commented Jul 21, 2018

@ysmolsky

jni.zip
unzip to: /Users/thorn/go/src/github.com/timob/include

@agnivade
Copy link
Contributor

Looks like a windows issue. Works fine on my linux box after placing the jni.h file.

cd /home/agniva/play/go/src/github.com/timob/jnigi
git config remote.origin.url
cd /home/agniva/play/go/src/github.com/timob/jnigi
git pull --ff-only
cd /home/agniva/play/go/src/github.com/timob/jnigi
git submodule update --init --recursive
cd /home/agniva/play/go/src/github.com/timob/jnigi
git show-ref
cd /home/agniva/play/go/src/github.com/timob/jnigi
git submodule update --init --recursive
WORK=/tmp/go-build916328045
mkdir -p $WORK/b028/
cd /home/agniva/sdk/go1.11beta2/src/runtime/cgo
CGO_LDFLAGS='"-I$JAVA_HOME/include/linux" "-lpthread"' /home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/cgo -objdir $WORK/b028/ -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -- -I $WORK/b028/ -g -O2 -Wall -Werror ./cgo.go
cd $WORK
gcc -fno-caret-diagnostics -c -x c - || true
gcc -Qunused-arguments -c -x c - || true
gcc -fdebug-prefix-map=a=b -c -x c - || true
gcc -gno-record-gcc-switches -c -x c - || true
cd $WORK/b028
TERM='dumb' gcc -I /home/agniva/sdk/go1.11beta2/src/runtime/cgo -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -Wall -Werror -o ./_x001.o -c _cgo_export.c
TERM='dumb' gcc -I /home/agniva/sdk/go1.11beta2/src/runtime/cgo -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -Wall -Werror -o ./_x002.o -c cgo.cgo2.c
cd /home/agniva/sdk/go1.11beta2/src/runtime/cgo
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x003.o -c gcc_context.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x004.o -c gcc_fatalf.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x005.o -c gcc_libinit.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x006.o -c gcc_linux_amd64.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x007.o -c gcc_mmap.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x008.o -c gcc_setenv.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x009.o -c gcc_sigaction.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x010.o -c gcc_traceback.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x011.o -c gcc_util.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I $WORK/b028/ -g -O2 -Wall -Werror -o $WORK/b028/_x012.o -c gcc_amd64.S
cd $WORK/b028
TERM='dumb' gcc -I /home/agniva/sdk/go1.11beta2/src/runtime/cgo -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -Wall -Werror -o ./_cgo_main.o -c _cgo_main.c
cd /home/agniva/sdk/go1.11beta2/src/runtime/cgo
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b028=/tmp/go-build -gno-record-gcc-switches -o $WORK/b028/_cgo_.o $WORK/b028/_cgo_main.o $WORK/b028/_x001.o $WORK/b028/_x002.o $WORK/b028/_x003.o $WORK/b028/_x004.o $WORK/b028/_x005.o $WORK/b028/_x006.o $WORK/b028/_x007.o $WORK/b028/_x008.o $WORK/b028/_x009.o $WORK/b028/_x010.o $WORK/b028/_x011.o $WORK/b028/_x012.o -I$JAVA_HOME/include/linux -lpthread
TERM='dumb' /home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/cgo -dynpackage cgo -dynimport $WORK/b028/_cgo_.o -dynout $WORK/b028/_cgo_import.go -dynlinker
cat >$WORK/b028/importcfg << 'EOF' # internal
# import config
EOF
/home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/compile -o $WORK/b028/_pkg_.a -trimpath $WORK/b028 -p runtime/cgo -std -buildid _y8Fh4VKAK3JA9wsB6V3/_y8Fh4VKAK3JA9wsB6V3 -goversion go1.11beta2 -D "" -importcfg $WORK/b028/importcfg -pack -asmhdr $WORK/b028/go_asm.h -c=4 ./callbacks.go ./callbacks_traceback.go ./iscgo.go ./mmap.go ./setenv.go ./sigaction.go $WORK/b028/_cgo_gotypes.go $WORK/b028/cgo.cgo1.go $WORK/b028/_cgo_import.go
/home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/asm -trimpath $WORK/b028 -I $WORK/b028/ -I /home/agniva/sdk/go1.11beta2/pkg/include -D GOOS_linux -D GOARCH_amd64 -o $WORK/b028/asm_amd64.o ./asm_amd64.s
/home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/pack r $WORK/b028/_pkg_.a $WORK/b028/asm_amd64.o $WORK/b028/_x001.o $WORK/b028/_x002.o $WORK/b028/_x003.o $WORK/b028/_x004.o $WORK/b028/_x005.o $WORK/b028/_x006.o $WORK/b028/_x007.o $WORK/b028/_x008.o $WORK/b028/_x009.o $WORK/b028/_x010.o $WORK/b028/_x011.o $WORK/b028/_x012.o # internal
/home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/buildid -w $WORK/b028/_pkg_.a # internal
cp $WORK/b028/_pkg_.a /home/agniva/.cache/go-build/f6/f6580b55dd39a18d8149deca3b9b62c558f31f6bc759ab3e3de75959b4bec064-d # internal
mkdir -p $WORK/b001/
cd /home/agniva/play/go/src/github.com/timob/jnigi
CGO_LDFLAGS='"-I$JAVA_HOME/include/linux" "-ldl"' /home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/cgo -objdir $WORK/b001/ -importpath github.com/timob/jnigi -- -I $WORK/b001/ -g -O2 -I/home/agniva/play/go/src/github.com/timob/include -I/usr/lib/jvm/default-java/include ./cinit.go ./cmem.go ./cwrapper.go ./linux.go
cd $WORK/b001
TERM='dumb' gcc -I /home/agniva/play/go/src/github.com/timob/jnigi -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -I/home/agniva/play/go/src/github.com/timob/include -I/usr/lib/jvm/default-java/include -o ./_x001.o -c _cgo_export.c
TERM='dumb' gcc -I /home/agniva/play/go/src/github.com/timob/jnigi -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -I/home/agniva/play/go/src/github.com/timob/include -I/usr/lib/jvm/default-java/include -o ./_x002.o -c cinit.cgo2.c
TERM='dumb' gcc -I /home/agniva/play/go/src/github.com/timob/jnigi -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -I/home/agniva/play/go/src/github.com/timob/include -I/usr/lib/jvm/default-java/include -o ./_x003.o -c cmem.cgo2.c
TERM='dumb' gcc -I /home/agniva/play/go/src/github.com/timob/jnigi -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -I/home/agniva/play/go/src/github.com/timob/include -I/usr/lib/jvm/default-java/include -o ./_x004.o -c cwrapper.cgo2.c
TERM='dumb' gcc -I /home/agniva/play/go/src/github.com/timob/jnigi -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -I/home/agniva/play/go/src/github.com/timob/include -I/usr/lib/jvm/default-java/include -o ./_x005.o -c linux.cgo2.c
TERM='dumb' gcc -I /home/agniva/play/go/src/github.com/timob/jnigi -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -I/home/agniva/play/go/src/github.com/timob/include -I/usr/lib/jvm/default-java/include -o ./_cgo_main.o -c _cgo_main.c
cd /home/agniva/play/go/src/github.com/timob/jnigi
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -o $WORK/b001/_cgo_.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o $WORK/b001/_x003.o $WORK/b001/_x004.o $WORK/b001/_x005.o -I$JAVA_HOME/include/linux -ldl
TERM='dumb' /home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/cgo -dynpackage jnigi -dynimport $WORK/b001/_cgo_.o -dynout $WORK/b001/_cgo_import.go
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile errors=/home/agniva/sdk/go1.11beta2/pkg/linux_amd64/errors.a
packagefile fmt=/home/agniva/sdk/go1.11beta2/pkg/linux_amd64/fmt.a
packagefile log=/home/agniva/sdk/go1.11beta2/pkg/linux_amd64/log.a
packagefile runtime=/home/agniva/sdk/go1.11beta2/pkg/linux_amd64/runtime.a
packagefile strings=/home/agniva/sdk/go1.11beta2/pkg/linux_amd64/strings.a
packagefile runtime/cgo=$WORK/b028/_pkg_.a
packagefile syscall=/home/agniva/sdk/go1.11beta2/pkg/linux_amd64/syscall.a
EOF
/home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/compile -o $WORK/b001/_pkg_.a -trimpath $WORK/b001 -p github.com/timob/jnigi -buildid 5gsjjDjtqhCFBCgZJ6af/5gsjjDjtqhCFBCgZJ6af -goversion go1.11beta2 -D "" -importcfg $WORK/b001/importcfg -pack -c=4 ./jnigi.go $WORK/b001/_cgo_gotypes.go $WORK/b001/cinit.cgo1.go $WORK/b001/cmem.cgo1.go $WORK/b001/cwrapper.cgo1.go $WORK/b001/linux.cgo1.go $WORK/b001/_cgo_import.go
/home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/pack r $WORK/b001/_pkg_.a $WORK/b001/_x001.o $WORK/b001/_x002.o $WORK/b001/_x003.o $WORK/b001/_x004.o $WORK/b001/_x005.o # internal
/home/agniva/sdk/go1.11beta2/pkg/tool/linux_amd64/buildid -w $WORK/b001/_pkg_.a # internal
cp $WORK/b001/_pkg_.a /home/agniva/.cache/go-build/aa/aad21fcbe91e7f8daeddd4106b5490da3b1520e76085155aee4ec36b405b015a-d # internal
# github.com/timob/jnigi
../jnigi/cwrapper.go: In function ‘AttachCurrentThread’:
../jnigi/cwrapper.go:570:41: warning: passing argument 2 of ‘(*vm)->AttachCurrentThread’ from incompatible pointer type [-Wincompatible-pointer-types]
  return (*vm)->AttachCurrentThread (vm, penv, args);
                                         ^
../jnigi/cwrapper.go:570:41: note: expected ‘const struct JNINativeInterface ***’ but argument is of type ‘void **’
mkdir -p /home/agniva/play/go/pkg/linux_amd64/github.com/timob/
cp $WORK/b001/_pkg_.a /home/agniva/play/go/pkg/linux_amd64/github.com/timob/jnigi.a
rm -r $WORK/b001/

@ysmolski
Copy link
Member

It worked on Mac after putting the .h file into github.com/timob/jnigi.
@gooid can you paste the result of running the get command with -v -x parameters?

@mvdan
Copy link
Member

mvdan commented Jul 21, 2018

Looking at the trace, it seems like the cgo tool is trying to generate (print) an invalid Go file. That is, it's trying to print an *ast.StarExpr where the child expression is unset. The package being built has special files for Windows, so the bug is probably triggered by those.

@gooid does this happen with Go 1.10.3?

@mvdan mvdan changed the title cmd/go: build github.com/timob/jnigi fail. cmd/cgo: crash when building github.com/timob/jnigi on Windows Jul 21, 2018
@mvdan
Copy link
Member

mvdan commented Jul 21, 2018

cc @ianlancetaylor

@gooid
Copy link
Author

gooid commented Jul 21, 2018

@mvdan
Go 1.10.3 and Go 1.11beta1 is ok.

@ysmolsky

D:\Golang\go1.11beta2\src\vendor>go get -v -x github.com/timob/jnigi
WORK=C:\Users\W10\AppData\Local\Temp\go-build530163350
github.com/timob/jnigi
mkdir -p $WORK\b001\
cd C:\Users\W10\go\src\github.com\timob\jnigi
CGO_LDFLAGS='"-g" "-O2" "-ljvm" "-Lc:/oraclejdk/jre/bin/server"' "D:\\Golang\\go1.11beta2\\pkg\\tool\\windows_amd64\\cgo.exe" -objdir "C:\\Users\\W10\\AppData\\Local\\Temp\\go-build530163350\\b001\\" -importpath github.com/timob/jnigi -- -I "C:\\Users\\W10\\AppData\\Local\\Temp\\go-build530163350\\b001\\" -g -O2 "-IC:\\Users\\W10\\go\\src\\github.com\\timob\\include" -Ic:/oraclejdk/include -Ic:/oraclejdk/include/win32 "C:\\Users\\W10\\go\\src\\github.com\\timob\\jnigi\\cinit.go" "C:\\Users\\W10\\go\\src\\github.com\\timob\\jnigi\\cmem.go" "C:\\Users\\W10\\go\\src\\github.com\\timob\\jnigi\\cwrapper.go" "C:\\Users\\W10\\go\\src\\github.com\\timob\\jnigi\\windows.go"
# github.com/timob/jnigi
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x51b1c1]

goroutine 1 [running]:
go/printer.(*printer).expr1(0xc00041b520, 0x0, 0x0, 0x0, 0x1)
        D:/Golang/go1.11beta2/src/go/printer/nodes.go:732 +0x41
go/printer.(*printer).expr(0xc00041b520, 0x0, 0x0)
        D:/Golang/go1.11beta2/src/go/printer/nodes.go:992 +0x58
go/printer.(*printer).expr1(0xc00041b520, 0x622500, 0xc000223d00, 0x0, 0x1)
        D:/Golang/go1.11beta2/src/go/printer/nodes.go:764 +0xed6
go/printer.(*printer).expr(0xc00041b520, 0x622500, 0xc000223d00)
        D:/Golang/go1.11beta2/src/go/printer/nodes.go:992 +0x58
go/printer.(*printer).printNode(0xc00041b520, 0x5b96a0, 0xc000223d00, 0xc0004a20b0, 0x0)
        D:/Golang/go1.11beta2/src/go/printer/printer.go:1128 +0x356
go/printer.(*Config).fprint(0x72d830, 0x61fc80, 0xc0000fa2a0, 0xc000048180, 0x5b96a0, 0xc000223d00, 0xc0004a42a0, 0xc00016f201, 0xc0000fa2a0)
        D:/Golang/go1.11beta2/src/go/printer/printer.go:1293 +0x177
go/printer.(*Config).Fprint(0x72d830, 0x61fc80, 0xc0000fa2a0, 0xc000048180, 0x5b96a0, 0xc000223d00, 0x1, 0x1b)
        D:/Golang/go1.11beta2/src/go/printer/printer.go:1351 +0x79
main.(*Package).writeDefs(0xc000082100)
        D:/Golang/go1.11beta2/src/cmd/cgo/out.go:116 +0xbf2
main.main()
        D:/Golang/go1.11beta2/src/cmd/cgo/main.go:347 +0xb09

@mvdan
Copy link
Member

mvdan commented Jul 21, 2018

@gooid thanks. Could you by any chance bisect this between go1.11beta1 and go1.11beta2? Knowing which commit added the regression would be very useful. git log go1.11beta1..go1.11beta2 src/cmd/cgo only shows 10 commits, so it shouldn't take you too long to find the culprit.

In particular, a371bc2 and b888a62 could be related, by looking at the commit log.

@gooid
Copy link
Author

gooid commented Jul 21, 2018

@mvdan you're right,it's b888a62 .

@mvdan
Copy link
Member

mvdan commented Jul 21, 2018

Thanks. In that case, cc @randall77 too.

@ianlancetaylor
Copy link
Contributor

Can we find out which typedef is failing to print?

@alexbrainman
Copy link
Member

Can we find out which typedef is failing to print?

I am not sure what you are after, but I did this:

c:\Users\Alex\dev\go\src>git rev-parse HEAD
08ab820437229f68fe5f7dad1c9b4940c674e206

c:\Users\Alex\dev\go\src>git diff
diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go
index 07874974ee..e332fc46e8 100644
--- a/src/cmd/cgo/out.go
+++ b/src/cmd/cgo/out.go
@@ -100,6 +100,7 @@ func (p *Package) writeDefs() {
        for _, name := range typedefNames {
                def := typedef[name]
                fmt.Fprintf(fgo2, "type %s ", name)
+               fmt.Printf("type %s\n", name)
                // We don't have source info for these types, so write them out without source info.
                // Otherwise types would look like:
                //

c:\Users\Alex\dev\go\src>

and then I can see this output:

...
# github.com/timob/jnigi
type _Ctype_JNIEnv
type _Ctype_JNINativeMethod
type _Ctype_JavaVM
type _Ctype_JavaVMInitArgs
type _Ctype_JavaVMOption
type _Ctype___gnuc_va_list
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x51b1c1]

goroutine 1 [running]:
go/printer.(*printer).expr1(0xc000059500, 0x0, 0x0, 0x0, 0x1)
        c:/users/alex/dev/go/src/go/printer/nodes.go:732 +0x41
go/printer.(*printer).expr(0xc000059500, 0x0, 0x0)
        c:/users/alex/dev/go/src/go/printer/nodes.go:992 +0x58
go/printer.(*printer).expr1(0xc000059500, 0x6225e0, 0xc000452900, 0x0, 0x1)
        c:/users/alex/dev/go/src/go/printer/nodes.go:764 +0xed6
go/printer.(*printer).expr(0xc000059500, 0x6225e0, 0xc000452900)
        c:/users/alex/dev/go/src/go/printer/nodes.go:992 +0x58
go/printer.(*printer).printNode(0xc000059500, 0x5b96a0, 0xc000452900, 0xc0002ce0e0, 0x0)
        c:/users/alex/dev/go/src/go/printer/printer.go:1128 +0x356
go/printer.(*Config).fprint(0x72d830, 0x61fd60, 0xc0002442a0, 0xc0000321c0, 0x5b96a0, 0xc000452900, 0xc0004802d0, 0x1, 0xc0002442a0)
        c:/users/alex/dev/go/src/go/printer/printer.go:1293 +0x177
go/printer.(*Config).Fprint(0x72d830, 0x61fd60, 0xc0002442a0, 0xc0000321c0, 0x5b96a0, 0xc000452900, 0x0, 0x0)
        c:/users/alex/dev/go/src/go/printer/printer.go:1351 +0x79
main.(*Package).writeDefs(0xc000070100)
        c:/users/alex/dev/go/src/cmd/cgo/out.go:117 +0xc89
main.main()
        c:/users/alex/dev/go/src/cmd/cgo/main.go:347 +0xb09

c:\Users\Alex\dev\go\src>

Alex

@randall77
Copy link
Contributor

This may be due to:

typedef __builtin_va_list __gnuc_va_list;

Where __builtin_va_list is not defined anywhere; it's probably a special case inside the compiler.
Could you do: fmt.Printf("type=%s def=%+v\n", name, def) instead?

@alexbrainman
Copy link
Member

Could you do: fmt.Printf("type=%s def=%+v\n", name, def) instead?

Sure:

...
# github.com/timob/jnigi
type=_Ctype_JNIEnv def=&{Size:8 Align:8 C:JNIEnv Go:0xc000237c60 EnumValues:map[] Typedef:}
type=_Ctype_JNINativeMethod def=&{Size:24 Align:8 C:JNINativeMethod Go:_Ctype_struct___0 EnumValues:map[] Typedef:}
type=_Ctype_JavaVM def=&{Size:8 Align:8 C:JavaVM Go:0xc00036a540 EnumValues:map[] Typedef:}
type=_Ctype_JavaVMInitArgs def=&{Size:24 Align:8 C:JavaVMInitArgs Go:_Ctype_struct_JavaVMInitArgs EnumValues:map[] Typedef:}
type=_Ctype_JavaVMOption def=&{Size:16 Align:8 C:JavaVMOption Go:_Ctype_struct_JavaVMOption EnumValues:map[] Typedef:}
type=_Ctype___gnuc_va_list def=&{Size:8 Align:8 C:__gnuc_va_list Go:0xc00022b180 EnumValues:map[] Typedef:}
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x51b1c1]

goroutine 1 [running]:
go/printer.(*printer).expr1(0xc0003214f0, 0x0, 0x0, 0x0, 0x1)
        c:/users/alex/dev/go/src/go/printer/nodes.go:732 +0x41
go/printer.(*printer).expr(0xc0003214f0, 0x0, 0x0)
        c:/users/alex/dev/go/src/go/printer/nodes.go:992 +0x58
go/printer.(*printer).expr1(0xc0003214f0, 0x6225e0, 0xc00022b180, 0x0, 0x1)
        c:/users/alex/dev/go/src/go/printer/nodes.go:764 +0xed6
go/printer.(*printer).expr(0xc0003214f0, 0x6225e0, 0xc00022b180)
        c:/users/alex/dev/go/src/go/printer/nodes.go:992 +0x58
go/printer.(*printer).printNode(0xc0003214f0, 0x5b96a0, 0xc00022b180, 0xc00012a230, 0x0)
        c:/users/alex/dev/go/src/go/printer/printer.go:1128 +0x356
go/printer.(*Config).fprint(0x72d830, 0x61fd60, 0xc0004942a0, 0xc000046180, 0x5b96a0, 0xc00022b180, 0xc0001302a0, 0x1, 0xc0004942a0)
        c:/users/alex/dev/go/src/go/printer/printer.go:1293 +0x177
go/printer.(*Config).Fprint(0x72d830, 0x61fd60, 0xc0004942a0, 0xc000046180, 0x5b96a0, 0xc00022b180, 0x0, 0x0)
        c:/users/alex/dev/go/src/go/printer/printer.go:1351 +0x79
main.(*Package).writeDefs(0xc000080100)
        c:/users/alex/dev/go/src/cmd/cgo/out.go:117 +0xcb0
main.main()
        c:/users/alex/dev/go/src/cmd/cgo/main.go:347 +0xb09

c:\>

Alex

@gopherbot
Copy link

Change https://golang.org/cl/126275 mentions this issue: cmd/cgo: make sure we FinishType everything

@golang golang locked and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows release-blocker
Projects
None yet
Development

No branches or pull requests

9 participants