[PATCH] D89176: Modify split CallSiteRanges to use correct lengths

Di Mo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 18:46:08 PDT 2020


modimo created this revision.
modimo added reviewers: rahmanl, MaskRay.
Herald added subscribers: llvm-commits, lxfind, hiraditya.
Herald added a project: LLVM.
modimo requested review of this revision.

In D73739 <https://reviews.llvm.org/D73739> @MaskRay pointed out that the lengths for CallSiteRanges in .gcc_except_table are not quite correct if blocks are outlined or using basic-block-sections. At runtime this is fine because the .eh_frame data will limit a function to a particular LSDA entry so that even though the longer length allows buffer-overflow the code length in .eh_frame acts as a back-stop.

However, in post-binary analysis tools (e.g. BOLT) that may only parse the .gcc_except_table section having these lengths be incorrect will result in a buffer overflow when using this field to read forward.

There's also no binary cost for making these labels correct and leads to smaller offsets which compress better leading to very minor metadata size reduction.

Testing:
ninja check


https://reviews.llvm.org/D89176

Files:
  llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
  llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
  llvm/test/CodeGen/X86/gcc_except_table_bb_sections_ehpad_groups_with_cold.ll


Index: llvm/test/CodeGen/X86/gcc_except_table_bb_sections_ehpad_groups_with_cold.ll
===================================================================
--- llvm/test/CodeGen/X86/gcc_except_table_bb_sections_ehpad_groups_with_cold.ll
+++ llvm/test/CodeGen/X86/gcc_except_table_bb_sections_ehpad_groups_with_cold.ll
@@ -67,6 +67,7 @@
 ; CHECK-NEXT:    .uleb128 .Ltmp1-.Ltmp0         #   Call between .Ltmp0 and .Ltmp1
 ; CHECK-NEXT:    .uleb128 .Ltmp2-main.cold      #     jumps to .Ltmp2
 ; CHECK-NEXT:    .byte	3                       #   On action: 2
+; CHECK-NEXT:  .Laction_table_base0:
 ; CHECK-NEXT:    .p2align	2
 ; CHECK-NEXT:  .Lexception1:
 ; CHECK-NEXT:    .byte	0                       # @LPStart Encoding = absptr
@@ -75,13 +76,13 @@
 ; CHECK-NEXT:    .uleb128 .Lttbase0-.Lttbaseref1
 ; CHECK-NEXT:  .Lttbaseref1:
 ; CHECK-NEXT:    .byte	1                       # Call site Encoding = uleb128
-; CHECK-NEXT:    .uleb128 .Laction_table_base0-.Lcst_begin1
+; CHECK-NEXT:    .uleb128 .Laction_table_base1-.Lcst_begin1
 ; CHECK-NEXT:  .Lcst_begin1:
 ; CHECK-NEXT:    .uleb128 main.cold-main.cold   # >> Call Site 2 <<
 ; CHECK-NEXT:    .uleb128 .LBB_END0_2-main.cold #   Call between main.cold and .LBB_END0_2
 ; CHECK-NEXT:    .byte	0                       #     has no landing pad
 ; CHECK-NEXT:    .byte	0                       #   On action: cleanup
-; CHECK-NEXT:  .Laction_table_base0:
+; CHECK-NEXT:  .Laction_table_base1:
 ; CHECK-NEXT:    .byte	0                       # >> Action Record 1 <<
 ; CHECK-NEXT:                                   #   Cleanup
 ; CHECK-NEXT:    .byte	0                       #   No further actions
Index: llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
===================================================================
--- llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
+++ llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll
@@ -104,6 +104,7 @@
 ; CHECK-NEXT:           .uleb128 .Ltmp1-.Ltmp0          #   Call between .Ltmp0 and .Ltmp1
 ; CHECK-NEXT:           .uleb128 .Ltmp2-main.2          #     jumps to .Ltmp2
 ; CHECK-NEXT:           .byte	3                       #   On action: 2
+; CHECK-NEXT:         .Laction_table_base0
 ; CHECK-NEXT:           .p2align	2
 ; CHECK-NEXT:         .Lexception1:
 
@@ -121,8 +122,9 @@
 ; CHECK-NEXT:           .uleb128 .Lttbase0-.Lttbaseref1
 ; CHECK-NEXT:         .Lttbaseref1:
 ; CHECK-NEXT:           .byte	1                       # Call site Encoding = uleb128
-; CHECK-NEXT:           .uleb128 .Laction_table_base0-.Lcst_begin1
+; CHECK-NEXT:           .uleb128 .Laction_table_base1-.Lcst_begin1
 ; CHECK-NEXT:         .Lcst_begin1:
+; CHECK-NEXT:         .Laction_table_base1
 ; CHECK-NEXT:           .p2align 2
 ; CHECK-NEXT:         .Lexception2:
 
@@ -140,13 +142,13 @@
 ; CHECK-NEXT:           .uleb128 .Lttbase0-.Lttbaseref2
 ; CHECK-NEXT:         .Lttbaseref2:
 ; CHECK-NEXT:           .byte	1                       # Call site Encoding = uleb128
-; CHECK-NEXT:           .uleb128 .Laction_table_base0-.Lcst_begin2
+; CHECK-NEXT:           .uleb128 .Laction_table_base2-.Lcst_begin2
 ; CHECK-NEXT:         .Lcst_begin2:
 ; CHECK-NEXT:           .uleb128 main.2-main.2          # >> Call Site 2 <<
 ; CHECK-NEXT:           .uleb128 .LBB_END0_2-main.2     #   Call between main.2 and .LBB_END0_2
 ; CHECK-NEXT:           .byte	0                       #     has no landing pad
 ; CHECK-NEXT:           .byte	0                       #   On action: cleanup
-; CHECK-NEXT:         .Laction_table_base0:
+; CHECK-NEXT:         .Laction_table_base2:
 ; CHECK-NEXT:           .byte	0                       # >> Action Record 1 <<
 ; CHECK-NEXT:                                           #   Cleanup
 ; CHECK-NEXT:           .byte	0                       #   No further actions
Index: llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
+++ llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
@@ -671,8 +671,13 @@
         }
         Asm->emitULEB128(S.Action);
       }
+
+      Asm->OutStreamer->emitLabel(CstEndLabel);
+
+      // With multiple call ranges, we need go generate multiple bases
+      if (CstEndLabel)
+        CstEndLabel = Asm->createTempSymbol("action_table_base");
     }
-    Asm->OutStreamer->emitLabel(CstEndLabel);
   }
 
   // Emit the Action Table.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89176.297374.patch
Type: text/x-patch
Size: 4380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201010/bcf5d5dd/attachment.bin>


More information about the llvm-commits mailing list