[mac/lld] Fix scale computation for vector ops in PAGEOFF12 relocations
authorNico Weber <thakis@chromium.org>
Fri, 5 Mar 2021 16:17:08 +0000 (11:17 -0500)
committerNico Weber <thakis@chromium.org>
Fri, 5 Mar 2021 17:24:37 +0000 (12:24 -0500)
commit210cc0738bbeecf97c9698e2bbe54bbb7d520387
treeba3974a5f212d57c60f40605e002b3fc376ac0fb
parent2ec43e416734bdead6bfeeaf5ab54c479b6f444e
[mac/lld] Fix scale computation for vector ops in PAGEOFF12 relocations

With this, llvm-tblgen no longer tries and fails to allocate 7953 petabyte
when it runs during the build. Instead, `check-llvm` with lld/mac as host
linker now completes without any failures on an m1 mac.

This vector op handling code matches what happens in:
- ld64's OutputFile::applyFixUps() in OutputFile.cpp for kindStoreARM64PageOff12
- lld.ld64.darwinold's offset12KindFromInstruction() in
  lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp for offset12scale16
- RuntimeDyld's decodeAddend() in
  llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h for
  ARM64_RELOC_PAGEOFF12

Fixes PR49444.

Differential Revision: https://reviews.llvm.org/D98053
lld/MachO/Arch/ARM64.cpp
lld/test/MachO/arm64-relocs.s