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/link: combining dwarf failed: Unknown load command 0x80000018 (2147483672) #32233

Closed
triztian opened this issue May 24, 2019 · 8 comments
Closed

Comments

@triztian
Copy link

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

$ go version
go1.12.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
λ dwarfunk ~> go env
GOARCH="amd64"
GOBIN="/Users/Tristian/go/bin"
GOCACHE="/Users/Tristian/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Tristian/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/Tristian/Repositories/github.com/triztian/dwarfunk/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/7s/cnfg6ksj44gb3br_lc4v3gn40000gp/T/go-build997778752=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Tried to install the main package

What did you expect to see?

A successful linking and executable for the macOS platform.

What did you see instead?

The following error:

go install Output
# github.com/triztian/dwarfunk
/usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64/link: /usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64/link: combining dwarf failed: Unknown load command 0x80000018 (2147483672)

Notes

I've created the following repo to reproduce the issue:

The subpackage github.com/triztian/dwarfunk/lib contains an objective-c file and successfully builds using the go build command:

go build ./lib

I've noticed that if I edit the objc.m file and remove the following line, then the go install command works.

Looking at the following CL, it seems like the command is not part of the list:

Could it be that the the command has to be added and OR ed as depicted in the ruby-macho library?

@thanm thanm self-assigned this May 24, 2019
@thanm
Copy link
Contributor

thanm commented May 24, 2019

Problem appears to be here I think. Looks like the constant defined for LC_LOAD_WEAK_DYLIB is incorrect. I will send a patch.

@triztian
Copy link
Author

Awesome, thank you for the quick response, it probably has to be more like 0x80000018

@gopherbot
Copy link

Change https://golang.org/cl/178723 mentions this issue: cmd/link: fix incorrect constant for macho-o load command

@gopherbot
Copy link

Change https://golang.org/cl/178726 mentions this issue: cmd/link: new test case for Darwin/DWARF

gopherbot pushed a commit that referenced this issue May 30, 2019
Test case for issue 32233.

Updates #32233.

Change-Id: I0e3b4a46832f39de4ef36d8fd8c6070bf9b1a019
Reviewed-on: https://go-review.googlesource.com/c/go/+/178726
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@thanm
Copy link
Contributor

thanm commented May 31, 2019

Hi @triztian

I've made an attempt to adapt your reproducer as a testcase -- see https://golang.org/cl/178726. My first attempt is problematic in that I it contains code that doesn't work with older versions of MacOS, e.g. 10.11, since it refers to the UserNotifications framework.

I can add guards via #ifdef to insure that those constructs are conditionally compiled based on the OS version, e.g.

#import <Foundation/Foundation.h>
#if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__>101300)
#import <UserNotifications/UserNotifications.h>
#endif

however I can't use the same trick with the cgo directives. Something like

#if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__>101300)
#cgo darwin LDFLAGS: -framework Foundation -framework UserNotifications
#endif

doesn't have the desired effect, since cgo doesn't run the C preprocessor.

A question for you: is it possible to reproduce the same DWARF issue without using the newer framework (e.g. just using something from the Foundation framework)?

Thanks, Than

@gopherbot
Copy link

Change https://golang.org/cl/179837 mentions this issue: cmd/link: revise test case to work on pre-10.14 macos

@thanm
Copy link
Contributor

thanm commented May 31, 2019

OK, I think I have a revised testcase that works.

@triztian
Copy link
Author

triztian commented May 31, 2019

@thanm I stumbled into the issue randomly because I was trying to use the UserNotifications framework from Go.

I don't have an alternative way to reproduce that issue. I could look into how we can get the compiler to produce a binary that specifically uses that MACH-O command.

Ah, from looking at the revised test case, did you try different frameworks randomly?, curious about it.

Thank you for looking into this issue!

gopherbot pushed a commit that referenced this issue May 31, 2019
Rework this recently introduced test case to insure that it works with
older versions of the OS. It was using a new framework library not
available on pre-10.14 to trigger the weak symbol reference; switch to
using a new symbol from an existing library. Tested on MacOS 10.14 and
10.11.

Updates #32233.

Change-Id: I1fe2a9255fca46cb7cdf33ff7fed67bba86fdc22
Reviewed-on: https://go-review.googlesource.com/c/go/+/179837
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
@golang golang locked and limited conversation to collaborators May 30, 2020
@rsc rsc unassigned thanm Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants