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

[MachO] requires dsymutil for DWARF symbols #15439

Closed
motiejus opened this issue Apr 24, 2023 · 3 comments
Closed

[MachO] requires dsymutil for DWARF symbols #15439

motiejus opened this issue Apr 24, 2023 · 3 comments
Labels
linking os-macos upstream An issue with a third party project that Zig uses.

Comments

@motiejus
Copy link
Contributor

motiejus commented Apr 24, 2023

Currently we cannot compile CGo programs to MacOS (at least x86_64) with default settings:

main.go

package main

// #include <stdio.h>
// char* hello() { return "hello, world"; }
// void phello() { printf("%s\n", hello()); }
import "C"

func main() {
        C.phello()
}

func Chello() string {
        return C.GoString(C.hello())
}

Compile to MacOS

$ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="zig cc -target x86_64-macos-none" go build -ldflags=-buildmode=pie .
# example.com/x
/usr/local/go/pkg/tool/linux_amd64/link: /usr/local/go/pkg/tool/linux_amd64/link: running dsymutil failed: exec: "dsymutil": executable file not found in $PATH

We can make it work by adding -w to the linker flags:

$ go tool link -h |& grep -- -w
  -w    disable DWARF generation
$ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="zig cc -target x86_64-macos-none" go build -ldflags="-w -buildmode=pie" .
$ file ./x
./x: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>
@kubkon
Copy link
Member

kubkon commented Jun 4, 2023

This is a GO issue and not Zig's in assuming there is a dsymutil binary in the PATH which generally is not the case on non-native hosts.

@kubkon kubkon added os-macos upstream An issue with a third party project that Zig uses. linking labels Jun 4, 2023
@motiejus
Copy link
Contributor Author

motiejus commented Jun 4, 2023

Oh wow, I was quite sure I saw zig exec'ing that command, not Go. Sorry!

@motiejus motiejus closed this as completed Jun 4, 2023
@kubkon
Copy link
Member

kubkon commented Jun 4, 2023

Oh wow, I was quite sure I saw zig exec'ing that command, not Go. Sorry!

No problem. As a heads up, I want to implement dsymutil's functionality as part of Zig's linker toolchain in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linking os-macos upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

No branches or pull requests

2 participants