Skip to content

net: macOS link of Go c-archive now requires -lresolv in 1.20 #58159

@bradfitz

Description

@bradfitz

Go 1.20rc3.

I tried to convert our application (@tailscale) over to Go 1.20 but hit macOS compilation errors in Xcode for our target (a network extension) that links in Go code:

    /Applications/Xcode-13.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-macos10.13 -isysroot /Applications/Xcode-13.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -L/Users/github-ci/Library/Developer/Xcode/DerivedData/IPN-dcmqhkiofztpxzcjkertpymoivvw/Build/Intermediates.noindex/ArchiveIntermediates/IPN-macOS/BuildProductsPath/Release -F/Users/github-ci/Library/Developer/Xcode/DerivedData/IPN-dcmqhkiofztpxzcjkertpymoivvw/Build/Intermediates.noindex/ArchiveIntermediates/IPN-macOS/BuildProductsPath/Release -filelist /Users/github-ci/Library/Developer/Xcode/DerivedData/IPN-dcmqhkiofztpxzcjkertpymoivvw/Build/Intermediates.noindex/ArchiveIntermediates/IPN-macOS/IntermediateBuildFilesPath/IPN.build/Release/IPNExtension-macOS.build/Objects-normal/arm64/IPNExtension.LinkFileList -exported_symbols_list IPNExtension/exported-symbols.exp -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker @executable_path/../Frameworks -Xlinker -rpath -Xlinker @executable_path/../../../../Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/github-ci/Library/Developer/Xcode/DerivedData/IPN-dcmqhkiofztpxzcjkertpymoivvw/Build/Intermediates.noindex/ArchiveIntermediates/IPN-macOS/IntermediateBuildFilesPath/IPN.build/Release/IPNExtension-macOS.build/Objects-normal/arm64/IPNExtension_lto.o -fapplication-extension -fobjc-link-runtime -L/Applications/Xcode-13.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/github-ci/Library/Developer/Xcode/DerivedData/IPN-dcmqhkiofztpxzcjkertpymoivvw/Build/Intermediates.noindex/ArchiveIntermediates/IPN-macOS/IntermediateBuildFilesPath/IPN.build/Release/IPNExtension-macOS.build/Objects-normal/arm64/IPNExtension.swiftmodule -e _NSExtensionMain -lipn-go-arm64\ x86_64 -framework NetworkExtension -Xlinker -dependency_info -Xlinker /Users/github-ci/Library/Developer/Xcode/DerivedData/IPN-dcmqhkiofztpxzcjkertpymoivvw/Build/Intermediates.noindex/ArchiveIntermediates/IPN-macOS/IntermediateBuildFilesPath/IPN.build/Release/IPNExtension-macOS.build/Objects-normal/arm64/IPNExtension_dependency_info.dat -o /Users/github-ci/Library/Developer/Xcode/DerivedData/IPN-dcmqhkiofztpxzcjkertpymoivvw/Build/Intermediates.noindex/ArchiveIntermediates/IPN-macOS/IntermediateBuildFilesPath/IPN.build/Release/IPNExtension-macOS.build/Objects-normal/arm64/Binary/IPNExtension
Undefined symbols for architecture arm64:
  "_res_9_nsearch", referenced from:
      _internal/syscall/unix.libresolv_res_9_nsearch_trampoline.abi0 in libipn-go-arm64 x86_64.a(go.o)
  "_res_9_nclose", referenced from:
      _internal/syscall/unix.libresolv_res_9_nclose_trampoline.abi0 in libipn-go-arm64 x86_64.a(go.o)
  "_res_9_ninit", referenced from:
      _internal/syscall/unix.libresolv_res_9_ninit_trampoline.abi0 in libipn-go-arm64 x86_64.a(go.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

...

The following build commands failed:
	Ld /Users/github-ci/Library/Developer/Xcode/DerivedData/IPN-dcmqhkiofztpxzcjkertpymoivvw/Build/Intermediates.noindex/ArchiveIntermediates/IPN-macOS/IntermediateBuildFilesPath/IPN.build/Release/IPNExtension-macOS.build/Objects-normal/arm64/Binary/IPNExtension normal arm64 (in target 'IPNExtension-macOS' from project 'IPN')

I assume this is fallout from https://tip.golang.org/doc/go1.20#cgo ...

On macOS, the net and os/user packages have been rewritten not to use cgo: the same code is now used for cgo and non-cgo builds as well as cross-compiled builds.

Unfortunately I don't have a small easy repro. (Nothing is small or easy with Xcode)

/cc @rsc @ianlancetaylor

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-DarwinWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions