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

debug/pe: big-obj is not supported #24341

Open
k-takata opened this issue Mar 10, 2018 · 2 comments
Open

debug/pe: big-obj is not supported #24341

k-takata opened this issue Mar 10, 2018 · 2 comments
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@k-takata
Copy link

cgo doesn't support the big-obj format.

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

go version go1.10 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 GOOS=windows

What did you do?

I tried to link a .o file which is generated with the -Wa,-mbig-obj gcc option.
See the following background for detail.

What did you expect to see?

The big-obj format is supported by cgo.

What did you see instead?

cannot parse gcc output $WORK\b001\\_cgo_.o as ELF, Mach-O, PE object

The message is produced at here:

fatalf("cannot parse gcc output %s as ELF, Mach-O, PE object", gccTmp())

I suppose debug/pe doesn't support the big-obj format.

Background

I'm now trying to use wxGo, but the size of an executable file is quite big (~30MB), so I tried to reduce the size by using -fdata-sections -ffunction-sections CPPFLAGS and -Wl,--gc-sections LDFLAGS. (See: https://stackoverflow.com/a/6770305/4570471)
However, this caused the following error:

C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: $WORK\b001\_x003.o: too many sections (70137)
C:\Users\*******\AppData\Local\Temp\ccjbnMxS.s: Fatal error: can't close $WORK\b001\_x003.o: File too big

This is because the traditional PE-COFF format stores the number of sections with a 16-bit signed integer. To support more than 32K sections, the big-obj format is needed, and the -Wa,-mbig-obj CPPFLAGS can be used for that. However, cgo doesn't support the big-obj format.

Steps to reproduce:

path C:\TDM-GCC-64\bin;%PATH%
set "CGO_LDFLAGS_ALLOW=-Wl,--subsystem,windows|-mwindows"
set "CGO_CPPFLAGS_ALLOW=-fdata-sections|-ffunction-sections|-Wa,-mbig-obj"
go get -u -d github.com/dontpanic92/wxGo/wx
cd %GOPATH%\src\github.com\dontpanic92\wxGo

Then apply the following patch to wxGo:

--- a/wx/setup_windows_amd64.go
+++ b/wx/setup_windows_amd64.go
@@ -1,6 +1,6 @@
 package wx
 
-// #cgo CPPFLAGS: -I${SRCDIR}/windows_amd64/ -I${SRCDIR}/../wxWidgets/wxWidgets-3.1.0/include -D_FILE_OFFSET_BITS=64 -D__WXMSW__
+// #cgo CPPFLAGS: -I${SRCDIR}/windows_amd64/ -I${SRCDIR}/../wxWidgets/wxWidgets-3.1.0/include -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -fdata-sections -ffunction-sections -Wa,-mbig-obj
 // #cgo !wxgo_binary_package_build LDFLAGS: -L${SRCDIR}/windows_amd64/lib -lwxmsw31u -lwxmsw31u_gl -lwxscintilla -lwxregexu -lwxexpat -lwxtiff -lwxjpeg -lwxpng -lwxzlib
 // #cgo mingw_workaround LDFLAGS: -Wl,--subsystem,windows,--allow-multiple-definition
 // #cgo !mingw_workaround LDFLAGS: -Wl,--subsystem,windows

Then:

cd wx
go install -x .

The following error is shown:

cannot parse gcc output $WORK\b001\\_cgo_.o as ELF, Mach-O, PE object

Cf. in case of Haskell: https://ghc.haskell.org/trac/ghc/ticket/13815

@andybons andybons added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 12, 2018
@andybons andybons added this to the Unplanned milestone Mar 12, 2018
@andybons
Copy link
Member

/cc @ianlancetaylor

@ianlancetaylor ianlancetaylor changed the title cmd/cgo, debug/pe: big-obj is not supported debug/pe: big-obj is not supported Mar 12, 2018
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 12, 2018
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 12, 2018
@ianlancetaylor
Copy link
Contributor

I think this will all start working if we modify the debug/pe package to support the big-obj format. I haven't looked at the format, but assuming there is nothing weird about it we should just go ahead and do that.

Labelled as "help wanted".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants