]> Cypherpunks repositories - gostls13.git/commit
cmd/link: handle dynamic import variables on Darwin
authorCherry Mui <cherryyz@google.com>
Thu, 8 Jun 2023 16:19:54 +0000 (12:19 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 20 Jul 2023 19:39:32 +0000 (19:39 +0000)
commitac81156bce3ff4bfdcf983cf21acb6830a450a4b
tree2ea28191bd8b8f0311785496800a0efde2384b6f
parent3ffc8a25569ed107ebc1786bbd4f993dd6689601
cmd/link: handle dynamic import variables on Darwin

Currently, on darwin, we only support cgo_dynamic_import for
functions, but not variables, as we don't need it before.
mach_task_self_ is a variable defined in the system library, which
can be used to e.g. access the process's memory mappings via the
mach API. The C header defines a macro mach_task_self(), which
refers to the variable. To use mach_task_self_ (in pure-Go
programs) we need to access it in Go.

This CL handles cgo_dynamic_import for variables in the linker,
loading its address via the GOT. (Currently only on Darwin, as
we only need it there.)

For #50891.

Change-Id: Idf64fa88ba2f2381443a1ed0b42b14b581843493
Reviewed-on: https://go-review.googlesource.com/c/go/+/501855
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/arm64/asm.go
src/cmd/link/link_test.go
src/cmd/link/testdata/dynimportvar/asm/a.go [new file with mode: 0644]
src/cmd/link/testdata/dynimportvar/asm/a_amd64.s [new file with mode: 0644]
src/cmd/link/testdata/dynimportvar/asm/a_arm64.s [new file with mode: 0644]
src/cmd/link/testdata/dynimportvar/main.go [new file with mode: 0644]