1# REQUIRES: system-linux 2 3# RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %s -o %t1.o 4# RUN: %clang %cflags -dwarf-5 %t1.o -o %t.exe -Wl,-q -Wl,-gc-sections -fuse-ld=lld -Wl,--entry=main 5# RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections 6# RUN: llvm-dwarfdump --debug-info %t.exe | FileCheck --check-prefix=PRECHECK %s 7# RUN: llvm-dwarfdump --debug-info %t.bolt | FileCheck --check-prefix=POSTCHECK %s 8 9# PRECHECK: DW_TAG_subprogram 10# PRECHECK-NEXT: DW_AT_ranges 11# PRECHECK-NEXT: [0x0000000000000000 12# PRECHECK-NEXT: [0x0000000000000000 13# PRECHECK-NEXT: [0x0000000000000000 14# PRECHECK-NEXT: [0x0000000000000000 15# PRECHECK-NEXT: DW_AT_frame_base 16# PRECHECK-NEXT: DW_AT_linkage_name ("_Z6helperi") 17# PRECHECK-NEXT: DW_AT_name ("helper") 18 19# POSTCHECK: DW_TAG_subprogram 20# POSTCHECK-NEXT: DW_AT_frame_base 21# POSTCHECK-NEXT: DW_AT_linkage_name ("_Z6helperi") 22# POSTCHECK-NEXT: DW_AT_name ("helper") 23# POSTCHECK-NEXT: DW_AT_decl_file 24# POSTCHECK-NEXT: DW_AT_decl_line 25# POSTCHECK-NEXT: DW_AT_type 26# POSTCHECK-NEXT: DW_AT_external 27# POSTCHECK-NEXT: DW_AT_low_pc (0x0000000000000000) 28# POSTCHECK-NEXT: DW_AT_high_pc (0x0000000000000001) 29 30## Tests BOLT path that handles DW_AT_ranges with no output function ranges. 31 32## clang++ main.cpp -O0 -fno-inline-functions -fbasic-block-sections=all -g2 -S 33## int helper(int argc) { 34## int x = argc; 35## if (x == 3) 36## x++; 37## else 38## x--; 39## return x; 40## } 41## int main(int argc, char *argv[]) { 42## int x = argc; 43## if (x == 3) 44## x++; 45## else 46## x--; 47## return x; 48## } 49 50 .text 51 .file "main.cpp" 52 .section .text._Z6helperi,"ax",@progbits 53 .globl _Z6helperi # -- Begin function _Z6helperi 54 .p2align 4, 0x90 55 .type _Z6helperi,@function 56_Z6helperi: # @_Z6helperi 57.Lfunc_begin0: 58 .file 0 "/repro2" "main.cpp" md5 0x888a2704226ec400f256aa9c2207456c 59 .loc 0 1 0 # main.cpp:1:0 60 .cfi_startproc 61# %bb.0: # %entry 62 pushq %rbp 63 .cfi_def_cfa_offset 16 64 .cfi_offset %rbp, -16 65 movq %rsp, %rbp 66 .cfi_def_cfa_register %rbp 67 movl %edi, -4(%rbp) 68.Ltmp0: 69 .loc 0 2 11 prologue_end # main.cpp:2:11 70 movl -4(%rbp), %eax 71 .loc 0 2 7 is_stmt 0 # main.cpp:2:7 72 movl %eax, -8(%rbp) 73.Ltmp1: 74 .loc 0 3 9 is_stmt 1 # main.cpp:3:9 75 cmpl $3, -8(%rbp) 76.Ltmp2: 77 .loc 0 3 7 is_stmt 0 # main.cpp:3:7 78 jne _Z6helperi.__part.2 79 jmp _Z6helperi.__part.1 80.LBB_END0_0: 81 .cfi_endproc 82 .section .text._Z6helperi,"ax",@progbits,unique,1 83_Z6helperi.__part.1: # %if.then 84 .cfi_startproc 85 .cfi_def_cfa %rbp, 16 86 .cfi_offset %rbp, -16 87 .loc 0 4 6 is_stmt 1 # main.cpp:4:6 88 movl -8(%rbp), %eax 89 addl $1, %eax 90 movl %eax, -8(%rbp) 91 .loc 0 4 5 is_stmt 0 # main.cpp:4:5 92 jmp _Z6helperi.__part.3 93.LBB_END0_1: 94 .size _Z6helperi.__part.1, .LBB_END0_1-_Z6helperi.__part.1 95 .cfi_endproc 96 .section .text._Z6helperi,"ax",@progbits,unique,2 97_Z6helperi.__part.2: # %if.else 98 .cfi_startproc 99 .cfi_def_cfa %rbp, 16 100 .cfi_offset %rbp, -16 101 .loc 0 6 6 is_stmt 1 # main.cpp:6:6 102 movl -8(%rbp), %eax 103 addl $-1, %eax 104 movl %eax, -8(%rbp) 105 jmp _Z6helperi.__part.3 106.LBB_END0_2: 107 .size _Z6helperi.__part.2, .LBB_END0_2-_Z6helperi.__part.2 108 .cfi_endproc 109 .section .text._Z6helperi,"ax",@progbits,unique,3 110_Z6helperi.__part.3: # %if.end 111 .cfi_startproc 112 .cfi_def_cfa %rbp, 16 113 .cfi_offset %rbp, -16 114 .loc 0 7 10 # main.cpp:7:10 115 movl -8(%rbp), %eax 116 .loc 0 7 3 epilogue_begin is_stmt 0 # main.cpp:7:3 117 popq %rbp 118 .cfi_def_cfa %rsp, 8 119 retq 120.LBB_END0_3: 121 .size _Z6helperi.__part.3, .LBB_END0_3-_Z6helperi.__part.3 122 .cfi_endproc 123 .section .text._Z6helperi,"ax",@progbits 124.Lfunc_end0: 125 .size _Z6helperi, .Lfunc_end0-_Z6helperi 126 # -- End function 127 .section .text.main,"ax",@progbits 128 .globl main # -- Begin function main 129 .p2align 4, 0x90 130 .type main,@function 131main: # @main 132.Lfunc_begin1: 133 .loc 0 9 0 is_stmt 1 # main.cpp:9:0 134 .cfi_startproc 135# %bb.0: # %entry 136 pushq %rbp 137 .cfi_def_cfa_offset 16 138 .cfi_offset %rbp, -16 139 movq %rsp, %rbp 140 .cfi_def_cfa_register %rbp 141 movl $0, -4(%rbp) 142 movl %edi, -8(%rbp) 143 movq %rsi, -16(%rbp) 144.Ltmp3: 145 .loc 0 10 11 prologue_end # main.cpp:10:11 146 movl -8(%rbp), %eax 147 .loc 0 10 7 is_stmt 0 # main.cpp:10:7 148 movl %eax, -20(%rbp) 149.Ltmp4: 150 .loc 0 11 9 is_stmt 1 # main.cpp:11:9 151 cmpl $3, -20(%rbp) 152.Ltmp5: 153 .loc 0 11 7 is_stmt 0 # main.cpp:11:7 154 jne main.__part.2 155 jmp main.__part.1 156.LBB_END1_0: 157 .cfi_endproc 158 .section .text.main,"ax",@progbits,unique,4 159main.__part.1: # %if.then 160 .cfi_startproc 161 .cfi_def_cfa %rbp, 16 162 .cfi_offset %rbp, -16 163 .loc 0 12 6 is_stmt 1 # main.cpp:12:6 164 movl -20(%rbp), %eax 165 addl $1, %eax 166 movl %eax, -20(%rbp) 167 .loc 0 12 5 is_stmt 0 # main.cpp:12:5 168 jmp main.__part.3 169.LBB_END1_1: 170 .size main.__part.1, .LBB_END1_1-main.__part.1 171 .cfi_endproc 172 .section .text.main,"ax",@progbits,unique,5 173main.__part.2: # %if.else 174 .cfi_startproc 175 .cfi_def_cfa %rbp, 16 176 .cfi_offset %rbp, -16 177 .loc 0 14 6 is_stmt 1 # main.cpp:14:6 178 movl -20(%rbp), %eax 179 addl $-1, %eax 180 movl %eax, -20(%rbp) 181 jmp main.__part.3 182.LBB_END1_2: 183 .size main.__part.2, .LBB_END1_2-main.__part.2 184 .cfi_endproc 185 .section .text.main,"ax",@progbits,unique,6 186main.__part.3: # %if.end 187 .cfi_startproc 188 .cfi_def_cfa %rbp, 16 189 .cfi_offset %rbp, -16 190 .loc 0 15 10 # main.cpp:15:10 191 movl -20(%rbp), %eax 192 .loc 0 15 3 epilogue_begin is_stmt 0 # main.cpp:15:3 193 popq %rbp 194 .cfi_def_cfa %rsp, 8 195 retq 196.LBB_END1_3: 197 .size main.__part.3, .LBB_END1_3-main.__part.3 198 .cfi_endproc 199 .section .text.main,"ax",@progbits 200.Lfunc_end1: 201 .size main, .Lfunc_end1-main 202 # -- End function 203 .section .debug_abbrev,"",@progbits 204 .byte 1 # Abbreviation Code 205 .byte 17 # DW_TAG_compile_unit 206 .byte 1 # DW_CHILDREN_yes 207 .byte 37 # DW_AT_producer 208 .byte 37 # DW_FORM_strx1 209 .byte 19 # DW_AT_language 210 .byte 5 # DW_FORM_data2 211 .byte 3 # DW_AT_name 212 .byte 37 # DW_FORM_strx1 213 .byte 114 # DW_AT_str_offsets_base 214 .byte 23 # DW_FORM_sec_offset 215 .byte 16 # DW_AT_stmt_list 216 .byte 23 # DW_FORM_sec_offset 217 .byte 27 # DW_AT_comp_dir 218 .byte 37 # DW_FORM_strx1 219 .byte 17 # DW_AT_low_pc 220 .byte 1 # DW_FORM_addr 221 .byte 85 # DW_AT_ranges 222 .byte 35 # DW_FORM_rnglistx 223 .byte 115 # DW_AT_addr_base 224 .byte 23 # DW_FORM_sec_offset 225 .byte 116 # DW_AT_rnglists_base 226 .byte 23 # DW_FORM_sec_offset 227 .byte 0 # EOM(1) 228 .byte 0 # EOM(2) 229 .byte 2 # Abbreviation Code 230 .byte 46 # DW_TAG_subprogram 231 .byte 1 # DW_CHILDREN_yes 232 .byte 85 # DW_AT_ranges 233 .byte 35 # DW_FORM_rnglistx 234 .byte 64 # DW_AT_frame_base 235 .byte 24 # DW_FORM_exprloc 236 .byte 110 # DW_AT_linkage_name 237 .byte 37 # DW_FORM_strx1 238 .byte 3 # DW_AT_name 239 .byte 37 # DW_FORM_strx1 240 .byte 58 # DW_AT_decl_file 241 .byte 11 # DW_FORM_data1 242 .byte 59 # DW_AT_decl_line 243 .byte 11 # DW_FORM_data1 244 .byte 73 # DW_AT_type 245 .byte 19 # DW_FORM_ref4 246 .byte 63 # DW_AT_external 247 .byte 25 # DW_FORM_flag_present 248 .byte 0 # EOM(1) 249 .byte 0 # EOM(2) 250 .byte 3 # Abbreviation Code 251 .byte 5 # DW_TAG_formal_parameter 252 .byte 0 # DW_CHILDREN_no 253 .byte 2 # DW_AT_location 254 .byte 24 # DW_FORM_exprloc 255 .byte 3 # DW_AT_name 256 .byte 37 # DW_FORM_strx1 257 .byte 58 # DW_AT_decl_file 258 .byte 11 # DW_FORM_data1 259 .byte 59 # DW_AT_decl_line 260 .byte 11 # DW_FORM_data1 261 .byte 73 # DW_AT_type 262 .byte 19 # DW_FORM_ref4 263 .byte 0 # EOM(1) 264 .byte 0 # EOM(2) 265 .byte 4 # Abbreviation Code 266 .byte 52 # DW_TAG_variable 267 .byte 0 # DW_CHILDREN_no 268 .byte 2 # DW_AT_location 269 .byte 24 # DW_FORM_exprloc 270 .byte 3 # DW_AT_name 271 .byte 37 # DW_FORM_strx1 272 .byte 58 # DW_AT_decl_file 273 .byte 11 # DW_FORM_data1 274 .byte 59 # DW_AT_decl_line 275 .byte 11 # DW_FORM_data1 276 .byte 73 # DW_AT_type 277 .byte 19 # DW_FORM_ref4 278 .byte 0 # EOM(1) 279 .byte 0 # EOM(2) 280 .byte 5 # Abbreviation Code 281 .byte 46 # DW_TAG_subprogram 282 .byte 1 # DW_CHILDREN_yes 283 .byte 85 # DW_AT_ranges 284 .byte 35 # DW_FORM_rnglistx 285 .byte 64 # DW_AT_frame_base 286 .byte 24 # DW_FORM_exprloc 287 .byte 3 # DW_AT_name 288 .byte 37 # DW_FORM_strx1 289 .byte 58 # DW_AT_decl_file 290 .byte 11 # DW_FORM_data1 291 .byte 59 # DW_AT_decl_line 292 .byte 11 # DW_FORM_data1 293 .byte 73 # DW_AT_type 294 .byte 19 # DW_FORM_ref4 295 .byte 63 # DW_AT_external 296 .byte 25 # DW_FORM_flag_present 297 .byte 0 # EOM(1) 298 .byte 0 # EOM(2) 299 .byte 6 # Abbreviation Code 300 .byte 36 # DW_TAG_base_type 301 .byte 0 # DW_CHILDREN_no 302 .byte 3 # DW_AT_name 303 .byte 37 # DW_FORM_strx1 304 .byte 62 # DW_AT_encoding 305 .byte 11 # DW_FORM_data1 306 .byte 11 # DW_AT_byte_size 307 .byte 11 # DW_FORM_data1 308 .byte 0 # EOM(1) 309 .byte 0 # EOM(2) 310 .byte 7 # Abbreviation Code 311 .byte 15 # DW_TAG_pointer_type 312 .byte 0 # DW_CHILDREN_no 313 .byte 73 # DW_AT_type 314 .byte 19 # DW_FORM_ref4 315 .byte 0 # EOM(1) 316 .byte 0 # EOM(2) 317 .byte 0 # EOM(3) 318 .section .debug_info,"",@progbits 319.Lcu_begin0: 320 .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit 321.Ldebug_info_start0: 322 .short 5 # DWARF version number 323 .byte 1 # DWARF Unit Type 324 .byte 8 # Address Size (in bytes) 325 .long .debug_abbrev # Offset Into Abbrev. Section 326 .byte 1 # Abbrev [1] 0xc:0x82 DW_TAG_compile_unit 327 .byte 0 # DW_AT_producer 328 .short 33 # DW_AT_language 329 .byte 1 # DW_AT_name 330 .long .Lstr_offsets_base0 # DW_AT_str_offsets_base 331 .long .Lline_table_start0 # DW_AT_stmt_list 332 .byte 2 # DW_AT_comp_dir 333 .quad 0 # DW_AT_low_pc 334 .byte 2 # DW_AT_ranges 335 .long .Laddr_table_base0 # DW_AT_addr_base 336 .long .Lrnglists_table_base0 # DW_AT_rnglists_base 337 .byte 2 # Abbrev [2] 0x2b:0x23 DW_TAG_subprogram 338 .byte 0 # DW_AT_ranges 339 .byte 1 # DW_AT_frame_base 340 .byte 86 341 .byte 3 # DW_AT_linkage_name 342 .byte 4 # DW_AT_name 343 .byte 0 # DW_AT_decl_file 344 .byte 1 # DW_AT_decl_line 345 .long 123 # DW_AT_type 346 # DW_AT_external 347 .byte 3 # Abbrev [3] 0x37:0xb DW_TAG_formal_parameter 348 .byte 2 # DW_AT_location 349 .byte 145 350 .byte 124 351 .byte 7 # DW_AT_name 352 .byte 0 # DW_AT_decl_file 353 .byte 1 # DW_AT_decl_line 354 .long 123 # DW_AT_type 355 .byte 4 # Abbrev [4] 0x42:0xb DW_TAG_variable 356 .byte 2 # DW_AT_location 357 .byte 145 358 .byte 120 359 .byte 8 # DW_AT_name 360 .byte 0 # DW_AT_decl_file 361 .byte 2 # DW_AT_decl_line 362 .long 123 # DW_AT_type 363 .byte 0 # End Of Children Mark 364 .byte 5 # Abbrev [5] 0x4e:0x2d DW_TAG_subprogram 365 .byte 1 # DW_AT_ranges 366 .byte 1 # DW_AT_frame_base 367 .byte 86 368 .byte 6 # DW_AT_name 369 .byte 0 # DW_AT_decl_file 370 .byte 9 # DW_AT_decl_line 371 .long 123 # DW_AT_type 372 # DW_AT_external 373 .byte 3 # Abbrev [3] 0x59:0xb DW_TAG_formal_parameter 374 .byte 2 # DW_AT_location 375 .byte 145 376 .byte 120 377 .byte 7 # DW_AT_name 378 .byte 0 # DW_AT_decl_file 379 .byte 9 # DW_AT_decl_line 380 .long 123 # DW_AT_type 381 .byte 3 # Abbrev [3] 0x64:0xb DW_TAG_formal_parameter 382 .byte 2 # DW_AT_location 383 .byte 145 384 .byte 112 385 .byte 9 # DW_AT_name 386 .byte 0 # DW_AT_decl_file 387 .byte 9 # DW_AT_decl_line 388 .long 127 # DW_AT_type 389 .byte 4 # Abbrev [4] 0x6f:0xb DW_TAG_variable 390 .byte 2 # DW_AT_location 391 .byte 145 392 .byte 108 393 .byte 8 # DW_AT_name 394 .byte 0 # DW_AT_decl_file 395 .byte 10 # DW_AT_decl_line 396 .long 123 # DW_AT_type 397 .byte 0 # End Of Children Mark 398 .byte 6 # Abbrev [6] 0x7b:0x4 DW_TAG_base_type 399 .byte 5 # DW_AT_name 400 .byte 5 # DW_AT_encoding 401 .byte 4 # DW_AT_byte_size 402 .byte 7 # Abbrev [7] 0x7f:0x5 DW_TAG_pointer_type 403 .long 132 # DW_AT_type 404 .byte 7 # Abbrev [7] 0x84:0x5 DW_TAG_pointer_type 405 .long 137 # DW_AT_type 406 .byte 6 # Abbrev [6] 0x89:0x4 DW_TAG_base_type 407 .byte 10 # DW_AT_name 408 .byte 6 # DW_AT_encoding 409 .byte 1 # DW_AT_byte_size 410 .byte 0 # End Of Children Mark 411.Ldebug_info_end0: 412 .section .debug_rnglists,"",@progbits 413 .long .Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length 414.Ldebug_list_header_start0: 415 .short 5 # Version 416 .byte 8 # Address size 417 .byte 0 # Segment selector size 418 .long 3 # Offset entry count 419.Lrnglists_table_base0: 420 .long .Ldebug_ranges0-.Lrnglists_table_base0 421 .long .Ldebug_ranges1-.Lrnglists_table_base0 422 .long .Ldebug_ranges2-.Lrnglists_table_base0 423.Ldebug_ranges0: 424 .byte 3 # DW_RLE_startx_length 425 .byte 0 # start index 426 .uleb128 .LBB_END0_1-_Z6helperi.__part.1 # length 427 .byte 3 # DW_RLE_startx_length 428 .byte 1 # start index 429 .uleb128 .LBB_END0_2-_Z6helperi.__part.2 # length 430 .byte 3 # DW_RLE_startx_length 431 .byte 2 # start index 432 .uleb128 .LBB_END0_3-_Z6helperi.__part.3 # length 433 .byte 3 # DW_RLE_startx_length 434 .byte 3 # start index 435 .uleb128 .Lfunc_end0-.Lfunc_begin0 # length 436 .byte 0 # DW_RLE_end_of_list 437.Ldebug_ranges1: 438 .byte 3 # DW_RLE_startx_length 439 .byte 4 # start index 440 .uleb128 .LBB_END1_1-main.__part.1 # length 441 .byte 3 # DW_RLE_startx_length 442 .byte 5 # start index 443 .uleb128 .LBB_END1_2-main.__part.2 # length 444 .byte 3 # DW_RLE_startx_length 445 .byte 6 # start index 446 .uleb128 .LBB_END1_3-main.__part.3 # length 447 .byte 3 # DW_RLE_startx_length 448 .byte 7 # start index 449 .uleb128 .Lfunc_end1-.Lfunc_begin1 # length 450 .byte 0 # DW_RLE_end_of_list 451.Ldebug_ranges2: 452 .byte 3 # DW_RLE_startx_length 453 .byte 0 # start index 454 .uleb128 .LBB_END0_1-_Z6helperi.__part.1 # length 455 .byte 3 # DW_RLE_startx_length 456 .byte 1 # start index 457 .uleb128 .LBB_END0_2-_Z6helperi.__part.2 # length 458 .byte 3 # DW_RLE_startx_length 459 .byte 2 # start index 460 .uleb128 .LBB_END0_3-_Z6helperi.__part.3 # length 461 .byte 3 # DW_RLE_startx_length 462 .byte 3 # start index 463 .uleb128 .Lfunc_end0-.Lfunc_begin0 # length 464 .byte 3 # DW_RLE_startx_length 465 .byte 4 # start index 466 .uleb128 .LBB_END1_1-main.__part.1 # length 467 .byte 3 # DW_RLE_startx_length 468 .byte 5 # start index 469 .uleb128 .LBB_END1_2-main.__part.2 # length 470 .byte 3 # DW_RLE_startx_length 471 .byte 6 # start index 472 .uleb128 .LBB_END1_3-main.__part.3 # length 473 .byte 3 # DW_RLE_startx_length 474 .byte 7 # start index 475 .uleb128 .Lfunc_end1-.Lfunc_begin1 # length 476 .byte 0 # DW_RLE_end_of_list 477.Ldebug_list_header_end0: 478 .section .debug_str_offsets,"",@progbits 479 .long 48 # Length of String Offsets Set 480 .short 5 481 .short 0 482.Lstr_offsets_base0: 483 .section .debug_str,"MS",@progbits,1 484.Linfo_string0: 485 .asciz "clang version 19.0.0git (git@github.com:ayermolo/llvm-project.git a1d8664d409cac2a923176a8e9a731385bde279e)" # string offset=0 486.Linfo_string1: 487 .asciz "main.cpp" # string offset=108 488.Linfo_string2: 489 .asciz "/repro2" # string offset=117 490.Linfo_string3: 491 .asciz "_Z6helperi" # string offset=162 492.Linfo_string4: 493 .asciz "helper" # string offset=173 494.Linfo_string5: 495 .asciz "int" # string offset=180 496.Linfo_string6: 497 .asciz "main" # string offset=184 498.Linfo_string7: 499 .asciz "argc" # string offset=189 500.Linfo_string8: 501 .asciz "x" # string offset=194 502.Linfo_string9: 503 .asciz "argv" # string offset=196 504.Linfo_string10: 505 .asciz "char" # string offset=201 506 .section .debug_str_offsets,"",@progbits 507 .long .Linfo_string0 508 .long .Linfo_string1 509 .long .Linfo_string2 510 .long .Linfo_string3 511 .long .Linfo_string4 512 .long .Linfo_string5 513 .long .Linfo_string6 514 .long .Linfo_string7 515 .long .Linfo_string8 516 .long .Linfo_string9 517 .long .Linfo_string10 518 .section .debug_addr,"",@progbits 519 .long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution 520.Ldebug_addr_start0: 521 .short 5 # DWARF version number 522 .byte 8 # Address size 523 .byte 0 # Segment selector size 524.Laddr_table_base0: 525 .quad _Z6helperi.__part.1 526 .quad _Z6helperi.__part.2 527 .quad _Z6helperi.__part.3 528 .quad .Lfunc_begin0 529 .quad main.__part.1 530 .quad main.__part.2 531 .quad main.__part.3 532 .quad .Lfunc_begin1 533.Ldebug_addr_end0: 534 .ident "clang version 19.0.0git (git@github.com:ayermolo/llvm-project.git a1d8664d409cac2a923176a8e9a731385bde279e)" 535 .section ".note.GNU-stack","",@progbits 536 .addrsig 537 .section .debug_line,"",@progbits 538.Lline_table_start0: 539