[BOLT] Support multiple parents for split jump table
authorHuan Nguyen <nhuhuan@yahoo.com>
Thu, 14 Jul 2022 06:35:51 +0000 (23:35 -0700)
committerHuan Nguyen <nhuhuan@yahoo.com>
Thu, 14 Jul 2022 06:37:31 +0000 (23:37 -0700)
commit05523dc32d8ca81d9a92ff955194a9e80cf79dc0
tree4a85fa6f39547c05193f1e44b66c3e9f2a72e14d
parent611ffcf4e4a2ab19063174f6990969f96e9078de
[BOLT] Support multiple parents for split jump table

There are two assumptions regarding jump table:
(a) It is accessed by only one fragment, say, Parent
(b) All entries target instructions in Parent

For (a), BOLT stores jump table entries as relative offset to Parent.
For (b), BOLT treats jump table entries target somewhere out of Parent
as INVALID_OFFSET, including fragment of same split function.

In this update, we extend (a) and (b) to include fragment of same split
functinon. For (a), we store jump table entries in absolute offset
instead. In addition, jump table will store all fragments that access
it. A fragment uses this information to only create label for jump table
entries that target to that fragment.

For (b), using absolute offset allows jump table entries to target
fragments of same split function, i.e., extend support for split jump
table. This can be done using relocation (fragment start/size) and
fragment detection heuristics (e.g., using symbol name pattern for
non-stripped binaries).

For jump table targets that can only be reached by one fragment, we
mark them as local label; otherwise, they would be the secondary
function entry to the target fragment.

Test Plan
```
ninja check-bolt
```

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D128474
bolt/include/bolt/Core/BinaryContext.h
bolt/include/bolt/Core/BinaryFunction.h
bolt/include/bolt/Core/JumpTable.h
bolt/lib/Core/BinaryContext.cpp
bolt/lib/Core/BinaryFunction.cpp
bolt/lib/Core/JumpTable.cpp
bolt/lib/Passes/AsmDump.cpp
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/test/X86/jump-table-move.s [new file with mode: 0644]
bolt/test/X86/split-func-jump-table-fragment-bidirection.s