1# REQUIRES: system-linux 2 3# RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %s -o %tmain.o 4# RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q 5# RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections 6# RUN: llvm-dwarfdump --show-children --name=main --debug-info %t.bolt \ 7# RUN: | FileCheck %s 8 9# CHECK: DW_TAG_inlined_subroutine 10# CHECK: DW_AT_low_pc 11# CHECK-SAME: 0x0000000000000000 12 13# CHECK: DW_TAG_call_site 14# CHECK: DW_AT_call_return_pc 15# CHECK-SAME: 0x0000000000000000 16 17## Test that llvm-bolt correctly updates DIEs corresponding to deleted code. 18 19# Test case built from the following source using: 20# 21# clang -O2 -g -gdwarf-5 ... 22# 23# Assembly modified with "je" -> "jmp" to introduce unreachable block. 24# 25# extern void puts(const char *); 26# 27# static void foo() { 28# puts("hi"); 29# } 30# 31# int main(int argc, char **argv) { 32# if (argc) 33# foo(); 34# return 0; 35# } 36 37 .text 38 .file "unreachable.c" 39 .file 0 "." "unreachable.c" md5 0xd268d8460ea246544a440d4d42235947 40 .globl main # -- Begin function main 41 .p2align 4, 0x90 42 .type main,@function 43main: # @main 44.Lfunc_begin0: 45 .loc 0 7 0 # unreachable.c:7:0 46 .cfi_startproc 47# %bb.0: 48 #DEBUG_VALUE: main:argc <- $edi 49 #DEBUG_VALUE: main:argv <- $rsi 50 .loc 0 8 7 prologue_end # unreachable.c:8:7 51 testl %edi, %edi 52.Ltmp0: 53 .loc 0 8 7 is_stmt 0 # unreachable.c:8:7 54 jmp .LBB0_2 55.Ltmp1: 56# %bb.1: 57 #DEBUG_VALUE: main:argc <- $edi 58 #DEBUG_VALUE: main:argv <- $rsi 59 pushq %rax 60 .cfi_def_cfa_offset 16 61.Ltmp2: 62 .loc 0 4 3 is_stmt 1 # unreachable.c:4:3 63 movl $.L.str, %edi 64.Ltmp3: 65 #DEBUG_VALUE: main:argc <- [DW_OP_LLVM_entry_value 1] $edi 66 callq puts 67.Ltmp4: 68 #DEBUG_VALUE: main:argv <- [DW_OP_LLVM_entry_value 1] $rsi 69 .loc 0 0 3 is_stmt 0 # unreachable.c:0:3 70 addq $8, %rsp 71.Ltmp5: 72 .cfi_def_cfa_offset 8 73.LBB0_2: 74 #DEBUG_VALUE: main:argc <- [DW_OP_LLVM_entry_value 1] $edi 75 #DEBUG_VALUE: main:argv <- [DW_OP_LLVM_entry_value 1] $rsi 76 .loc 0 10 3 is_stmt 1 # unreachable.c:10:3 77 xorl %eax, %eax 78 retq 79.Ltmp6: 80.Lfunc_end0: 81 .size main, .Lfunc_end0-main 82 .cfi_endproc 83 # -- End function 84 .type .L.str,@object # @.str 85 .section .rodata.str1.1,"aMS",@progbits,1 86.L.str: 87 .asciz "hi" 88 .size .L.str, 3 89 90 .section .debug_loclists,"",@progbits 91 .long .Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length 92.Ldebug_list_header_start0: 93 .short 5 # Version 94 .byte 8 # Address size 95 .byte 0 # Segment selector size 96 .long 2 # Offset entry count 97.Lloclists_table_base0: 98 .long .Ldebug_loc0-.Lloclists_table_base0 99 .long .Ldebug_loc1-.Lloclists_table_base0 100.Ldebug_loc0: 101 .byte 4 # DW_LLE_offset_pair 102 .uleb128 .Lfunc_begin0-.Lfunc_begin0 # starting offset 103 .uleb128 .Ltmp3-.Lfunc_begin0 # ending offset 104 .byte 1 # Loc expr size 105 .byte 85 # super-register DW_OP_reg5 106 .byte 4 # DW_LLE_offset_pair 107 .uleb128 .Ltmp3-.Lfunc_begin0 # starting offset 108 .uleb128 .Lfunc_end0-.Lfunc_begin0 # ending offset 109 .byte 4 # Loc expr size 110 .byte 163 # DW_OP_entry_value 111 .byte 1 # 1 112 .byte 85 # super-register DW_OP_reg5 113 .byte 159 # DW_OP_stack_value 114 .byte 0 # DW_LLE_end_of_list 115.Ldebug_loc1: 116 .byte 4 # DW_LLE_offset_pair 117 .uleb128 .Lfunc_begin0-.Lfunc_begin0 # starting offset 118 .uleb128 .Ltmp4-.Lfunc_begin0 # ending offset 119 .byte 1 # Loc expr size 120 .byte 84 # DW_OP_reg4 121 .byte 4 # DW_LLE_offset_pair 122 .uleb128 .Ltmp4-.Lfunc_begin0 # starting offset 123 .uleb128 .Lfunc_end0-.Lfunc_begin0 # ending offset 124 .byte 4 # Loc expr size 125 .byte 163 # DW_OP_entry_value 126 .byte 1 # 1 127 .byte 84 # DW_OP_reg4 128 .byte 159 # DW_OP_stack_value 129 .byte 0 # DW_LLE_end_of_list 130.Ldebug_list_header_end0: 131 .section .debug_abbrev,"",@progbits 132 .byte 1 # Abbreviation Code 133 .byte 17 # DW_TAG_compile_unit 134 .byte 1 # DW_CHILDREN_yes 135 .byte 37 # DW_AT_producer 136 .byte 37 # DW_FORM_strx1 137 .byte 19 # DW_AT_language 138 .byte 5 # DW_FORM_data2 139 .byte 3 # DW_AT_name 140 .byte 37 # DW_FORM_strx1 141 .byte 114 # DW_AT_str_offsets_base 142 .byte 23 # DW_FORM_sec_offset 143 .byte 16 # DW_AT_stmt_list 144 .byte 23 # DW_FORM_sec_offset 145 .byte 27 # DW_AT_comp_dir 146 .byte 37 # DW_FORM_strx1 147 .byte 17 # DW_AT_low_pc 148 .byte 27 # DW_FORM_addrx 149 .byte 18 # DW_AT_high_pc 150 .byte 6 # DW_FORM_data4 151 .byte 115 # DW_AT_addr_base 152 .byte 23 # DW_FORM_sec_offset 153 .ascii "\214\001" # DW_AT_loclists_base 154 .byte 23 # DW_FORM_sec_offset 155 .byte 0 # EOM(1) 156 .byte 0 # EOM(2) 157 .byte 2 # Abbreviation Code 158 .byte 52 # DW_TAG_variable 159 .byte 0 # DW_CHILDREN_no 160 .byte 73 # DW_AT_type 161 .byte 19 # DW_FORM_ref4 162 .byte 58 # DW_AT_decl_file 163 .byte 11 # DW_FORM_data1 164 .byte 59 # DW_AT_decl_line 165 .byte 11 # DW_FORM_data1 166 .byte 2 # DW_AT_location 167 .byte 24 # DW_FORM_exprloc 168 .byte 0 # EOM(1) 169 .byte 0 # EOM(2) 170 .byte 3 # Abbreviation Code 171 .byte 1 # DW_TAG_array_type 172 .byte 1 # DW_CHILDREN_yes 173 .byte 73 # DW_AT_type 174 .byte 19 # DW_FORM_ref4 175 .byte 0 # EOM(1) 176 .byte 0 # EOM(2) 177 .byte 4 # Abbreviation Code 178 .byte 33 # DW_TAG_subrange_type 179 .byte 0 # DW_CHILDREN_no 180 .byte 73 # DW_AT_type 181 .byte 19 # DW_FORM_ref4 182 .byte 55 # DW_AT_count 183 .byte 11 # DW_FORM_data1 184 .byte 0 # EOM(1) 185 .byte 0 # EOM(2) 186 .byte 5 # Abbreviation Code 187 .byte 36 # DW_TAG_base_type 188 .byte 0 # DW_CHILDREN_no 189 .byte 3 # DW_AT_name 190 .byte 37 # DW_FORM_strx1 191 .byte 62 # DW_AT_encoding 192 .byte 11 # DW_FORM_data1 193 .byte 11 # DW_AT_byte_size 194 .byte 11 # DW_FORM_data1 195 .byte 0 # EOM(1) 196 .byte 0 # EOM(2) 197 .byte 6 # Abbreviation Code 198 .byte 36 # DW_TAG_base_type 199 .byte 0 # DW_CHILDREN_no 200 .byte 3 # DW_AT_name 201 .byte 37 # DW_FORM_strx1 202 .byte 11 # DW_AT_byte_size 203 .byte 11 # DW_FORM_data1 204 .byte 62 # DW_AT_encoding 205 .byte 11 # DW_FORM_data1 206 .byte 0 # EOM(1) 207 .byte 0 # EOM(2) 208 .byte 7 # Abbreviation Code 209 .byte 46 # DW_TAG_subprogram 210 .byte 0 # DW_CHILDREN_no 211 .byte 3 # DW_AT_name 212 .byte 37 # DW_FORM_strx1 213 .byte 58 # DW_AT_decl_file 214 .byte 11 # DW_FORM_data1 215 .byte 59 # DW_AT_decl_line 216 .byte 11 # DW_FORM_data1 217 .byte 32 # DW_AT_inline 218 .byte 33 # DW_FORM_implicit_const 219 .byte 1 220 .byte 0 # EOM(1) 221 .byte 0 # EOM(2) 222 .byte 8 # Abbreviation Code 223 .byte 46 # DW_TAG_subprogram 224 .byte 1 # DW_CHILDREN_yes 225 .byte 17 # DW_AT_low_pc 226 .byte 27 # DW_FORM_addrx 227 .byte 18 # DW_AT_high_pc 228 .byte 6 # DW_FORM_data4 229 .byte 64 # DW_AT_frame_base 230 .byte 24 # DW_FORM_exprloc 231 .byte 122 # DW_AT_call_all_calls 232 .byte 25 # DW_FORM_flag_present 233 .byte 3 # DW_AT_name 234 .byte 37 # DW_FORM_strx1 235 .byte 58 # DW_AT_decl_file 236 .byte 11 # DW_FORM_data1 237 .byte 59 # DW_AT_decl_line 238 .byte 11 # DW_FORM_data1 239 .byte 39 # DW_AT_prototyped 240 .byte 25 # DW_FORM_flag_present 241 .byte 73 # DW_AT_type 242 .byte 19 # DW_FORM_ref4 243 .byte 63 # DW_AT_external 244 .byte 25 # DW_FORM_flag_present 245 .byte 0 # EOM(1) 246 .byte 0 # EOM(2) 247 .byte 9 # Abbreviation Code 248 .byte 5 # DW_TAG_formal_parameter 249 .byte 0 # DW_CHILDREN_no 250 .byte 2 # DW_AT_location 251 .byte 34 # DW_FORM_loclistx 252 .byte 3 # DW_AT_name 253 .byte 37 # DW_FORM_strx1 254 .byte 58 # DW_AT_decl_file 255 .byte 11 # DW_FORM_data1 256 .byte 59 # DW_AT_decl_line 257 .byte 11 # DW_FORM_data1 258 .byte 73 # DW_AT_type 259 .byte 19 # DW_FORM_ref4 260 .byte 0 # EOM(1) 261 .byte 0 # EOM(2) 262 .byte 10 # Abbreviation Code 263 .byte 29 # DW_TAG_inlined_subroutine 264 .byte 0 # DW_CHILDREN_no 265 .byte 49 # DW_AT_abstract_origin 266 .byte 19 # DW_FORM_ref4 267 .byte 17 # DW_AT_low_pc 268 .byte 27 # DW_FORM_addrx 269 .byte 18 # DW_AT_high_pc 270 .byte 6 # DW_FORM_data4 271 .byte 88 # DW_AT_call_file 272 .byte 11 # DW_FORM_data1 273 .byte 89 # DW_AT_call_line 274 .byte 11 # DW_FORM_data1 275 .byte 87 # DW_AT_call_column 276 .byte 11 # DW_FORM_data1 277 .byte 0 # EOM(1) 278 .byte 0 # EOM(2) 279 .byte 11 # Abbreviation Code 280 .byte 72 # DW_TAG_call_site 281 .byte 0 # DW_CHILDREN_no 282 .byte 127 # DW_AT_call_origin 283 .byte 19 # DW_FORM_ref4 284 .byte 125 # DW_AT_call_return_pc 285 .byte 27 # DW_FORM_addrx 286 .byte 0 # EOM(1) 287 .byte 0 # EOM(2) 288 .byte 12 # Abbreviation Code 289 .byte 46 # DW_TAG_subprogram 290 .byte 1 # DW_CHILDREN_yes 291 .byte 3 # DW_AT_name 292 .byte 37 # DW_FORM_strx1 293 .byte 58 # DW_AT_decl_file 294 .byte 11 # DW_FORM_data1 295 .byte 59 # DW_AT_decl_line 296 .byte 11 # DW_FORM_data1 297 .byte 39 # DW_AT_prototyped 298 .byte 25 # DW_FORM_flag_present 299 .byte 60 # DW_AT_declaration 300 .byte 25 # DW_FORM_flag_present 301 .byte 63 # DW_AT_external 302 .byte 25 # DW_FORM_flag_present 303 .byte 0 # EOM(1) 304 .byte 0 # EOM(2) 305 .byte 13 # Abbreviation Code 306 .byte 5 # DW_TAG_formal_parameter 307 .byte 0 # DW_CHILDREN_no 308 .byte 73 # DW_AT_type 309 .byte 19 # DW_FORM_ref4 310 .byte 0 # EOM(1) 311 .byte 0 # EOM(2) 312 .byte 14 # Abbreviation Code 313 .byte 15 # DW_TAG_pointer_type 314 .byte 0 # DW_CHILDREN_no 315 .byte 73 # DW_AT_type 316 .byte 19 # DW_FORM_ref4 317 .byte 0 # EOM(1) 318 .byte 0 # EOM(2) 319 .byte 15 # Abbreviation Code 320 .byte 38 # DW_TAG_const_type 321 .byte 0 # DW_CHILDREN_no 322 .byte 73 # DW_AT_type 323 .byte 19 # DW_FORM_ref4 324 .byte 0 # EOM(1) 325 .byte 0 # EOM(2) 326 .byte 0 # EOM(3) 327 .section .debug_info,"",@progbits 328.Lcu_begin0: 329 .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit 330.Ldebug_info_start0: 331 .short 5 # DWARF version number 332 .byte 1 # DWARF Unit Type 333 .byte 8 # Address Size (in bytes) 334 .long .debug_abbrev # Offset Into Abbrev. Section 335 .byte 1 # Abbrev [1] 0xc:0x95 DW_TAG_compile_unit 336 .byte 0 # DW_AT_producer 337 .short 12 # DW_AT_language 338 .byte 1 # DW_AT_name 339 .long .Lstr_offsets_base0 # DW_AT_str_offsets_base 340 .long .Lline_table_start0 # DW_AT_stmt_list 341 .byte 2 # DW_AT_comp_dir 342 .byte 1 # DW_AT_low_pc 343 .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc 344 .long .Laddr_table_base0 # DW_AT_addr_base 345 .long .Lloclists_table_base0 # DW_AT_loclists_base 346 .byte 2 # Abbrev [2] 0x27:0xa DW_TAG_variable 347 .long 49 # DW_AT_type 348 .byte 0 # DW_AT_decl_file 349 .byte 4 # DW_AT_decl_line 350 .byte 2 # DW_AT_location 351 .byte 161 352 .byte 0 353 .byte 3 # Abbrev [3] 0x31:0xc DW_TAG_array_type 354 .long 61 # DW_AT_type 355 .byte 4 # Abbrev [4] 0x36:0x6 DW_TAG_subrange_type 356 .long 65 # DW_AT_type 357 .byte 3 # DW_AT_count 358 .byte 0 # End Of Children Mark 359 .byte 5 # Abbrev [5] 0x3d:0x4 DW_TAG_base_type 360 .byte 3 # DW_AT_name 361 .byte 6 # DW_AT_encoding 362 .byte 1 # DW_AT_byte_size 363 .byte 6 # Abbrev [6] 0x41:0x4 DW_TAG_base_type 364 .byte 4 # DW_AT_name 365 .byte 8 # DW_AT_byte_size 366 .byte 7 # DW_AT_encoding 367 .byte 7 # Abbrev [7] 0x45:0x4 DW_TAG_subprogram 368 .byte 5 # DW_AT_name 369 .byte 0 # DW_AT_decl_file 370 .byte 3 # DW_AT_decl_line 371 # DW_AT_inline 372 .byte 8 # Abbrev [8] 0x49:0x35 DW_TAG_subprogram 373 .byte 1 # DW_AT_low_pc 374 .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc 375 .byte 1 # DW_AT_frame_base 376 .byte 87 377 # DW_AT_call_all_calls 378 .byte 7 # DW_AT_name 379 .byte 0 # DW_AT_decl_file 380 .byte 7 # DW_AT_decl_line 381 # DW_AT_prototyped 382 .long 146 # DW_AT_type 383 # DW_AT_external 384 .byte 9 # Abbrev [9] 0x58:0x9 DW_TAG_formal_parameter 385 .byte 0 # DW_AT_location 386 .byte 9 # DW_AT_name 387 .byte 0 # DW_AT_decl_file 388 .byte 7 # DW_AT_decl_line 389 .long 146 # DW_AT_type 390 .byte 9 # Abbrev [9] 0x61:0x9 DW_TAG_formal_parameter 391 .byte 1 # DW_AT_location 392 .byte 10 # DW_AT_name 393 .byte 0 # DW_AT_decl_file 394 .byte 7 # DW_AT_decl_line 395 .long 150 # DW_AT_type 396 .byte 10 # Abbrev [10] 0x6a:0xd DW_TAG_inlined_subroutine 397 .long 69 # DW_AT_abstract_origin 398 .byte 2 # DW_AT_low_pc 399 .long .Ltmp5-.Ltmp2 # DW_AT_high_pc 400 .byte 0 # DW_AT_call_file 401 .byte 9 # DW_AT_call_line 402 .byte 5 # DW_AT_call_column 403 .byte 11 # Abbrev [11] 0x77:0x6 DW_TAG_call_site 404 .long 126 # DW_AT_call_origin 405 .byte 3 # DW_AT_call_return_pc 406 .byte 0 # End Of Children Mark 407 .byte 12 # Abbrev [12] 0x7e:0xa DW_TAG_subprogram 408 .byte 6 # DW_AT_name 409 .byte 0 # DW_AT_decl_file 410 .byte 1 # DW_AT_decl_line 411 # DW_AT_prototyped 412 # DW_AT_declaration 413 # DW_AT_external 414 .byte 13 # Abbrev [13] 0x82:0x5 DW_TAG_formal_parameter 415 .long 136 # DW_AT_type 416 .byte 0 # End Of Children Mark 417 .byte 14 # Abbrev [14] 0x88:0x5 DW_TAG_pointer_type 418 .long 141 # DW_AT_type 419 .byte 15 # Abbrev [15] 0x8d:0x5 DW_TAG_const_type 420 .long 61 # DW_AT_type 421 .byte 5 # Abbrev [5] 0x92:0x4 DW_TAG_base_type 422 .byte 8 # DW_AT_name 423 .byte 5 # DW_AT_encoding 424 .byte 4 # DW_AT_byte_size 425 .byte 14 # Abbrev [14] 0x96:0x5 DW_TAG_pointer_type 426 .long 155 # DW_AT_type 427 .byte 14 # Abbrev [14] 0x9b:0x5 DW_TAG_pointer_type 428 .long 61 # DW_AT_type 429 .byte 0 # End Of Children Mark 430.Ldebug_info_end0: 431 .section .debug_str_offsets,"",@progbits 432 .long 48 # Length of String Offsets Set 433 .short 5 434 .short 0 435.Lstr_offsets_base0: 436 .section .debug_str,"MS",@progbits,1 437.Linfo_string0: 438 .asciz "clang version 15.0.7 " # string offset=0 439.Linfo_string1: 440 .asciz "unreachable.c" # string offset=69 441.Linfo_string2: 442 .asciz "." # string offset=83 443.Linfo_string3: 444 .asciz "char" # string offset=85 445.Linfo_string4: 446 .asciz "__ARRAY_SIZE_TYPE__" # string offset=90 447.Linfo_string5: 448 .asciz "foo" # string offset=110 449.Linfo_string6: 450 .asciz "puts" # string offset=114 451.Linfo_string7: 452 .asciz "main" # string offset=119 453.Linfo_string8: 454 .asciz "int" # string offset=124 455.Linfo_string9: 456 .asciz "argc" # string offset=128 457.Linfo_string10: 458 .asciz "argv" # string offset=133 459 .section .debug_str_offsets,"",@progbits 460 .long .Linfo_string0 461 .long .Linfo_string1 462 .long .Linfo_string2 463 .long .Linfo_string3 464 .long .Linfo_string4 465 .long .Linfo_string5 466 .long .Linfo_string6 467 .long .Linfo_string7 468 .long .Linfo_string8 469 .long .Linfo_string9 470 .long .Linfo_string10 471 .section .debug_addr,"",@progbits 472 .long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution 473.Ldebug_addr_start0: 474 .short 5 # DWARF version number 475 .byte 8 # Address size 476 .byte 0 # Segment selector size 477.Laddr_table_base0: 478 .quad .L.str 479 .quad .Lfunc_begin0 480 .quad .Ltmp2 481 .quad .Ltmp4 482.Ldebug_addr_end0: 483 .section .debug_line,"",@progbits 484.Lline_table_start0: 485