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: go test -c on darwin/arm64 produces invalid code signature in combination with cgo #63576

Closed
tsenart opened this issue Oct 16, 2023 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@tsenart
Copy link

tsenart commented Oct 16, 2023

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

$ go version
go version go1.21.3 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
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/tomas/Library/Caches/go-build'
GOENV='/Users/tomas/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/tomas/.local/share/rtx/installs/go/1.21.3/packages/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/tomas/.local/share/rtx/installs/go/1.21.3/packages'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/tomas/.local/share/rtx/installs/go/1.21.3/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/tomas/.local/share/rtx/installs/go/1.21.3/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/tomas/Code/go-test-cgo-fail/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/ls/998j2q9x6n5fjlgrcbrbbnqh0000gn/T/go-build3647025484=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Exact same steps as #43105, but using -c instead, so:

git clone https://github.com/oxisto/go-test-cgo-fail
cd go-test-cgo-fail
go test -c -work pkg/native_test.go
./pkg.test

What did you expect to see?

This works with Go 1.20.3 so I thin the bug was introduced in Go 1.21.0

./pkg.test 
hello
PASS

What did you see instead?

[1]    10186 killed     ./pkg.test
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 16, 2023
@tsenart
Copy link
Author

tsenart commented Oct 16, 2023

Here's the macOS crash report if it's useful:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               pkg.test [10186]
Path:                  /Users/USER/*/pkg.test
Identifier:            pkg.test
Version:               ???
Code Type:             ARM-64 (Native)
Parent Process:        zsh [7042]
Responsible:           kitty [6785]
User ID:               501

Date/Time:             2023-10-16 20:29:18.3757 +0200
OS Version:            macOS 14.0 (23A344)
Report Version:        12
Anonymous UUID:        D83D4DD4-DB7D-8E82-903F-FC1B0B18DE9A

Sleep/Wake UUID:       CFB433B1-6490-476F-B547-60BE63FD26E3

Time Awake Since Boot: 6200 seconds
Time Since Wake:       3436 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGKILL (Code Signature Invalid))
Exception Codes:       UNKNOWN_0x32 at 0x0000000104d6ebd0
Exception Codes:       0x0000000000000032, 0x0000000104d6ebd0

Termination Reason:    Namespace CODESIGNING, Code 2 Invalid Page

VM Region Info: 0x104d6ebd0 is in 0x104d68000-0x104e8c000;  bytes after start: 27600  bytes before end: 1168431
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  __TEXT                      104d68000-104e8c000    [ 1168K] r-x/r-x SM=COW  ...ER/*/pkg.test
      __DATA_CONST                104e8c000-104ec4000    [  224K] r--/rw- SM=COW  ...ER/*/pkg.test

Kernel Triage:
VM - (arg = 0x0) A memory corruption was found in executable text


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   pkg.test                      	       0x104d6ebd0 */bytealg.IndexByteString.abi0 + 0
1   pkg.test                      	       0x104dbd29c runtime.findnull + 124


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x000000016b096e48   x1: 0x00000000000001b8   x2: 0x0000000000000000   x3: 0x000000016b096e48
    x4: 0x0000020000000002   x5: 0x0000000104fb8578   x6: 0x0000000000000000   x7: 0x000000016b0969b0
    x8: 0x000000016a89b978   x9: 0xffffffffffffc000  x10: 0x0000000000800000  x11: 0x0000000000004000
   x12: 0x0000000104e5bd30  x13: 0x000000016b0968f0  x14: 0x0000000000000004  x15: 0x0000000000008000
   x16: 0x000000016a89bd18  x17: 0x00000001ee2010b0  x18: 0x0000000000000000  x19: 0x00000001053f9bd0
   x20: 0x0000000104dd5980  x21: 0x00000001053f9d38  x22: 0x00000001053f9910  x23: 0x000000016b096a70
   x24: 0x000000016b096ab0  x25: 0x000000018da0fb1b  x26: 0x0000000000000000  x27: 0x0000000104f83000
   x28: 0x0000000104f847a0   fp: 0x000000016b0968d8   lr: 0x0000000104dbd29c
    sp: 0x000000016b0968e0   pc: 0x0000000104d6ebd0 cpsr: 0x20001000
   far: 0x0000000104d6ebd0  esr: 0x82000007 (Instruction Abort) Translation fault

