[BOLT][AArch64] Handle adrp+ld64 linker relaxations
authorVladislav Khmelevsky <och95@yandex.ru>
Wed, 16 Nov 2022 07:57:35 +0000 (11:57 +0400)
committerVladislav Khmelevsky <och95@yandex.ru>
Thu, 22 Dec 2022 21:20:18 +0000 (01:20 +0400)
commit17ed8f29287b1c0495d25025a28f065c0f53bbc7
treecbb3076c2e9226b25b7ec222fc8d7e2d86b97b29
parent63173d11ecb50236e86578574584bd9a86e27387
[BOLT][AArch64] Handle adrp+ld64 linker relaxations

Linker might relax adrp + ldr got address loading to adrp + add for
local non-preemptible symbols (e.g. hidden/protected symbols in
executable). As usually linker doesn't change relocations properly after
relaxation, so we have to handle such cases by ourselves. To do that
during relocations reading we change LD64 reloc to ADD if instruction
mismatch found and introduce FixRelaxationPass that searches for ADRP+ADD
pairs and after performing some checks we're replacing ADRP target symbol
to already fixed ADDs one.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Differential Revision: https://reviews.llvm.org/D138097
12 files changed:
bolt/include/bolt/Core/MCPlusBuilder.h
bolt/include/bolt/Core/Relocation.h
bolt/include/bolt/Passes/FixRelaxationPass.h [new file with mode: 0644]
bolt/include/bolt/Rewrite/RewriteInstance.h
bolt/lib/Core/Relocation.cpp
bolt/lib/Passes/CMakeLists.txt
bolt/lib/Passes/FixRelaxationPass.cpp [new file with mode: 0644]
bolt/lib/Rewrite/BinaryPassManager.cpp
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
bolt/test/AArch64/Inputs/got-ld64-relaxation.yaml [new file with mode: 0644]
bolt/test/AArch64/got-ld64-relaxation.test [new file with mode: 0644]