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: better error message when a different gcc is needed on Windows #21024

Closed
pkch opened this issue Jul 15, 2017 · 11 comments
Closed

cmd/cgo: better error message when a different gcc is needed on Windows #21024

pkch opened this issue Jul 15, 2017 · 11 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@pkch
Copy link

pkch commented Jul 15, 2017

When building go from source on Windows, the gcc needs to support input from stdin; the exact command run is:

$ gcc -E -dM -xc -m64 -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror - <<EOF

something something

EOF

Apparently, not all gcc for Windows handle reading from stdin correctly; mine (realgcc) didn't, and I got this very brief error message when running tests with all.bat:

# runtime/cgo
realgcc.exe: fatal error: no input files
compilation terminated.

It would be nice to have an error message suggesting to use a different gcc (and ideally, recommending a particular one).

@pkch pkch changed the title Better error message needed when a different gcc is needed on Windows Better error message when a different gcc is needed on Windows Jul 15, 2017
@ianlancetaylor ianlancetaylor changed the title Better error message when a different gcc is needed on Windows cmd/cgo: better error message when a different gcc is needed on Windows Jul 15, 2017
@ianlancetaylor
Copy link
Contributor

Which version of Go?

In current versions of Go the comment that is executed is not precisely the command that is printed. cgo actually writes the input to a file, and passes the file to the compiler. That should have happened in this case. That was fixed in the Go 1.7 release.

@pkch
Copy link
Author

pkch commented Jul 15, 2017

I was building from master, and pointed go bootstrap path to the newest ( go 1.8.3) binary that I just downloaded.

@ianlancetaylor
Copy link
Contributor

Can you attach the complete output from cgo with the -debug-gcc option?

Note that the command that cgo displays is not the exact command that it executes. So while clearly something is wrong, I don't yet see how the problem could be passing standard input to the compiler. See the run function in cmd/cgo/util.go.

@pkch
Copy link
Author

pkch commented Jul 15, 2017

IIUC, I don't get to the point of running cgo; the error happens when building cgo:

C:\Users\max\Downloads\go\src>..\bin\go build -x -v runtime/cgo
WORK=C:\Users\max\AppData\Local\Temp\go-build037782430
runtime/cgo
mkdir -p $WORK\runtime\cgo\_obj\
mkdir -p $WORK\runtime\
cd C:\Users\max\Downloads\go\src\runtime\cgo
CGO_LDFLAGS="-g" "-O2" "C:\\Users\\max\\Downloads\\go\\pkg\\tool\\windows_amd64\\cgo.exe" -objdir "C:\\Users\\max\\AppData\\Local\\Temp\\go-build037782430\\runtime\\cgo\\_obj\\" -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -- -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build037782430\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror cgo.go                                                                                                                               
# runtime/cgo
realgcc.exe: fatal error: no input files
compilation terminated.                                                                                                                                                      

