[BOLT] Fix handling of code references from unmodified code
authorMaksim Panchenko <maks@fb.com>
Wed, 7 Jun 2023 01:25:46 +0000 (18:25 -0700)
committerMaksim Panchenko <maks@fb.com>
Mon, 12 Jun 2023 17:46:51 +0000 (10:46 -0700)
commit43f56a2f27e565af6983b86e748e49935675e9db
treec84a81711d2b21518c805f26d0379bf569b5ec41
parent85f1726c1b7dc53f3a71c74601614fa4a0bfa8cd
[BOLT] Fix handling of code references from unmodified code

In lite mode (default for X86), BOLT optimizes and relocates functions
with profile. The rest of the code is preserved, but if it references
relocated code such references have to be updated. The update is handled
by scanExternalRefs() function. Note that we cannot solely rely on
relocations written by the linker, as not all code references are
exposed to the linker. Additionally, the linker can modify certain
instructions and relocations will no longer match the code.

With this change, start using symbolic disassembler for scanning code
for references in scanExternalRefs(). Unlike the previous approach, the
symbolizer properly detects and creates references for instructions with
multiple/ambiguous symbolic operands and handles cases where a
relocation doesn't match any operand. See test cases for examples.

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D152631
bolt/include/bolt/Core/BinaryFunction.h
bolt/include/bolt/Core/MCPlusBuilder.h
bolt/lib/Core/BinaryFunction.cpp
bolt/lib/Target/X86/X86MCPlusBuilder.cpp
bolt/lib/Target/X86/X86MCSymbolizer.cpp
bolt/lib/Target/X86/X86MCSymbolizer.h
bolt/test/X86/double-rel-scan.s [new file with mode: 0644]
bolt/test/X86/double-rel.s
bolt/test/X86/gotpcrelx.s