[BOLT] Fix writing out unmarked .eh_frame section
authorMaksim Panchenko <maks@fb.com>
Tue, 4 Oct 2022 01:50:18 +0000 (18:50 -0700)
committerMaksim Panchenko <maks@fb.com>
Fri, 7 Oct 2022 18:19:51 +0000 (11:19 -0700)
commit0b213c9090369ff43060816aed38cb6c67e228f8
treeadd038287e97da5f65708369aa0d9913dedc7adc
parentc683e281cdc99b04497d5102c28be0d2e991c9f6
[BOLT] Fix writing out unmarked .eh_frame section

When BOLT updates .eh_frame section, it concatenates newly-generated
contents (from CFI directives) with the original .eh_frame that has
relocations applied to it. However, if no new content is generated,
the original .eh_frame has to be left intact. In that case, BOLT was
still writing out the relocatable copy of the original .eh_frame section
to the new segment, even though this copy was never used and was not
even marked in the section header table.

Detect the scenario above and skip allocating extra space for .eh_frame.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D135223
bolt/lib/Rewrite/RewriteInstance.cpp
bolt/test/X86/dummy-eh-frame-bug.s [new file with mode: 0644]