[BOLT] Fix EH trampoline backout code
authorMaksim Panchenko <maks@fb.com>
Fri, 24 Jun 2022 23:51:46 +0000 (16:51 -0700)
committerMaksim Panchenko <maks@fb.com>
Wed, 29 Jun 2022 21:35:57 +0000 (14:35 -0700)
commited74304506a0c97860bad5c91b0b7ccb59ab181d
tree6b5096e8ed0787127544e492ce0f3ee25063bb93
parent5530e5552128e9360dccf5e4813dd691d8b4c503
[BOLT] Fix EH trampoline backout code

When SplitFunctions pass adds a trampoline code for exception landing
pads (limited to shared objects), it may increase the size of the hot
fragment making it larger than the whole function pre-split. When this
happens, the pass reverts the splitting action by restoring the original
block order and marking all blocks hot.

However, if createEHTrampolines() added new blocks to the CFG and
modified invoke instructions, simply restoring the original block layout
will not suffice as the new CFG has more blocks.

For proper backout of the split, modify the original layout by merging
in trampoline blocks immediately before their matching targets. As a
result, the number of blocks increases, but the number of instructions
and the function size remains the same as pre-split.

Add an assertion for the number of blocks when updating a function
layout.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D128696
bolt/include/bolt/Core/BinaryFunction.h
bolt/include/bolt/Passes/SplitFunctions.h
bolt/lib/Passes/SplitFunctions.cpp
bolt/test/runtime/X86/Inputs/pie-exceptions-failed-split.s [new file with mode: 0644]
bolt/test/runtime/X86/pie-exceptions-failed-split.test [new file with mode: 0644]