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/dwarf: cgo produces malformed DWARF data #32673

Closed
mistydemeo opened this issue Jun 18, 2019 · 15 comments
Closed

debug/dwarf: cgo produces malformed DWARF data #32673

mistydemeo opened this issue Jun 18, 2019 · 15 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@mistydemeo
Copy link
Contributor

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

$ go version
go version go1.12.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes, including master.

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

macOS 10.15 beta 2

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mistydemeo/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mistydemeo/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.6/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mistydemeo/oss/go/src/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y2/qxl_xqt53vb2f5yrkmtdkyxc0000gn/T/go-build736553091=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Build a Go binary with cgo usage, for example https://github.com/sstephenson/launch_socket_server

What did you expect to see?

Binary is built and works.

What did you see instead?

Binary receives a SIGABRT with the following error:

dyld: malformed mach-o image: segment __DWARF has vmsize < filesize
fish: 'launch_socket_server' terminated by signal SIGABRT (Abort)

Examining some binaries produced by Go, it appears this bug predates macOS 10.15; however, the macOS 10.15 SDK is pickier about it, and any malformed binaries built against it will fail to execute with this error.

I've tested using the latest master to see if any of the commits reference #31459 affect it, but this behaviour still occurs.

@odeke-em
Copy link
Member

Thank you for this report @mistydemeo!

I shall page some experts @ianlancetaylor @heschik @dr2chase

@odeke-em odeke-em added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 19, 2019
@thanm
Copy link
Contributor

thanm commented Jun 19, 2019

I can take an initial look at this.

NB, possibly related to #21647 ?

@mistydemeo
Copy link
Contributor Author

That definitely looks related.

@thanm
Copy link
Contributor

thanm commented Jun 19, 2019

Well, I am a little out of my depth here (not a MachO expert) but looking at the dyld source here around line 287 it might be possible to work around this by setting the initial protection to zero.

I don't have any viable way to test the fix, though -- the strict checking in question is hardwired based on the OS version it looks like.

@mistydemeo if I send a CL would you be able to test it (e.g. apply patch to Go source, rebuild, etc)?

@mistydemeo
Copy link
Contributor Author

@thanm Yes, absolutely. I can test. I've been testing a few tweaks locally so far, glad to test anything you send me too!

@gopherbot
Copy link

Change https://golang.org/cl/182958 mentions this issue: cmd/link: macos: set initial protection of 0 for __DWARF segment

@thanm
Copy link
Contributor

thanm commented Jun 19, 2019

OK, thanks. I sent a CL -- if you can patch that in and see if it helps, I'd be grateful.

@mistydemeo
Copy link
Contributor Author

Confirmed that has fixed the issue. After building Go at this branch, I tried rebuilding launch_socket_server and another affected project and both are now accepted by dyld.

@thanm
Copy link
Contributor

thanm commented Jun 19, 2019

Cool, glad to hear it. I'll see about getting it reviewed and checked in. Thanks for your help.

@mistydemeo
Copy link
Contributor Author

Thanks! Can you make sure this gets backported to all maintenance branches, please? I can also open backport requests if you'd like.

@thanm
Copy link
Contributor

thanm commented Jun 19, 2019

Yes, if you can open requests I can follow up.

@mistydemeo
Copy link
Contributor Author

@gopherbot please consider this for backport, it's a regression

@gopherbot
Copy link

Backport issue(s) opened: #32696 (for 1.11), #32697 (for 1.12).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@gopherbot
Copy link

Change https://golang.org/cl/183237 mentions this issue: cmd/link: revise previous __DWARF segment protection fix

gopherbot pushed a commit that referenced this issue Jun 21, 2019
Tweak the previous fix for issue 32673 (in CL 182958) to work around
problems with c-shared build mode that crop up on some of the builders
(10.11, 10.12).  We now consistently set vmaddr and vmsize to zero
for the DWARF segment regardless of build mode.

Updates #32673

Change-Id: Id1fc213590ad00c28352925e2d754d760e022b5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/183237
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
ackratos added a commit to bnb-chain/node that referenced this issue Oct 21, 2019
ns-codereview pushed a commit to couchbase/tlm that referenced this issue Oct 28, 2019
To address this error seen with MacOS Catalina ..
dyld: malformed mach-o image: segment __DWARF has vmsize < filesize

Also see ..
golang/go#32673

Change-Id: I5aa6f86ba7c45bc380d748f35601ac8fb40e688e
Reviewed-on: http://review.couchbase.org/117022
Reviewed-by: Chris Hillery <ceej@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
@buihdk
Copy link

buihdk commented Apr 30, 2020

I still encountered this issue in the Go newest version v1.14.2. I posted an issue here, could someone please check? #38765

kubkon added a commit to kubkon/zig that referenced this issue Dec 24, 2020
Preallocate finite filesize for `__DWARF`, but make sure it is
nonloadable by setting protection flags to always 0, and make it
vmsize also 0. I found this is required to make the `dyld` happy
over at Go issue board:

golang/go#32673

Also, preallocate dwarf debug sections that go within the `__DWARF`
segment.
@golang golang locked and limited conversation to collaborators Apr 30, 2021
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.
Projects
None yet
Development

No branches or pull requests

5 participants