]> Cypherpunks repositories - gostls13.git/commit
cmd/link: generate relative relocs for PIE
authorMichael Pratt <mpratt@google.com>
Fri, 6 Dec 2019 22:25:51 +0000 (17:25 -0500)
committerCherry Zhang <cherryyz@google.com>
Fri, 21 Feb 2020 20:28:45 +0000 (20:28 +0000)
commit675a2e70780208dce18a0bc4b3e420de71fe0178
tree8c8449366e40737092c48c3a4c43465b51f59e4d
parent13d73b2a8a4c84be5c4c9425db91521a44390321
cmd/link: generate relative relocs for PIE

Go's PIE binaries have tons of relocations, all R_X86_64_64 [1] when
internally linked. R_X86_64_64 relocations require symbol lookup in the
dynamic linker, which can be quite slow. The simple Go HTTP server
in #36028 takes over 1s to complete dynamic linking!

The external linker generates R_X86_64_RELATIVE [2] relocations, which
are significantly more efficient. It turns out that generating these
relocations internally is quite simple, so lets do it.

Rather than referencing targ.Dynid in r_info and having the dynamic
linker do a symbol lookup and then add (final targ address) + r.Add, use
AddAddrPlus to generate another R_ADDR to have the linker compute (targ
address + r.Add). The dynamic linker is then only left with base address
+ r_addend.

Since we don't reference the symbol in the final relocation, Adddynsym
is no longer necessary, saving ~1MB (of ~9MB) from the binary size of
the example in #36028.

[1] R_AARCH64_ABS64 on arm64.
[2] R_AARCH64_RELATIVE on arm64.

Fixes #36028

Change-Id: Ie0f4bb1d911f2e05ab46a0a0454c0f46ac01b43b
Reviewed-on: https://go-review.googlesource.com/c/go/+/210181
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/arm64/asm.go