]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.17] cmd/link: don't use label symbol for absolute address relocat...
authorCherry Mui <cherryyz@google.com>
Tue, 2 Nov 2021 22:30:08 +0000 (18:30 -0400)
committerCarlos Amedee <carlos@golang.org>
Wed, 10 Nov 2021 19:35:55 +0000 (19:35 +0000)
commitb954f58e9db73853b05839363b3fbe4d1d0d8f54
treedad41167ce67e9a69b9bfaecaf06bb3ecdf80f73
parentf1935e2c4385b14f0da052b52da15fa89fa2efd9
[release-branch.go1.17] cmd/link: don't use label symbol for absolute address relocations on ARM64 PE

On ARM64 PE, when external linking, the PE relocation does not
have an explicit addend, and instead has the addend encoded in
the instruction or data. An instruction (e.g. ADRP, ADD) has
limited width for the addend, so when the addend is large we use
a label symbol, which points to the middle of the original target
symbol, and a smaller addend. But for an absolute address
relocation in the data section, we have the full width to encode
the addend and we should not use the label symbol. Also, since we
do not adjust the addend in the data, using the label symbol will
actually make it point to the wrong address. E.g for an R_ADDR
relocation targeting x+0x123456, we should emit 0x123456 in the
data with an IMAGE_REL_ARM64_ADDR64 relocation pointing to x,
whereas the current code emits  0x123456 in the data with an
IMAGE_REL_ARM64_ADDR64 relocation pointing to the label symbol
x+1MB, so it will actually be resolved to x+0x223456. This CL
fixes this.

Fixes #49479

Change-Id: I64e02b56f1d792f8c20ca61b78623ef5c3e34d7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/360895
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
(cherry picked from commit 988efd58197205060ace508d29984fbab6eb3840)
Reviewed-on: https://go-review.googlesource.com/c/go/+/363014
Run-TryBot: Carlos Amedee <carlos@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/link/internal/arm64/asm.go
src/cmd/link/link_test.go