[lld-macho] Handle LOH_ARM64_ADRP_LDR linker optimization hints
authorDaniel Bertalan <dani@danielbertalan.dev>
Thu, 30 Jun 2022 09:01:18 +0000 (11:01 +0200)
committerDaniel Bertalan <dani@danielbertalan.dev>
Fri, 1 Jul 2022 07:44:24 +0000 (09:44 +0200)
commit573c7e6b3c79c7ce80a2221e000fab7dd20c0bb4
tree7833ca3e7897ca9b4577be60f10ba7cb60925dd9
parentb822efc7404bf09ccfdc1ab7657475026966c3b2
[lld-macho] Handle LOH_ARM64_ADRP_LDR linker optimization hints

This linker optimization hint transforms a pair of adrp+ldr (immediate)
instructions into an ldr (literal) load from a PC-relative address if
it is 4-byte aligned and within +/- 1 MiB, as ldr can encode a signed
19-bit offset that gets multiplied by 4.

In the wild, only a small number of these hints are applicable because
not many loads end up close enough to the data segment. However, the
added helper functions will be useful in implementing the rest of the
LOH types.

Differential Revision: https://reviews.llvm.org/D128942
lld/MachO/Arch/ARM64.cpp
lld/test/MachO/loh-adrp-ldr.s [new file with mode: 0644]