Repository: go
Issue: cmd: support mapping symbols for ARM64
Labels: NeedsDecision,FeatureRequest,arch-arm64

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version devel go1.18-8b471db71b Wed Aug 18 08:26:44 2021 +0000 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE="off"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/slava/Library/Caches/go-build"
GOENV="/Users/slava/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/slava/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/Users/slava/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/slava/dev/mygo/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/slava/dev/mygo/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-8b471db71b Wed Aug 18 08:26:44 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="/usr/bin/clang"
CXX="/usr/bin/clang++"
CGO_ENABLED="0"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ld/pkx3km8x53qc7qb6wwwvxcr80000gn/T/go-build3739783046=/tmp/go-build -gno-record-gcc-switches"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->
<pre>
$ go build
</pre>

### What did you expect to see?
The special mapping symbols appear in the symbol table.
Readlef:
<pre>
67: 0000000000018dc4     0 NOTYPE  LOCAL  DEFAULT    1 $d
68: 0000000000018df0     0 NOTYPE  LOCAL  DEFAULT    1 $x
</pre>
Objdump:
<pre>
   18db4:	f94007e0 	ldr	x0, [sp, #8]
   18db8:	f9400be1 	ldr	x1, [sp, #16]
   18dbc:	17fffe99 	b	18820 <runtime.(*mheap).sysAlloc>
   18dc0:	14000000 	b	18dc0 <runtime.(*mheap).sysAlloc+0x5a0>
   18dc4:	00010198 	.inst	0x00010198 ; undefined
   18dc8:	000101f8 	.inst	0x000101f8 ; undefined
   18dcc:	000101f0 	.inst	0x000101f0 ; undefined
   18dd0:	000101e8 	.inst	0x000101e8 ; undefined
   18dd4:	000101c0 	.inst	0x000101c0 ; undefined
   18dd8:	000169e8 	.inst	0x000169e8 ; undefined
   18ddc:	000169b8 	.inst	0x000169b8 ; undefined
   18de0:	000169d0 	.inst	0x000169d0 ; undefined
   18de4:	d503201f 	nop
   18de8:	d503201f 	nop
   18dec:	d503201f 	nop

0000000000018df0 runtime.sysReserveAligned:
   18df0:	f9400b90 	ldr	x16, [x28, #16]
   18df4:	910003f1 	mov	x17, sp
   18df8:	eb10023f 	cmp	x17, x16
</pre>


### What did you see instead?
The lack of $x and $d arm mapping symbols inside the symbol table and a regular zeroed padding
Objfump:
<pre>
   18db4:	f94007e0 	ldr	x0, [sp, #8]
   18db8:	f9400be1 	ldr	x1, [sp, #16]
   18dbc:	17fffe99 	b	18820 <runtime.(*mheap).sysAlloc>
   18dc0:	14000000 	b	18dc0 <runtime.(*mheap).sysAlloc+0x5a0>
   18dc4:	00010198 	.inst	0x00010198 ; undefined
   18dc8:	000101f8 	.inst	0x000101f8 ; undefined
   18dcc:	000101f0 	.inst	0x000101f0 ; undefined
   18dd0:	000101e8 	.inst	0x000101e8 ; undefined
   18dd4:	000101c0 	.inst	0x000101c0 ; undefined
   18dd8:	000169e8 	.inst	0x000169e8 ; undefined
   18ddc:	000169b8 	.inst	0x000169b8 ; undefined
   18de0:	000169d0 	.inst	0x000169d0 ; undefined
	...

0000000000018df0 runtime.sysReserveAligned:
   18df0:	f9400b90 	ldr	x16, [x28, #16]
   18df4:	910003f1 	mov	x17, sp
   18df8:	eb10023f 	cmp	x17, x16
</pre>

[ELF for the Arm® 64-bit Architecture (AArch64): Mapping symbols chapter](https://github.com/ARM-software/abi-aa/blob/2020q4/aaelf64/aaelf64.rst#mapping-symbols)
requires that the special symbols are inserted into object files:
$x - At the start of a region of code containing AArch64 instructions.
$d - At the start of a region of data.

I propose to add this functionality since it's a part of a standard and already supported by other languages.

Also I think it's reasonable to use NOPs for function aligning instead of zeroing. There was no purpose of doing it before, but now this's needed to not generate $x and $d for every function and place them just in transitions. In other words, this is an optimization that minimizes the amount of mapping symbols inside the symbol table.