[PR] AArch64: Fix ADR instruction handling
authorVladislav Khmelevsky <vladislav.khmelevskyi@huawei.com>
Fri, 20 Aug 2021 00:07:01 +0000 (03:07 +0300)
committerMaksim Panchenko <maks@fb.com>
Fri, 20 Aug 2021 00:07:01 +0000 (03:07 +0300)
commitc040431fe6d5e49f5c090f0e14c74888380d3c9e
tree6d7a7e12bf3cc56b08a7bb68382ab4c5b605729c
parenta1036e42dab5b7556d797049eef9cefb4dbc3da4
[PR] AArch64: Fix ADR instruction handling

Summary:
There are 2 problems found when handling ADR instruction:
1. When extracting value from the ADR instruction we need to do
it another way, then we do it for ADRP instruction.
2. When creating target expression the VariantKind should be other for
ADR instruction.

And we introduces R_AARCH64_ADR_PREL_LO21,
R_AARCH64_TLSDESC_ADR_PREL21 and R_AARCH64_ADR_PREL_PG_HI21_NC
relocations support.

Also this patch introduces AdrPass, which will replace non-local
pointing ADR instructions with ADRP + ADD instructions sequence due to
small offset range of ADR instruction, so after BOLT magic there are no
guarantees that ADR instruction will still be in the range of
just +- 1MB from its target. The instruction replacement needs
relocations to be avalailable, so we won't remove "IsFromCode"
relocations after disassembly from BF anymore. Also we need original
offset of ADR instruction to be available so we add offset annotation
for these instructions.

The last thing this patch adds is ARM testing directory, which will be
used only on ARM testing servers. The common tests (non-assembler tests
which are platform-independent) might be moved from the X86 directory to
the parent one in the future, so such tests could be tested on both X86
and ARM machines.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

(cherry picked from FBD30497379)
13 files changed:
bolt/src/BinaryFunction.cpp
bolt/src/BinaryFunction.h
bolt/src/BinaryPassManager.cpp
bolt/src/MCPlusBuilder.h
bolt/src/Passes/ADRRelaxationPass.cpp [new file with mode: 0644]
bolt/src/Passes/ADRRelaxationPass.h [new file with mode: 0644]
bolt/src/Passes/CMakeLists.txt
bolt/src/Relocation.cpp
bolt/src/RewriteInstance.cpp
bolt/src/Target/AArch64/AArch64MCPlusBuilder.cpp
bolt/test/AArch64/adrrelaxationpass.s [new file with mode: 0644]
bolt/test/AArch64/lit.local.cfg [new file with mode: 0644]
bolt/test/X86/lit.local.cfg [new file with mode: 0644]