Binary Images:
       0x104d68000 -        0x104e8bfff pkg.test (*) <694e69e9-cadb-348f-8551-b591f21d4736> /Users/USER/*/pkg.test
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???
       0x18d98b000 -        0x18da1e873 dyld (*) <ffd8ab66-c9ab-31df-ab80-3a3dff367ddd> /usr/lib/dyld

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 2
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=1.0G resident=0K(0%) swapped_out_or_unallocated=1.0G(100%)
Writable regions: Total=529.6M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=529.6M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Kernel Alloc Once                   32K        1 
MALLOC                           521.2M       11 
MALLOC guard page                   96K        6 
STACK GUARD                       56.0M        1 
Stack                             8176K        1 
__AUTH                             339K       65 
__AUTH_CONST                      4041K      147 
__DATA                            2082K      141 
__DATA_CONST                      4993K      150 
__DATA_DIRTY                       363K       58 
__LINKEDIT                       886.6M        2 
__OBJC_RO                         70.6M        1 
__OBJC_RW                         2153K        1 
__TEXT                           120.8M      156 
dyld private memory                272K        2 
shared memory                       16K        1 
===========                     =======  ======= 
TOTAL                              1.6G      744 



-----------
Full Report
-----------

{"app_name":"pkg.test","timestamp":"2023-10-16 20:29:18.00 +0200","app_version":"","slice_uuid":"694e69e9-cadb-348f-8551-b591f21d4736","build_version":"","platform":1,"share_with_app_devs":0,"is_first_party":1,"bug_type":"309","os_version":"macOS 14.0 (23A344)","roots_installed":0,"incident_id":"18EF39FF-85EB-4254-B42B-2F2C09905AC1","name":"pkg.test"}
{
  "uptime" : 6200,
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro18,2",
  "coalitionID" : 1571,
  "osVersion" : {
    "train" : "macOS 14.0",
    "build" : "23A344",
    "releaseType" : "User"
  },
  "captureTime" : "2023-10-16 20:29:18.3757 +0200",
  "codeSigningMonitor" : 1,
  "incident" : "18EF39FF-85EB-4254-B42B-2F2C09905AC1",
  "pid" : 10186,
  "translated" : false,
  "cpuType" : "ARM-64",
  "roots_installed" : 0,
  "bug_type" : "309",
  "procLaunch" : "2023-10-16 20:29:18.3722 +0200",
  "procStartAbsTime" : 149104653885,
  "procExitAbsTime" : 149104729825,
  "procName" : "pkg.test",
  "procPath" : "\/Users\/USER\/*\/pkg.test",
  "parentProc" : "zsh",
  "parentPid" : 7042,
  "coalitionName" : "net.kovidgoyal.kitty",
  "crashReporterKey" : "D83D4DD4-DB7D-8E82-903F-FC1B0B18DE9A",
  "responsiblePid" : 6785,
  "responsibleProc" : "kitty",
  "codeSigningID" : "pkg.test",
  "codeSigningTeamID" : "",
  "codeSigningFlags" : 587334144,
  "codeSigningValidationCategory" : 0,
  "codeSigningTrustLevel" : 4294967295,
  "instructionByteStream" : {"beforePC":"AAAAAAAAAADgB0D54gtA+eGDQDnoowCRwP\/\/FwAAAAAAAAAAAAAAAA==","atPC":"4AdA+eILQPnhY0A56IMAkbj\/\/xcAAAAAAAAAAAAAAACQC0D5\/2Mw6w=="},
  "wakeTime" : 3436,
  "sleepWakeUUID" : "CFB433B1-6490-476F-B547-60BE63FD26E3",
  "sip" : "enabled",
  "vmRegionInfo" : "0x104d6ebd0 is in 0x104d68000-0x104e8c000;  bytes after start: 27600  bytes before end: 1168431\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  __TEXT                      104d68000-104e8c000    [ 1168K] r-x\/r-x SM=COW  ...ER\/*\/pkg.test\n      __DATA_CONST                104e8c000-104ec4000    [  224K] r--\/rw- SM=COW  ...ER\/*\/pkg.test",
  "exception" : {"codes":"0x0000000000000032, 0x0000000104d6ebd0","rawCodes":[50,4376161232],"type":"EXC_BAD_ACCESS","signal":"SIGKILL (Code Signature Invalid)","subtype":"UNKNOWN_0x32 at 0x0000000104d6ebd0"},
  "termination" : {"flags":0,"code":2,"namespace":"CODESIGNING","indicator":"Invalid Page"},
  "ktriageinfo" : "VM - (arg = 0x0) A memory corruption was found in executable text\n",
  "vmregioninfo" : "0x104d6ebd0 is in 0x104d68000-0x104e8c000;  bytes after start: 27600  bytes before end: 1168431\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  __TEXT                      104d68000-104e8c000    [ 1168K] r-x\/r-x SM=COW  ...ER\/*\/pkg.test\n      __DATA_CONST                104e8c000-104ec4000    [  224K] r--\/rw- SM=COW  ...ER\/*\/pkg.test",
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":2},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 0,
  "threads" : [{"triggered":true,"id":113952,"threadState":{"x":[{"value":6090747464},{"value":440},{"value":0},{"value":6090747464},{"value":2199023255554},{"value":4378559864,"symbolLocation":0,"symbol":"runtime.test_z64"},{"value":0},{"value":6090746288},{"value":6082378104},{"value":18446744073709535232},{"value":8388608},{"value":16384},{"value":4377132336,"symbolLocation":0,"symbol":"x_cgo_init"},{"value":6090746096},{"value":4},{"value":32768},{"value":6082379032},{"value":8290046128},{"value":0},{"value":4383022032},{"value":4376582528,"symbolLocation":0,"symbol":"main"},{"value":4383022392},{"value":4383021328},{"value":6090746480},{"value":6090746544},{"value":6671104795},{"value":0},{"value":4378341376,"symbolLocation":1280,"symbol":"runtime.itabTableInit"},{"value":4378347424,"symbolLocation":0,"symbol":"runtime.g0"}],"flavor":"ARM_THREAD_STATE64","lr":{"value":4376482460},"cpsr":{"value":536875008},"fp":{"value":6090746072},"sp":{"value":6090746080},"esr":{"value":2181038087,"description":"(Instruction Abort) Translation fault"},"pc":{"value":4376161232,"matchesCrashFrame":1},"far":{"value":4376161232}},"queue":"com.apple.main-thread","frames":[{"imageOffset":27600,"symbol":"*\/bytealg.IndexByteString.abi0","symbolLocation":0,"imageIndex":0},{"imageOffset":348828,"symbol":"runtime.findnull","symbolLocation":124,"imageIndex":0}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4376133632,
    "size" : 1196032,
    "uuid" : "694e69e9-cadb-348f-8551-b591f21d4736",
    "path" : "\/Users\/USER\/*\/pkg.test",
    "name" : "pkg.test"
  },
  {
    "size" : 0,
    "source" : "A",
    "base" : 0,
    "uuid" : "00000000-0000-0000-0000-000000000000"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6670561280,
    "size" : 604276,
    "uuid" : "ffd8ab66-c9ab-31df-ab80-3a3dff367ddd",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  }
],
  "sharedCache" : {
  "base" : 6669811712,
  "size" : 4012523520,
  "uuid" : "7906534c-5d2b-3ba8-b9c6-93a5cf1b7b50"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=1.0G resident=0K(0%) swapped_out_or_unallocated=1.0G(100%)\nWritable regions: Total=529.6M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=529.6M(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nKernel Alloc Once                   32K        1 \nMALLOC                           521.2M       11 \nMALLOC guard page                   96K        6 \nSTACK GUARD                       56.0M        1 \nStack                             8176K        1 \n__AUTH                             339K       65 \n__AUTH_CONST                      4041K      147 \n__DATA                            2082K      141 \n__DATA_CONST                      4993K      150 \n__DATA_DIRTY                       363K       58 \n__LINKEDIT                       886.6M        2 \n__OBJC_RO                         70.6M        1 \n__OBJC_RW                         2153K        1 \n__TEXT                           120.8M      156 \ndyld private memory                272K        2 \nshared memory                       16K        1 \n===========                     =======  ======= \nTOTAL                              1.6G      744 \n",
  "legacyInfo" : {
  "threadTriggered" : {
    "queue" : "com.apple.main-thread"
  }
},
  "logWritingSignature" : "197d4b63ea1b5f32782139a96c82cc8aab50b904",
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "639124e81d92412bfb4880b3",
      "factorPackIds" : {

      },
      "deploymentId" : 240000012
    },
    {
      "rolloutId" : "5ffde50ce2aacd000d47a95f",
      "factorPackIds" : {

      },
      "deploymentId" : 240000334
    }
  ],
  "experiments" : [
    {
      "treatmentId" : "6dd670af-0633-45e4-ae5f-122ae4df02be",
      "experimentId" : "64406ba83deb637ac8a04419",
      "deploymentId" : 900000017
    },
    {
      "treatmentId" : "a092db1b-c401-44fa-9c54-518b7d69ca61",
      "experimentId" : "64a844035c85000c0f42398a",
      "deploymentId" : 400000019
    }
  ]
}
}

@tsenart
Copy link
Author

tsenart commented Oct 16, 2023

This seems to be caused by CC and CXX being set to the homebrew installed llvm versions rather than the Apple versions.

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.
Projects
None yet
Development

No branches or pull requests

2 participants