Skip to content

[MachO] requires dsymutil for DWARF symbols #15439

@motiejus

Description

@motiejus

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    linkingos-macosmacOSupstreamAn issue with a third party project that Zig uses.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions