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: undefined symbols for architecture arm64 _darwin_arm_init_mach_exception_handler #62432

Closed
khanakia opened this issue Sep 3, 2023 · 7 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin

Comments

@khanakia
Copy link

khanakia commented Sep 3, 2023

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

go version go1.21.0 darwin/arm64

Does this issue reproduce with the latest release?

Yes

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

go env Output
➜  aa git:(main) go env    
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/demo/Library/Caches/go-build'
GOENV='/Users/demo/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/demo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/demo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/demo/Downloads/aa/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/qk/jzsg52995wn53dv8bw62dl1w0000gn/T/go-build3833455105=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

You can test this repo: https://github.com/khanakia/cobratest/tree/main#readme
or create a new file main.go like below

package main

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"
)

func main() {
	Execute()
}

var rootCmd = &cobra.Command{
	Use:   "hugo",
	Short: "Hugo1111is a very fast static site generator",
	Long: `A Fast and Flexible Static Site Generator built with
                love by spf13 and friends in Go.
                Complete documentation is available at http://hugo.spf13.com`,
	Run: func(cmd *cobra.Command, args []string) {
		// Do Stuff Here
	},
}

func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

What did you expect to see?

It should compile go build .

What did you see instead?

➜  aa git:(main) go build .        
# github.com/khanakia/cobratest
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
Undefined symbols for architecture arm64:
  "_darwin_arm_init_mach_exception_handler", referenced from:
      _x_cgo_init in 000005.o
  "_darwin_arm_init_thread_exception_port", referenced from:
      _threadentry in 000005.o
      _x_cgo_init in 000005.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@seankhliao
Copy link
Member

is your xcode / clang version up to date?

@khanakia
Copy link
Author

khanakia commented Sep 3, 2023

Yes

Anyway, i just checked i have created a new user and then i am able to build it. So it seems a user-specific issue on macros. I believe i will use the new user then.

Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@seankhliao
Copy link
Member

what if you clear the build cache?

@khanakia
Copy link
Author

khanakia commented Sep 3, 2023

tried already I will continue to debug to see if i can fix the issue

@seankhliao seankhliao changed the title go build: Undefined symbols for architecture arm64 _darwin_arm_init_mach_exception_handler cmd/link: undefined symbols for architecture arm64 _darwin_arm_init_mach_exception_handler Sep 3, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 3, 2023
@seankhliao seankhliao added OS-Darwin NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 3, 2023
@khanakia khanakia closed this as completed Sep 3, 2023
@khanakia
Copy link
Author

khanakia commented Sep 3, 2023

somehow going was Conflicting with the Xcode command line tools so i tried deleting the /Users/Luci/Library and renaming the Xcode.app and then restarting the PC Somehow it did reset the whole user account and go build started working.

@khanakia
Copy link
Author

Today i upgraded the MAC OS to Sonoma thus it upgraded XCode also.

Now i started getting the same error however if I log in as a different user then the build works.

mkdir -p $WORK/b001/exe/
cd .
/usr/local/go/pkg/tool/darwin_arm64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -buildmode=pie -buildid=IrOa0mMCbcmFG6SCKVtB/7ES0leaDxe0EO7LAN4Yx/6rZQn20_SSYLy8rIB6jF/IrOa0mMCbcmFG6SCKVtB -extld=clang /Users/test/Library/Caches/go-build/90/90f7e2ac98c79ec15a023732fb39c028d6b32f47795ac3e1c15eb63cd89d151e-d
# github.com/aa
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: Undefined symbols:
  _darwin_arm_init_mach_exception_handler, referenced from:
      _x_cgo_init in 000005.o
  _darwin_arm_init_thread_exception_port, referenced from:
      _threadentry in 000005.o
      _x_cgo_init in 000005.o
clang: error: linker command failed with exit

@khanakia
Copy link
Author

Solved it again.

Steps:

  • Go to ~/Library/Developer and rename it to Developer11
  • Go to ~/Library/Caches and delete all
  • Restart the machine
  • After restart Run go cache -clean and go build .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Projects
None yet
Development

No branches or pull requests

3 participants