1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
# This test reproduces the case where C++ exception handling is used and split
# function optimization is enabled. In particular, function foo is splitted
# to two fragments:
# foo: contains 2 try blocks, which invokes bar to throw exception
# foo.cold.1: contains 2 corresponding catch blocks (landing pad)
#
# Similar to split jump table, split landing pad target to different fragment.
# This test is written to ensure BOLT safely handle these targets, e.g., by
# marking them as non-simple.
#
# Steps to write this test:
# - Create a copy of Inputs/src/unreachable.cpp
# - Simplify bar(), focus on throw an exception
# - Create the second switch case in foo() to have multiple landing pads
# - Compile with clang++ to .s
# - Move landing pad code from foo to foo.cold.1
# - Ensure that all landing pads can be reached normally
#
# Additional details:
# .gcc_except_table specify the landing pads for try blocks
# LPStart = 255 (omit), which means LPStart = foo start
# Landing pads .Ltmp2 and .Ltmp5 in call site record are offset to foo start.
# REQUIRES: system-linux
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
# RUN: %clang++ %cxxflags %t.o -o %t.exe -Wl,-q
# RUN: llvm-bolt -v=3 %t.exe -o %t.out 2>&1 | FileCheck %s
# CHECK: BOLT-WARNING: Ignoring foo
# CHECK: BOLT-WARNING: Ignoring foo.cold.1
# CHECK: BOLT-WARNING: skipped 2 functions due to cold fragments
.text
.globl bar # -- Begin function bar
.p2align 4, 0x90
.type bar,@function
bar: # @bar
.cfi_startproc
# %bb.0: # %entry
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
subq $16, %rsp
movq %rdi, -8(%rbp)
cmpq $34, -8(%rbp)
jne .LBB0_2
# %bb.1: # %if.then
movl $4, %edi
callq __cxa_allocate_exception@PLT
movq %rax, %rdi
movl $0, (%rdi)
movq _ZTIi@GOTPCREL(%rip), %rsi
xorl %eax, %eax
movl %eax, %edx
callq __cxa_throw@PLT
.LBB0_2: # %if.else
movl $8, %edi
callq __cxa_allocate_exception@PLT
movq %rax, %rdi
movq $0, (%rdi)
movq _ZTIDn@GOTPCREL(%rip), %rsi
xorl %eax, %eax
movl %eax, %edx
callq __cxa_throw@PLT
.Lfunc_end0:
.size bar, .Lfunc_end0-bar
.cfi_endproc
# -- End function
.globl foo # -- Begin function foo
.p2align 4, 0x90
.type foo,@function
foo: # @foo
.Lfunc_begin0:
.cfi_startproc
.cfi_personality 155, DW.ref.__gxx_personality_v0
.cfi_lsda 27, .Lexception0
# %bb.0: # %entry
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
subq $48, %rsp
movq %rdi, -16(%rbp)
movq -16(%rbp), %rdi
.Ltmp0:
callq bar
.Ltmp1:
jmp .LBB1_1
.LBB1_1: # %invoke.cont
jmp .LBB1_5
.LBB1_5: # %try.cont
movq -16(%rbp), %rdi
addq $34, %rdi
.Ltmp3:
callq bar
.Ltmp4:
jmp .LBB1_6
.LBB1_6: # %invoke.cont2
jmp .LBB1_10
.LBB1_10: # %try.cont8
movq $0, -8(%rbp)
.LBB1_11: # %return
movq -8(%rbp), %rax
addq $48, %rsp
popq %rbp
.cfi_def_cfa %rsp, 8
retq
.LBB1_12: # %eh.resume
.cfi_def_cfa %rbp, 16
movq -24(%rbp), %rdi
callq _Unwind_Resume@PLT
.Lfunc_end1:
.size foo, .Lfunc_end1-foo
.cfi_endproc
.section .gcc_except_table,"a",@progbits
.p2align 2
GCC_except_table1:
.Lexception0:
.byte 255 # @LPStart Encoding = omit
.byte 155 # @TType Encoding = indirect pcrel sdata4
.uleb128 .Lttbase0-.Lttbaseref0
.Lttbaseref0:
.byte 1 # Call site Encoding = uleb128
.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
.uleb128 .Ltmp0-.Lfunc_begin0 # >> Call Site 1 <<
.uleb128 .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1
.uleb128 .Ltmp2-.Lfunc_begin0 # jumps to .Ltmp2
.byte 1 # On action: 1
.uleb128 .Ltmp1-.Lfunc_begin0 # >> Call Site 2 <<
.uleb128 .Ltmp3-.Ltmp1 # Call between .Ltmp1 and .Ltmp3
.byte 0 # has no landing pad
.byte 0 # On action: cleanup
.uleb128 .Ltmp3-.Lfunc_begin0 # >> Call Site 3 <<
.uleb128 .Ltmp4-.Ltmp3 # Call between .Ltmp3 and .Ltmp4
.uleb128 .Ltmp5-.Lfunc_begin0 # jumps to .Ltmp5
.byte 1 # On action: 1
.uleb128 .Ltmp4-.Lfunc_begin0 # >> Call Site 4 <<
.uleb128 .Lfunc_end1-.Ltmp4 # Call between .Ltmp4 and .Lfunc_end1
.byte 0 # has no landing pad
.byte 0 # On action: cleanup
.Lcst_end0:
.byte 1 # >> Action Record 1 <<
# Catch TypeInfo 1
.byte 0 # No further actions
.p2align 2
# >> Catch TypeInfos <<
.Ltmp6: # TypeInfo 1
.long .L_ZTIi.DW.stub-.Ltmp6
.Lttbase0:
.p2align 2
# -- End function
.text
.globl foo.cold.1 # -- Begin function foo.cold.1
.p2align 4, 0x90
.type foo.cold.1,@function
foo.cold.1: # @foo.cold.1
.Lfunc_begin3:
.cfi_startproc
.Ltmp2:
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -24(%rbp)
movl %eax, -28(%rbp)
# %bb.3: # %catch.dispatch
movl -28(%rbp), %eax
movl $1, %ecx
cmpl %ecx, %eax
jne .LBB1_12
# %bb.4: # %catch
movq -24(%rbp), %rdi
callq __cxa_begin_catch@PLT
movl (%rax), %eax
movl %eax, -32(%rbp)
movq $0, -8(%rbp)
callq __cxa_end_catch@PLT
jmp .LBB1_11
.Ltmp5:
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -24(%rbp)
movl %eax, -28(%rbp)
# %bb.8: # %catch.dispatch3
movl -28(%rbp), %eax
movl $1, %ecx
cmpl %ecx, %eax
jne .LBB1_12
# %bb.9: # %catch6
movq -24(%rbp), %rdi
callq __cxa_begin_catch@PLT
movl (%rax), %eax
movl %eax, -36(%rbp)
movq $0, -8(%rbp)
callq __cxa_end_catch@PLT
jmp .LBB1_11
.Lfunc_end3:
.size foo.cold.1, .Lfunc_end3-foo.cold.1
.cfi_endproc
.text
.globl main # -- Begin function main
.p2align 4, 0x90
.type main,@function
main: # @main
.cfi_startproc
# %bb.0: # %entry
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
subq $16, %rsp
movl $0, -4(%rbp)
movl %edi, -8(%rbp)
movq %rsi, -16(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq foo
# kill: def $eax killed $eax killed $rax
addq $16, %rsp
popq %rbp
.cfi_def_cfa %rsp, 8
retq
.Lfunc_end2:
.size main, .Lfunc_end2-main
.cfi_endproc
# -- End function
.data
.p2align 3
.L_ZTIi.DW.stub:
.quad _ZTIi
.hidden DW.ref.__gxx_personality_v0
.weak DW.ref.__gxx_personality_v0
.section .data.DW.ref.__gxx_personality_v0,"aGw",@progbits,DW.ref.__gxx_personality_v0,comdat
.p2align 3
.type DW.ref.__gxx_personality_v0,@object
.size DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
.quad __gxx_personality_v0
.section ".note.GNU-stack","",@progbits
.addrsig
.addrsig_sym bar
.addrsig_sym __cxa_allocate_exception
.addrsig_sym __cxa_throw
.addrsig_sym foo
.addrsig_sym __gxx_personality_v0
.addrsig_sym __cxa_begin_catch
.addrsig_sym __cxa_end_catch
.addrsig_sym _Unwind_Resume
.addrsig_sym _ZTIi
.addrsig_sym _ZTIDn
.addrsig_sym foo.cold.1
.addrsig_sym __cxa_begin_catch
.addrsig_sym __cxa_end_catch
|