Repository: go
Issue: runtime: immediate lock-up when using go library in Unity 6
Labels: help wanted,NeedsInvestigation,compiler/runtime

### Go version

go1.21.1 darwin/arm64 (we have observed identical behaviour when using go 1.23.1 and 1.23.4)

### Output of `go env` in your module/workspace:

```shell
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='Library/Caches/go-build'
GOENV='Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='temp/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/$HOME/temp/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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/f8/0nlswm8x445_jl3720jx6kmw0000gn/T/go-build2270444360=/tmp/go-build -gno-record-gcc-switches -fno-common'
```


### What did you do?

When running on Apple Silicon hardware:

Prerequisites:
1. Extract plugin code: [TestPlugin.zip](https://github.com/user-attachments/files/18062718/TestPlugin.zip)
2. Extract Unity `2022.3.43f1` repro project: [Unity2022ReproProject.zip](https://github.com/user-attachments/files/18062637/Unity2022ReproProject.zip). Do not open the project yet.
3. Extract Unity `6000.0.28f1` repro project: [Unity6ReproProject.zip](https://github.com/user-attachments/files/18062283/Unity6ReproProject.zip). Do not open the project yet.
4. Install [dylibbundler](https://github.com/auriamg/macdylibbundler) required for dylib signing (`brew install dylibbundler`)
5. Build attached TestPlugin go lib as `.dylib` on MacOS (using cgo). You can use the included magefile.
6. Copy `build/TestPlugin.dylib` to the extracted Unity 2022 project in `Assets/Plugins/TestPlugin.dylib`.
7. Copy the same `build/TestPlugin.dylib` to the extracted Unity 6 project in `Assets/Plugins/TestPlugin.dylib`.


### What did you see happen?

### In Unity 2022

Unity 2022 (and also other versions like Unity 2021 and Unity 2023) is working as expected.

Open the Unity 2022 project, open the `Scenes/SampleScene` and click the Play button. Observe that the Unity Console shows:

```
Calling HelloWorld on plugin...
Successfully called HelloWorld on plugin...
```

If you open `~/Library/Logging/Unity/Editor.log` it will show:

```
Calling HelloWorld on plugin...
UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:37)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
MacOSPluginLoader:Start () (at Assets/Scripts/MacOSPluginLoader.cs:17)

(Filename: Assets/Scripts/MacOSPluginLoader.cs Line: 17)

Hello from Go!
Hello from Go 2!
Hello from Go 3!
Successfully called HelloWorld on plugin...
UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:37)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
MacOSPluginLoader:Start () (at Assets/Scripts/MacOSPluginLoader.cs:19)
```

### In Unity 6

Unity 6 is immediately locking up (showing a beachball spinner) as soon as any go API is called.

Open the Unity 6 project, open the `Scenes/SampleScene` and click the Play button. Observe that the Unity Console shows:

```
Calling HelloWorld on plugin...
```

If you open `~/Library/Logging/Unity/Editor.log` it will show:

```
Calling HelloWorld on plugin...
UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:37)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
MacOSPluginLoader:Start () (at Assets/Scripts/MacOSPluginLoader.cs:17)
```


### What did you expect to see?

Unity 2022 and Unity 6 to behave the same. Instead, Unity 2022 is behaving as expected wheras Unity 6 immediately locks-up the Unity Editor.