Should I add any options to this to provide more details? (realgcc.exe is what's gcc is linked to on my computer.)

@ianlancetaylor
Copy link
Contributor

That is running cgo, not building cgo. It is running the program C:\\Users\\max\\Downloads\\go\\pkg\\tool\\windows_amd64\\cgo.exe with various environment variables and options.

A simple thing that may help is to temporarily replace realgcc.exe with a program that just dumps its arguments, such as the echo program if you have that. That will shows us exactly how the compiler is being invoked.

@pkch
Copy link
Author

pkch commented Jul 16, 2017

This is what I'm getting after replacing gcc (which came with Haskell distro, and seems to be mingw gcc) with echo:

C:\Users\max\Downloads\go\src>..\bin\go build -x -v runtime/cgo
WORK=C:\Users\max\AppData\Local\Temp\go-build247954586
runtime/cgo
mkdir -p $WORK\runtime\cgo\_obj\
mkdir -p $WORK\runtime\
cd C:\Users\max\Downloads\go\src\runtime\cgo
CGO_LDFLAGS="-g" "-O2" "C:\\Users\\max\\Downloads\\go\\pkg\\tool\\windows_amd64\\cgo.exe" -objdir "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -- -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror cgo.go
cd $WORK
gcc -fdebug-prefix-map=a=b -c trivial.c
gcc -gno-record-gcc-switches -c trivial.c
cd $WORK\runtime\cgo\_obj
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\_cgo_export.o" -c _cgo_export.c
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror -o $WORK\runtime\cgo\_obj\_cgo_export.o -c _cgo_export.c
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\cgo.cgo2.o" -c cgo.cgo2.c
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror -o $WORK\runtime\cgo\_obj\cgo.cgo2.o -c cgo.cgo2.c
cd C:\Users\max\Downloads\go\src\runtime\cgo
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_context.o" -c gcc_context.c
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror -o $WORK\runtime\cgo\_obj\gcc_context.o -c gcc_context.c
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_libinit_windows.o" -c gcc_libinit_windows.c
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror -o $WORK\runtime\cgo\_obj\gcc_libinit_windows.o -c gcc_libinit_windows.c
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_util.o" -c gcc_util.c
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror -o $WORK\runtime\cgo\_obj\gcc_util.o -c gcc_util.c
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_windows_amd64.o" -c gcc_windows_amd64.c
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror -o $WORK\runtime\cgo\_obj\gcc_windows_amd64.o -c gcc_windows_amd64.c
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_amd64.o" -c gcc_amd64.S
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror -o $WORK\runtime\cgo\_obj\gcc_amd64.o -c gcc_amd64.S
cd $WORK\runtime\cgo\_obj
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -I "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\" -g -O2 -Wall -Werror -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\_cgo_main.o" -c _cgo_main.c
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -I $WORK\runtime\cgo\_obj\ -g -O2 -Wall -Werror -o $WORK\runtime\cgo\_obj\_cgo_main.o -c _cgo_main.c
cd C:\Users\max\Downloads\go\src\runtime\cgo
gcc -I "C:\\Users\\max\\Downloads\\go\\src\\runtime\\cgo" -m64 -mthreads -fmessage-length=0 "-fdebug-prefix-map=C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586=/tmp/go-build" -gno-record-gcc-switches -o "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\_cgo_.o" "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\_cgo_main.o" "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\_cgo_export.o" "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\cgo.cgo2.o" "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_context.o" "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_libinit_windows.o" "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_util.o" "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_windows_amd64.o" "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\gcc_amd64.o" -g -O2
# runtime/cgo
-I runtime\cgo -m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build247954586=/tmp/go-build -gno-record-gcc-switches -o $WORK\runtime\cgo\_obj\_cgo_.o $WORK\runtime\cgo\_obj\_cgo_main.o $WORK\runtime\cgo\_obj\_cgo_export.o $WORK\runtime\cgo\_obj\cgo.cgo2.o $WORK\runtime\cgo\_obj\gcc_context.o $WORK\runtime\cgo\_obj\gcc_libinit_windows.o $WORK\runtime\cgo\_obj\gcc_util.o $WORK\runtime\cgo\_obj\gcc_windows_amd64.o $WORK\runtime\cgo\_obj\gcc_amd64.o -g -O2
"C:\\Users\\max\\Downloads\\go\\pkg\\tool\\windows_amd64\\cgo.exe" -dynpackage cgo -dynimport "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\_cgo_.o" -dynout "C:\\Users\\max\\AppData\\Local\\Temp\\go-build247954586\\runtime\\cgo\\_obj\\_cgo_import.go" -dynlinker
# runtime/cgo
cannot parse $WORK\runtime\cgo\_obj\_cgo_.o as ELF, Mach-O or PE

@ianlancetaylor
Copy link
Contributor

Thanks. Unfortunately, it looks like cgo breaks (unable to read _cgo_.o) before it reaches the point of failure. Perhaps you could use a script that echos the argument and then execs the real compiler.

@pkch
Copy link
Author

pkch commented Jul 17, 2017

Sorry, Windows + cgo build system outsmarted me. However much I tried to trick them with a Windows batch files to echo the arguments (to a file or to screen) and compile, it still managed to hide everything up until the "no input files" error. I will try again some time.

I guess that it's better to just use the recommended gcc anyway, and I just noticed the warning about incompatibility with some other flavors of gcc.

@odeke-em
Copy link
Member

Not a regression so I'll mark this for investigation during the Go1.10 cycle.

@odeke-em odeke-em added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 21, 2017
@odeke-em odeke-em added this to the Go1.10 milestone Jul 21, 2017
@alexbrainman
Copy link
Member

Sorry, Windows + cgo build system outsmarted me. However much I tried to trick them with a Windows batch files to echo the arguments (to a file or to screen)

I always struggle with batch files. I would use Go to write such tool instead. You will need to invoke programs with redirected stdin/stdout/stderr, pass program parameters and print to the screen or file - Go should be fine for that.

Alex

@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Aug 21, 2018
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants