go: cmd/link: cgo generates incorrect symbols on macOS 13 beta 5
What version of Go are you using (go version
)?
% go version go version go1.19 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 GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/kevin/Library/Caches/go-build" GOENV="/Users/kevin/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/kevin/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/kevin/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.19" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9s/xwtpw2qs21163sxc3_s54_cw0000gn/T/go-build1102081114=/tmp/go-build -gno-record-gcc-switches -fno-common"
% sw_vers ProductName: macOS ProductVersion: 13.0 BuildVersion: 22A5321d
What did you do?
cpoc.go
package main
// #include "cpoc.h"
import "C"
import (
"fmt"
)
//export goLogger
func goLogger() {
fmt.Println("goLogger")
}
func main() {
C.cLogger()
}
cpoc.c
#include "cpoc.h"
void cLogger(void)
{
printf("cLogger\n");
goLogger();
}
cpoc.h
#include <stdlib.h>
#include <stdio.h>
extern void goLogger(void);
void cLogger(void);
What did you expect to see?
Correctly compiled cgo binary.
What did you see instead?
% go run cpoc.go
# command-line-arguments
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: -no_pie is deprecated when targeting new OS versions
ld: warning: non-standard -pagezero_size is deprecated when targeting macOS 13.0 or later
Undefined symbols for architecture x86_64:
"_cLogger", referenced from:
__cgo_267e1da4216b_Cfunc_cLogger in 000001.o
(maybe you meant: __cgo_267e1da4216b_Cfunc_cLogger)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I’m guessing this is due to the beta-ness of the OS. Happy to provide more debug info to get this working.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 32 (9 by maintainers)
Commits related to this issue
- cmd/link: stop passing -pagezero_size to darwin linker We added -pagezero_size in CL 72730, where it was intented for iOS. The current code passes it only on macOS/AMD64 instead. It is not really nec... — committed to golang/go by cherrymui 2 years ago
- cmd/link: suppress -no_pie deprecation warning on darwin Apparently the new darwin linker starts to emit a warning about -no_pie deprecation. Maybe we want to switch to PIE by default. For now, suppr... — committed to golang/go by cherrymui 2 years ago
- [release-branch.go1.18] cmd/link: stop passing -pagezero_size to darwin linker We added -pagezero_size in CL 72730, where it was intented for iOS. The current code passes it only on macOS/AMD64 inste... — committed to golang/go by cherrymui 2 years ago
- [release-branch.go1.19] cmd/link: stop passing -pagezero_size to darwin linker We added -pagezero_size in CL 72730, where it was intented for iOS. The current code passes it only on macOS/AMD64 inste... — committed to golang/go by cherrymui 2 years ago
- [release-branch.go1.19] cmd/link: suppress -no_pie deprecation warning on darwin Apparently the new darwin linker starts to emit a warning about -no_pie deprecation. Maybe we want to switch to PIE by... — committed to golang/go by cherrymui 2 years ago
- [release-branch.go1.18] cmd/link: suppress -no_pie deprecation warning on darwin Apparently the new darwin linker starts to emit a warning about -no_pie deprecation. Maybe we want to switch to PIE by... — committed to golang/go by cherrymui 2 years ago
- [release-branch.go1.19] cmd/link: stop passing -pagezero_size to darwin linker We added -pagezero_size in CL 72730, where it was intented for iOS. The current code passes it only on macOS/AMD64 inste... — committed to tailscale/go by cherrymui 2 years ago
- [release-branch.go1.19] cmd/link: suppress -no_pie deprecation warning on darwin Apparently the new darwin linker starts to emit a warning about -no_pie deprecation. Maybe we want to switch to PIE by... — committed to tailscale/go by cherrymui 2 years ago
- [release-branch.go1.19] cmd/link: stop passing -pagezero_size to darwin linker We added -pagezero_size in CL 72730, where it was intented for iOS. The current code passes it only on macOS/AMD64 inste... — committed to tailscale/go by cherrymui 2 years ago
- [release-branch.go1.19] cmd/link: suppress -no_pie deprecation warning on darwin Apparently the new darwin linker starts to emit a warning about -no_pie deprecation. Maybe we want to switch to PIE by... — committed to tailscale/go by cherrymui 2 years ago
- [release-branch.go1.19] cmd/link: stop passing -pagezero_size to darwin linker We added -pagezero_size in CL 72730, where it was intented for iOS. The current code passes it only on macOS/AMD64 inste... — committed to tailscale/go by cherrymui 2 years ago
- [release-branch.go1.19] cmd/link: suppress -no_pie deprecation warning on darwin Apparently the new darwin linker starts to emit a warning about -no_pie deprecation. Maybe we want to switch to PIE by... — committed to tailscale/go by cherrymui 2 years ago
- cmd/go: default to PIE linking on darwin/amd64 The recent version of darwin linker ld64 emits an warning about deprecation of the -no_pie flag. Further, the new darwin linker ld-prime ignores -no_pie... — committed to golang/go by cherrymui 2 years ago
There are a few options:
-buildmode=pie
flag togo build
andgo test
for a workaroundHi! Thanks for the reply.
I was referring to
ld: warning: -no_pie is deprecated when targeting new OS versions
. The warning also causes go tests to fail when run via Intellij/GoLand as @ping-localhost also mentioned.I don’t know if this can help, however, after upgrading to MacOs Monterrey 12.6 I started getting the warning message
ld: warning: -no_pie is deprecated when targeting new OS versions
In itself this shouldn’t be a problem, when I run a test for a single file it shows the warning but runs the tests normally, just as I would expect.
However, when I try to run all the tests of the application, the warning message is taken as an error, the command used is the following:
/usr/local/go/bin/go test -json -race ./...
And the result obtained is:
I am running into the same issue, with the addition that it causes GoLand to fail my tests.
With the two CLs above submitted it should no longer emit the warnings. I’ll work on backport the fix to 1.18 and 1.19 releases. Thanks.
@krohmag When I run the tests from the terminal I get the following:
Same warning message as in IDE, and no evidence of test execution either.
@MitchStephan thanks! Yeah, although it is just a warning we still want to address it. It is also affects tests in the Go distribution.
Same problem after installing mac updates today 😦
@kevmo314 could you try updating Xcode? Also run
go clean -cache
to make sure we start from a clean state. If you still see the errors, could you provide the C compiler and linker version (clang -v
,ld- v
) (after update)?Tengo el mismo problema, mis configuraciones son las siguientes:
MacOs version 12.6
go version
go version go1.18 darwin/amd64
ld -v
@(#)PROGRAM:ld PROJECT:ld64-819.6 BUILD 14:58:37 Aug 5 2022 configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em LTO support using: LLVM version 14.0.0, (clang-1400.0.29.102) (static support for 29, runtime is 29) TAPI support using: Apple TAPI version 14.0.0 (tapi-1400.0.11)
Mensaje de error obtenido:
/usr/local/go/bin/go test -json -race ./...
ld: warning: -no_pie is deprecated when targeting new OS versions
I’m having this issue too. Seems like it started happening after installing XCode 14.
MacOS 12.5 (21G72)