[JITLink][AArch64] Use R-X permissions for the GOT.
authorLang Hames <lhames@gmail.com>
Wed, 12 Jan 2022 06:53:13 +0000 (17:53 +1100)
committerLang Hames <lhames@gmail.com>
Wed, 12 Jan 2022 07:03:58 +0000 (18:03 +1100)
commit1f3d4525d87e9cd69c18098449a21ed0199fc459
tree0040b44ec574d6775f73e77de935f59cdbe8d2cf
parentc2ba53518f5459b8e61c44549358065208d62125
[JITLink][AArch64] Use R-X permissions for the GOT.

This consistent with ld64's treatment of the GOT, but the main aim here is a
short-term workaround for a bad interaction between stub code sequences and
memory layout: Stubs use LDRLiteral19 relocations to reference the GOT, but
BasicLayout currently puts RW- segments between R-- and R-X segments -- a large
RW- segment (or a large R-- for that matter) can cause the relocation to fail
with an out-of-range error.

Putting the GOT in R-X fixes this efficiently in practice. A more robust fix
will be to use a longer code sequence to materialize the GOT pointer and then
rewrite the stub to use a shorter sequence where possible.
llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_stub_to_got_distance_stress_test.s [new file with mode: 0644]