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 5# RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections --skip-funcs=main 6# RUN: llvm-dwarfdump --show-form --verbose --debug-loclists --debug-addr %t.bolt > %t.txt 7# RUN: llvm-dwarfdump --show-form --verbose --debug-info %t.bolt >> %t.txt 8# RUN: cat %t.txt | FileCheck --check-prefix=POSTCHECK %s 9 10## Tests to make sure BOLT handles correctly locations that are out of order, and the function is not being processed. 11 12# POSTCHECK: DW_LLE_base_addressx 13# POSTCHECK-NEXT: DW_LLE_offset_pair 14# POSTCHECK-NEXT: DW_LLE_offset_pair 15# POSTCHECK-NEXT: DW_LLE_startx_length 16# POSTCHECK-NEXT: DW_LLE_end_of_list 17# POSTCHECK: DW_LLE_base_addressx 18# POSTCHECK-NEXT: DW_LLE_offset_pair 19# POSTCHECK-NEXT: DW_LLE_offset_pair 20# POSTCHECK-NEXT: DW_LLE_end_of_list 21 22# POSTCHECK: Addrs: [ 23# POSTCHECK-NEXT: 0x[[#%.16x,ADDR:]] 24# POSTCHECK-NEXT: 0x 25# POSTCHECK-NEXT: 0x 26# POSTCHECK-NEXT: 0x[[#%.16x,ADDR1:]] 27# POSTCHECK-NEXT: 0x 28# POSTCHECK-NEXT: 0x 29 30# POSTCHECK: DW_TAG_formal_parameter 31# POSTCHECK: DW_TAG_formal_parameter 32# POSTCHECK-NEXT: DW_AT_location 33# POSTCHECK-NEXT: [0x[[#ADDR1]], 0x[[#ADDR1 + 0x1a]]): DW_OP_reg3 RBX 34# POSTCHECK-NEXT: [0x[[#ADDR1 + 0x1a]], 0x[[#ADDR1 + 0x1d]]): DW_OP_entry_value(DW_OP_reg5 RDI), DW_OP_stack_value 35# POSTCHECK-NEXT: [0x[[#ADDR]], 0x[[#ADDR + 0x12]]): DW_OP_reg5 RDI) 36 37## clang++ main.cpp -fno-inline-functions -g2 -O2 -S 38## void use(int * x) { 39## *x += 4; 40## } 41## int main(int argc, char *argv[]) { 42## int x = argc; 43## use(&x); 44## x = x + argc; 45## use(&x); 46## return x; 47## } 48 49## Test was manually modified to re-order locations. 50 .text 51 .file "main.cpp" 52 .globl _Z3usePi # -- Begin function _Z3usePi 53 .p2align 4, 0x90 54 .type _Z3usePi,@function 55_Z3usePi: # @_Z3usePi 56.Lfunc_begin0: 57 .file 0 "/repro" "main.cpp" md5 0xe24a1d6afb5e23ce0028f1f33bc08cd7 58 .cfi_startproc 59# %bb.0: # %entry 60 #DEBUG_VALUE: use:x <- $rdi 61 .loc 0 2 8 prologue_end # main.cpp:2:8 62 addl $4, (%rdi) 63 .loc 0 3 1 # main.cpp:3:1 64 retq 65.Ltmp0: 66.Lfunc_end0: 67 .size _Z3usePi, .Lfunc_end0-_Z3usePi 68 .cfi_endproc 69 # -- End function 70 .globl main # -- Begin function main 71 .p2align 4, 0x90 72 .type main,@function 73main: # @main 74.Lfunc_begin1: 75 .loc 0 4 0 # main.cpp:4:0 76 .cfi_startproc 77# %bb.0: # %entry 78 #DEBUG_VALUE: main:argc <- $edi 79 #DEBUG_VALUE: main:argv <- $rsi 80 pushq %r14 81 .cfi_def_cfa_offset 16 82 pushq %rbx 83 .cfi_def_cfa_offset 24 84 pushq %rax 85 .cfi_def_cfa_offset 32 86 .cfi_offset %rbx, -24 87 .cfi_offset %r14, -16 88 movl %edi, %ebx 89.Ltmp1: 90 .loc 0 5 7 prologue_end # main.cpp:5:7 91 movl %edi, 4(%rsp) 92 leaq 4(%rsp), %r14 93 .loc 0 6 3 # main.cpp:6:3 94 movq %r14, %rdi 95.Ltmp2: 96 #DEBUG_VALUE: main:argc <- $ebx 97 callq _Z3usePi 98.Ltmp3: 99 #DEBUG_VALUE: main:argv <- [DW_OP_LLVM_entry_value 1] $rsi 100 .loc 0 7 5 # main.cpp:7:5 101 addl %ebx, 4(%rsp) 102 .loc 0 8 3 # main.cpp:8:3 103 movq %r14, %rdi 104 callq _Z3usePi 105.Ltmp4: 106 .loc 0 9 10 # main.cpp:9:10 107 movl 4(%rsp), %eax 108 .loc 0 9 3 epilogue_begin is_stmt 0 # main.cpp:9:3 109 addq $8, %rsp 110 .cfi_def_cfa_offset 24 111 popq %rbx 112.Ltmp5: 113 #DEBUG_VALUE: main:argc <- [DW_OP_LLVM_entry_value 1] $edi 114 .cfi_def_cfa_offset 16 115 popq %r14 116 .cfi_def_cfa_offset 8 117 retq 118.Ltmp6: 119.Lfunc_end1: 120 .size main, .Lfunc_end1-main 121 .cfi_endproc 122 # -- End function 123 .section .debug_loclists,"",@progbits 124 .long .Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length 125.Ldebug_list_header_start0: 126 .short 5 # Version 127 .byte 8 # Address size 128 .byte 0 # Segment selector size 129 .long 2 # Offset entry count 130.Lloclists_table_base0: 131 .long .Ldebug_loc0-.Lloclists_table_base0 132 .long .Ldebug_loc1-.Lloclists_table_base0 133.Ldebug_loc0: 134 .byte 4 # DW_LLE_offset_pair 135 .uleb128 .Ltmp2-.Lfunc_begin0 # starting offset 136 .uleb128 .Ltmp5-.Lfunc_begin0 # ending offset 137 .byte 1 # Loc expr size 138 .byte 83 # super-register DW_OP_reg3 139 .byte 4 # DW_LLE_offset_pair 140 .uleb128 .Ltmp5-.Lfunc_begin0 # starting offset 141 .uleb128 .Lfunc_end1-.Lfunc_begin0 # ending offset 142 .byte 4 # Loc expr size 143 .byte 163 # DW_OP_entry_value 144 .byte 1 # 1 145 .byte 85 # super-register DW_OP_reg5 146 .byte 159 # DW_OP_stack_value 147 .byte 4 # DW_LLE_offset_pair #manually moved out of order 148 .uleb128 .Lfunc_begin1-.Lfunc_begin0 # starting offset 149 .uleb128 .Ltmp2-.Lfunc_begin0 # ending offset 150 .byte 1 # Loc expr size 151 .byte 85 # super-register DW_OP_reg5 152 .byte 0 # DW_LLE_end_of_list 153.Ldebug_loc1: 154 .byte 4 # DW_LLE_offset_pair 155 .uleb128 .Lfunc_begin1-.Lfunc_begin0 # starting offset 156 .uleb128 .Ltmp3-.Lfunc_begin0 # ending offset 157 .byte 1 # Loc expr size 158 .byte 84 # DW_OP_reg4 159 .byte 4 # DW_LLE_offset_pair 160 .uleb128 .Ltmp3-.Lfunc_begin0 # starting offset 161 .uleb128 .Lfunc_end1-.Lfunc_begin0 # ending offset 162 .byte 4 # Loc expr size 163 .byte 163 # DW_OP_entry_value 164 .byte 1 # 1 165 .byte 84 # DW_OP_reg4 166 .byte 159 # DW_OP_stack_value 167 .byte 0 # DW_LLE_end_of_list 168.Ldebug_list_header_end0: 169 .section .debug_abbrev,"",@progbits 170 .byte 1 # Abbreviation Code 171 .byte 17 # DW_TAG_compile_unit 172 .byte 1 # DW_CHILDREN_yes 173 .byte 37 # DW_AT_producer 174 .byte 37 # DW_FORM_strx1 175 .byte 19 # DW_AT_language 176 .byte 5 # DW_FORM_data2 177 .byte 3 # DW_AT_name 178 .byte 37 # DW_FORM_strx1 179 .byte 114 # DW_AT_str_offsets_base 180 .byte 23 # DW_FORM_sec_offset 181 .byte 16 # DW_AT_stmt_list 182 .byte 23 # DW_FORM_sec_offset 183 .byte 27 # DW_AT_comp_dir 184 .byte 37 # DW_FORM_strx1 185 .byte 17 # DW_AT_low_pc 186 .byte 27 # DW_FORM_addrx 187 .byte 18 # DW_AT_high_pc 188 .byte 6 # DW_FORM_data4 189 .byte 115 # DW_AT_addr_base 190 .byte 23 # DW_FORM_sec_offset 191 .ascii "\214\001" # DW_AT_loclists_base 192 .byte 23 # DW_FORM_sec_offset 193 .byte 0 # EOM(1) 194 .byte 0 # EOM(2) 195 .byte 2 # Abbreviation Code 196 .byte 46 # DW_TAG_subprogram 197 .byte 1 # DW_CHILDREN_yes 198 .byte 17 # DW_AT_low_pc 199 .byte 27 # DW_FORM_addrx 200 .byte 18 # DW_AT_high_pc 201 .byte 6 # DW_FORM_data4 202 .byte 64 # DW_AT_frame_base 203 .byte 24 # DW_FORM_exprloc 204 .byte 122 # DW_AT_call_all_calls 205 .byte 25 # DW_FORM_flag_present 206 .byte 110 # DW_AT_linkage_name 207 .byte 37 # DW_FORM_strx1 208 .byte 3 # DW_AT_name 209 .byte 37 # DW_FORM_strx1 210 .byte 58 # DW_AT_decl_file 211 .byte 11 # DW_FORM_data1 212 .byte 59 # DW_AT_decl_line 213 .byte 11 # DW_FORM_data1 214 .byte 63 # DW_AT_external 215 .byte 25 # DW_FORM_flag_present 216 .byte 0 # EOM(1) 217 .byte 0 # EOM(2) 218 .byte 3 # Abbreviation Code 219 .byte 5 # DW_TAG_formal_parameter 220 .byte 0 # DW_CHILDREN_no 221 .byte 2 # DW_AT_location 222 .byte 24 # DW_FORM_exprloc 223 .byte 3 # DW_AT_name 224 .byte 37 # DW_FORM_strx1 225 .byte 58 # DW_AT_decl_file 226 .byte 11 # DW_FORM_data1 227 .byte 59 # DW_AT_decl_line 228 .byte 11 # DW_FORM_data1 229 .byte 73 # DW_AT_type 230 .byte 19 # DW_FORM_ref4 231 .byte 0 # EOM(1) 232 .byte 0 # EOM(2) 233 .byte 4 # Abbreviation Code 234 .byte 46 # DW_TAG_subprogram 235 .byte 1 # DW_CHILDREN_yes 236 .byte 17 # DW_AT_low_pc 237 .byte 27 # DW_FORM_addrx 238 .byte 18 # DW_AT_high_pc 239 .byte 6 # DW_FORM_data4 240 .byte 64 # DW_AT_frame_base 241 .byte 24 # DW_FORM_exprloc 242 .byte 122 # DW_AT_call_all_calls 243 .byte 25 # DW_FORM_flag_present 244 .byte 3 # DW_AT_name 245 .byte 37 # DW_FORM_strx1 246 .byte 58 # DW_AT_decl_file 247 .byte 11 # DW_FORM_data1 248 .byte 59 # DW_AT_decl_line 249 .byte 11 # DW_FORM_data1 250 .byte 73 # DW_AT_type 251 .byte 19 # DW_FORM_ref4 252 .byte 63 # DW_AT_external 253 .byte 25 # DW_FORM_flag_present 254 .byte 0 # EOM(1) 255 .byte 0 # EOM(2) 256 .byte 5 # Abbreviation Code 257 .byte 5 # DW_TAG_formal_parameter 258 .byte 0 # DW_CHILDREN_no 259 .byte 2 # DW_AT_location 260 .byte 34 # DW_FORM_loclistx 261 .byte 3 # DW_AT_name 262 .byte 37 # DW_FORM_strx1 263 .byte 58 # DW_AT_decl_file 264 .byte 11 # DW_FORM_data1 265 .byte 59 # DW_AT_decl_line 266 .byte 11 # DW_FORM_data1 267 .byte 73 # DW_AT_type 268 .byte 19 # DW_FORM_ref4 269 .byte 0 # EOM(1) 270 .byte 0 # EOM(2) 271 .byte 6 # Abbreviation Code 272 .byte 52 # DW_TAG_variable 273 .byte 0 # DW_CHILDREN_no 274 .byte 2 # DW_AT_location 275 .byte 24 # DW_FORM_exprloc 276 .byte 3 # DW_AT_name 277 .byte 37 # DW_FORM_strx1 278 .byte 58 # DW_AT_decl_file 279 .byte 11 # DW_FORM_data1 280 .byte 59 # DW_AT_decl_line 281 .byte 11 # DW_FORM_data1 282 .byte 73 # DW_AT_type 283 .byte 19 # DW_FORM_ref4 284 .byte 0 # EOM(1) 285 .byte 0 # EOM(2) 286 .byte 7 # Abbreviation Code 287 .byte 72 # DW_TAG_call_site 288 .byte 1 # DW_CHILDREN_yes 289 .byte 127 # DW_AT_call_origin 290 .byte 19 # DW_FORM_ref4 291 .byte 125 # DW_AT_call_return_pc 292 .byte 27 # DW_FORM_addrx 293 .byte 0 # EOM(1) 294 .byte 0 # EOM(2) 295 .byte 8 # Abbreviation Code 296 .byte 73 # DW_TAG_call_site_parameter 297 .byte 0 # DW_CHILDREN_no 298 .byte 2 # DW_AT_location 299 .byte 24 # DW_FORM_exprloc 300 .byte 126 # DW_AT_call_value 301 .byte 24 # DW_FORM_exprloc 302 .byte 0 # EOM(1) 303 .byte 0 # EOM(2) 304 .byte 9 # Abbreviation Code 305 .byte 36 # DW_TAG_base_type 306 .byte 0 # DW_CHILDREN_no 307 .byte 3 # DW_AT_name 308 .byte 37 # DW_FORM_strx1 309 .byte 62 # DW_AT_encoding 310 .byte 11 # DW_FORM_data1 311 .byte 11 # DW_AT_byte_size 312 .byte 11 # DW_FORM_data1 313 .byte 0 # EOM(1) 314 .byte 0 # EOM(2) 315 .byte 10 # Abbreviation Code 316 .byte 15 # DW_TAG_pointer_type 317 .byte 0 # DW_CHILDREN_no 318 .byte 73 # DW_AT_type 319 .byte 19 # DW_FORM_ref4 320 .byte 0 # EOM(1) 321 .byte 0 # EOM(2) 322 .byte 0 # EOM(3) 323 .section .debug_info,"",@progbits 324.Lcu_begin0: 325 .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit 326.Ldebug_info_start0: 327 .short 5 # DWARF version number 328 .byte 1 # DWARF Unit Type 329 .byte 8 # Address Size (in bytes) 330 .long .debug_abbrev # Offset Into Abbrev. Section 331 .byte 1 # Abbrev [1] 0xc:0x91 DW_TAG_compile_unit 332 .byte 0 # DW_AT_producer 333 .short 33 # DW_AT_language 334 .byte 1 # DW_AT_name 335 .long .Lstr_offsets_base0 # DW_AT_str_offsets_base 336 .long .Lline_table_start0 # DW_AT_stmt_list 337 .byte 2 # DW_AT_comp_dir 338 .byte 0 # DW_AT_low_pc 339 .long .Lfunc_end1-.Lfunc_begin0 # DW_AT_high_pc 340 .long .Laddr_table_base0 # DW_AT_addr_base 341 .long .Lloclists_table_base0 # DW_AT_loclists_base 342 .byte 2 # Abbrev [2] 0x27:0x17 DW_TAG_subprogram 343 .byte 0 # DW_AT_low_pc 344 .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc 345 .byte 1 # DW_AT_frame_base 346 .byte 87 347 # DW_AT_call_all_calls 348 .byte 3 # DW_AT_linkage_name 349 .byte 4 # DW_AT_name 350 .byte 0 # DW_AT_decl_file 351 .byte 1 # DW_AT_decl_line 352 # DW_AT_external 353 .byte 3 # Abbrev [3] 0x33:0xa DW_TAG_formal_parameter 354 .byte 1 # DW_AT_location 355 .byte 85 356 .byte 7 # DW_AT_name 357 .byte 0 # DW_AT_decl_file 358 .byte 1 # DW_AT_decl_line 359 .long 137 # DW_AT_type 360 .byte 0 # End Of Children Mark 361 .byte 4 # Abbrev [4] 0x3e:0x47 DW_TAG_subprogram 362 .byte 1 # DW_AT_low_pc 363 .long .Lfunc_end1-.Lfunc_begin1 # DW_AT_high_pc 364 .byte 1 # DW_AT_frame_base 365 .byte 87 366 # DW_AT_call_all_calls 367 .byte 5 # DW_AT_name 368 .byte 0 # DW_AT_decl_file 369 .byte 4 # DW_AT_decl_line 370 .long 133 # DW_AT_type 371 # DW_AT_external 372 .byte 5 # Abbrev [5] 0x4d:0x9 DW_TAG_formal_parameter 373 .byte 0 # DW_AT_location 374 .byte 8 # DW_AT_name 375 .byte 0 # DW_AT_decl_file 376 .byte 4 # DW_AT_decl_line 377 .long 133 # DW_AT_type 378 .byte 5 # Abbrev [5] 0x56:0x9 DW_TAG_formal_parameter 379 .byte 1 # DW_AT_location 380 .byte 9 # DW_AT_name 381 .byte 0 # DW_AT_decl_file 382 .byte 4 # DW_AT_decl_line 383 .long 142 # DW_AT_type 384 .byte 6 # Abbrev [6] 0x5f:0xb DW_TAG_variable 385 .byte 2 # DW_AT_location 386 .byte 145 387 .byte 4 388 .byte 7 # DW_AT_name 389 .byte 0 # DW_AT_decl_file 390 .byte 5 # DW_AT_decl_line 391 .long 133 # DW_AT_type 392 .byte 7 # Abbrev [7] 0x6a:0xd DW_TAG_call_site 393 .long 39 # DW_AT_call_origin 394 .byte 2 # DW_AT_call_return_pc 395 .byte 8 # Abbrev [8] 0x70:0x6 DW_TAG_call_site_parameter 396 .byte 1 # DW_AT_location 397 .byte 85 398 .byte 2 # DW_AT_call_value 399 .byte 126 400 .byte 0 401 .byte 0 # End Of Children Mark 402 .byte 7 # Abbrev [7] 0x77:0xd DW_TAG_call_site 403 .long 39 # DW_AT_call_origin 404 .byte 3 # DW_AT_call_return_pc 405 .byte 8 # Abbrev [8] 0x7d:0x6 DW_TAG_call_site_parameter 406 .byte 1 # DW_AT_location 407 .byte 85 408 .byte 2 # DW_AT_call_value 409 .byte 126 410 .byte 0 411 .byte 0 # End Of Children Mark 412 .byte 0 # End Of Children Mark 413 .byte 9 # Abbrev [9] 0x85:0x4 DW_TAG_base_type 414 .byte 6 # DW_AT_name 415 .byte 5 # DW_AT_encoding 416 .byte 4 # DW_AT_byte_size 417 .byte 10 # Abbrev [10] 0x89:0x5 DW_TAG_pointer_type 418 .long 133 # DW_AT_type 419 .byte 10 # Abbrev [10] 0x8e:0x5 DW_TAG_pointer_type 420 .long 147 # DW_AT_type 421 .byte 10 # Abbrev [10] 0x93:0x5 DW_TAG_pointer_type 422 .long 152 # DW_AT_type 423 .byte 9 # Abbrev [9] 0x98:0x4 DW_TAG_base_type 424 .byte 10 # DW_AT_name 425 .byte 6 # DW_AT_encoding 426 .byte 1 # DW_AT_byte_size 427 .byte 0 # End Of Children Mark 428.Ldebug_info_end0: 429 .section .debug_str_offsets,"",@progbits 430 .long 48 # Length of String Offsets Set 431 .short 5 432 .short 0 433.Lstr_offsets_base0: 434 .section .debug_str,"MS",@progbits,1 435.Linfo_string0: 436 .asciz "clang version 19.0.0git (git@github.com:ayermolo/llvm-project.git a1e412af2bf4bf613021f72205f249ab2469f08b)" # string offset=0 437.Linfo_string1: 438 .asciz "main.cpp" # string offset=108 439.Linfo_string2: 440 .asciz "/repro" # string offset=117 441.Linfo_string3: 442 .asciz "_Z3usePi" # string offset=161 443.Linfo_string4: 444 .asciz "use" # string offset=170 445.Linfo_string5: 446 .asciz "main" # string offset=174 447.Linfo_string6: 448 .asciz "int" # string offset=179 449.Linfo_string7: 450 .asciz "x" # string offset=183 451.Linfo_string8: 452 .asciz "argc" # string offset=185 453.Linfo_string9: 454 .asciz "argv" # string offset=190 455.Linfo_string10: 456 .asciz "char" # string offset=195 457 .section .debug_str_offsets,"",@progbits 458 .long .Linfo_string0 459 .long .Linfo_string1 460 .long .Linfo_string2 461 .long .Linfo_string3 462 .long .Linfo_string4 463 .long .Linfo_string5 464 .long .Linfo_string6 465 .long .Linfo_string7 466 .long .Linfo_string8 467 .long .Linfo_string9 468 .long .Linfo_string10 469 .section .debug_addr,"",@progbits 470 .long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution 471.Ldebug_addr_start0: 472 .short 5 # DWARF version number 473 .byte 8 # Address size 474 .byte 0 # Segment selector size 475.Laddr_table_base0: 476 .quad .Lfunc_begin0 477 .quad .Lfunc_begin1 478 .quad .Ltmp3 479 .quad .Ltmp4 480.Ldebug_addr_end0: 481 .ident "clang version 19.0.0git (git@github.com:ayermolo/llvm-project.git a1e412af2bf4bf613021f72205f249ab2469f08b)" 482 .section ".note.GNU-stack","",@progbits 483 .addrsig 484 .section .debug_line,"",@progbits 485.Lline_table_start0: 486