Index: test/tools/dsymutil/X86/null-die.s =================================================================== --- /dev/null +++ test/tools/dsymutil/X86/null-die.s @@ -0,0 +1,484 @@ +#RUN: llvm-dsymutil -f -oso-prepend-path=%p/../Inputs/ %p/../Inputs/null_die \ +#RUN: -no-output 2>&1 | FileCheck %s + +# CHECK: warning: could not find referenced DIE + +# We've modified the DW_AT_abstract_origin offset to reference a NULL DIE. +# +# Compile: +# llvm-mc -triple x86_64-apple-darwin -filetype=obj -o null_die.o null_die.s +# ld -arch x86_64 -macosx_version_min 10.13.0 -lSystem null_die.o -o null_die + + + .section __TEXT,__text,regular,pure_instructions + .macosx_version_min 10, 13 + .globl _foo ## -- Begin function foo + .p2align 4, 0x90 +_foo: ## @foo +Lfunc_begin0: + .file 1 "null_die.c" + .loc 1 3 0 ## null_die.c:3:0 + .cfi_startproc +## BB#0: ## %entry + pushq %rbp +Lcfi0: + .cfi_def_cfa_offset 16 +Lcfi1: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +Lcfi2: + .cfi_def_cfa_register %rbp + ##DEBUG_VALUE: foo:i <- %EDI + ## kill: %EDI %EDI %RDI +Ltmp0: + ##DEBUG_VALUE: foo:i <- %EDI + .loc 1 4 12 prologue_end ## null_die.c:4:12 + leal 10(%rdi), %eax + .loc 1 4 3 is_stmt 0 ## null_die.c:4:3 + popq %rbp + retq +Ltmp1: +Lfunc_end0: + .cfi_endproc + ## -- End function + .globl _main ## -- Begin function main + .p2align 4, 0x90 +_main: ## @main +Lfunc_begin1: + .loc 1 8 0 is_stmt 1 ## null_die.c:8:0 + .cfi_startproc +## BB#0: ## %entry + pushq %rbp +Lcfi3: + .cfi_def_cfa_offset 16 +Lcfi4: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +Lcfi5: + .cfi_def_cfa_register %rbp + ##DEBUG_VALUE: main:argc <- %EDI + ## kill: %EDI %EDI %RDI +Ltmp2: + ##DEBUG_VALUE: foo:i <- %EDI + ##DEBUG_VALUE: main:argv <- %RSI + ##DEBUG_VALUE: main:argc <- %EDI + .loc 1 4 12 prologue_end ## null_die.c:4:12 + leal 10(%rdi), %eax +Ltmp3: + .loc 1 9 3 ## null_die.c:9:3 + popq %rbp + retq +Ltmp4: +Lfunc_end1: + .cfi_endproc + ## -- End function + .section __DWARF,__debug_str,regular,debug +Linfo_string: + .asciz "clang version 6.0.0 (trunk 313521) (llvm/trunk 313530)" ## string offset=0 + .asciz "null_die.c" ## string offset=55 + .asciz "/private/tmp/dsymtest" ## string offset=66 + .asciz "foo" ## string offset=88 + .asciz "int" ## string offset=92 + .asciz "i" ## string offset=96 + .asciz "main" ## string offset=98 + .asciz "argc" ## string offset=103 + .asciz "argv" ## string offset=108 + .asciz "char" ## string offset=113 + .section __DWARF,__debug_loc,regular,debug +Lsection_debug_loc: +Ldebug_loc0: +Lset0 = Lfunc_begin0-Lfunc_begin0 + .quad Lset0 +Lset1 = Lfunc_end0-Lfunc_begin0 + .quad Lset1 + .short 1 ## Loc expr size + .byte 85 ## super-register DW_OP_reg5 + .quad 0 + .quad 0 +Ldebug_loc1: +Lset2 = Lfunc_begin1-Lfunc_begin0 + .quad Lset2 +Lset3 = Lfunc_end1-Lfunc_begin0 + .quad Lset3 + .short 1 ## Loc expr size + .byte 85 ## super-register DW_OP_reg5 + .quad 0 + .quad 0 + .section __DWARF,__debug_abbrev,regular,debug +Lsection_abbrev: + .byte 1 ## Abbreviation Code + .byte 17 ## DW_TAG_compile_unit + .byte 1 ## DW_CHILDREN_yes + .byte 37 ## DW_AT_producer + .byte 14 ## DW_FORM_strp + .byte 19 ## DW_AT_language + .byte 5 ## DW_FORM_data2 + .byte 3 ## DW_AT_name + .byte 14 ## DW_FORM_strp + .byte 16 ## DW_AT_stmt_list + .byte 23 ## DW_FORM_sec_offset + .byte 27 ## DW_AT_comp_dir + .byte 14 ## DW_FORM_strp + .ascii "\341\177" ## DW_AT_APPLE_optimized + .byte 25 ## DW_FORM_flag_present + .byte 17 ## DW_AT_low_pc + .byte 1 ## DW_FORM_addr + .byte 18 ## DW_AT_high_pc + .byte 6 ## DW_FORM_data4 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 2 ## Abbreviation Code + .byte 46 ## DW_TAG_subprogram + .byte 1 ## DW_CHILDREN_yes + .byte 17 ## DW_AT_low_pc + .byte 1 ## DW_FORM_addr + .byte 18 ## DW_AT_high_pc + .byte 6 ## DW_FORM_data4 + .byte 64 ## DW_AT_frame_base + .byte 24 ## DW_FORM_exprloc + .byte 49 ## DW_AT_abstract_origin + .byte 19 ## DW_FORM_ref4 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 3 ## Abbreviation Code + .byte 5 ## DW_TAG_formal_parameter + .byte 0 ## DW_CHILDREN_no + .byte 2 ## DW_AT_location + .byte 23 ## DW_FORM_sec_offset + .byte 49 ## DW_AT_abstract_origin + .byte 19 ## DW_FORM_ref4 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 4 ## Abbreviation Code + .byte 46 ## DW_TAG_subprogram + .byte 1 ## DW_CHILDREN_yes + .byte 3 ## DW_AT_name + .byte 14 ## DW_FORM_strp + .byte 58 ## DW_AT_decl_file + .byte 11 ## DW_FORM_data1 + .byte 59 ## DW_AT_decl_line + .byte 11 ## DW_FORM_data1 + .byte 39 ## DW_AT_prototyped + .byte 25 ## DW_FORM_flag_present + .byte 73 ## DW_AT_type + .byte 19 ## DW_FORM_ref4 + .byte 63 ## DW_AT_external + .byte 25 ## DW_FORM_flag_present + .ascii "\341\177" ## DW_AT_APPLE_optimized + .byte 25 ## DW_FORM_flag_present + .byte 32 ## DW_AT_inline + .byte 11 ## DW_FORM_data1 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 5 ## Abbreviation Code + .byte 5 ## DW_TAG_formal_parameter + .byte 0 ## DW_CHILDREN_no + .byte 3 ## DW_AT_name + .byte 14 ## DW_FORM_strp + .byte 58 ## DW_AT_decl_file + .byte 11 ## DW_FORM_data1 + .byte 59 ## DW_AT_decl_line + .byte 11 ## DW_FORM_data1 + .byte 73 ## DW_AT_type + .byte 19 ## DW_FORM_ref4 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 6 ## Abbreviation Code + .byte 36 ## DW_TAG_base_type + .byte 0 ## DW_CHILDREN_no + .byte 3 ## DW_AT_name + .byte 14 ## DW_FORM_strp + .byte 62 ## DW_AT_encoding + .byte 11 ## DW_FORM_data1 + .byte 11 ## DW_AT_byte_size + .byte 11 ## DW_FORM_data1 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 7 ## Abbreviation Code + .byte 46 ## DW_TAG_subprogram + .byte 1 ## DW_CHILDREN_yes + .byte 17 ## DW_AT_low_pc + .byte 1 ## DW_FORM_addr + .byte 18 ## DW_AT_high_pc + .byte 6 ## DW_FORM_data4 + .byte 64 ## DW_AT_frame_base + .byte 24 ## DW_FORM_exprloc + .byte 3 ## DW_AT_name + .byte 14 ## DW_FORM_strp + .byte 58 ## DW_AT_decl_file + .byte 11 ## DW_FORM_data1 + .byte 59 ## DW_AT_decl_line + .byte 11 ## DW_FORM_data1 + .byte 39 ## DW_AT_prototyped + .byte 25 ## DW_FORM_flag_present + .byte 73 ## DW_AT_type + .byte 19 ## DW_FORM_ref4 + .byte 63 ## DW_AT_external + .byte 25 ## DW_FORM_flag_present + .ascii "\341\177" ## DW_AT_APPLE_optimized + .byte 25 ## DW_FORM_flag_present + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 8 ## Abbreviation Code + .byte 5 ## DW_TAG_formal_parameter + .byte 0 ## DW_CHILDREN_no + .byte 2 ## DW_AT_location + .byte 23 ## DW_FORM_sec_offset + .byte 3 ## DW_AT_name + .byte 14 ## DW_FORM_strp + .byte 58 ## DW_AT_decl_file + .byte 11 ## DW_FORM_data1 + .byte 59 ## DW_AT_decl_line + .byte 11 ## DW_FORM_data1 + .byte 73 ## DW_AT_type + .byte 19 ## DW_FORM_ref4 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 9 ## Abbreviation Code + .byte 5 ## DW_TAG_formal_parameter + .byte 0 ## DW_CHILDREN_no + .byte 2 ## DW_AT_location + .byte 24 ## DW_FORM_exprloc + .byte 3 ## DW_AT_name + .byte 14 ## DW_FORM_strp + .byte 58 ## DW_AT_decl_file + .byte 11 ## DW_FORM_data1 + .byte 59 ## DW_AT_decl_line + .byte 11 ## DW_FORM_data1 + .byte 73 ## DW_AT_type + .byte 19 ## DW_FORM_ref4 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 10 ## Abbreviation Code + .byte 29 ## DW_TAG_inlined_subroutine + .byte 1 ## DW_CHILDREN_yes + .byte 49 ## DW_AT_abstract_origin + .byte 19 ## DW_FORM_ref4 + .byte 17 ## DW_AT_low_pc + .byte 1 ## DW_FORM_addr + .byte 18 ## DW_AT_high_pc + .byte 6 ## DW_FORM_data4 + .byte 88 ## DW_AT_call_file + .byte 11 ## DW_FORM_data1 + .byte 89 ## DW_AT_call_line + .byte 11 ## DW_FORM_data1 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 11 ## Abbreviation Code + .byte 5 ## DW_TAG_formal_parameter + .byte 0 ## DW_CHILDREN_no + .byte 2 ## DW_AT_location + .byte 24 ## DW_FORM_exprloc + .byte 49 ## DW_AT_abstract_origin + .byte 19 ## DW_FORM_ref4 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 12 ## Abbreviation Code + .byte 15 ## DW_TAG_pointer_type + .byte 0 ## DW_CHILDREN_no + .byte 73 ## DW_AT_type + .byte 19 ## DW_FORM_ref4 + .byte 0 ## EOM(1) + .byte 0 ## EOM(2) + .byte 0 ## EOM(3) + .section __DWARF,__debug_info,regular,debug +Lsection_info: +Lcu_begin0: + .long 197 ## Length of Unit + .short 4 ## DWARF version number +Lset4 = Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section + .long Lset4 + .byte 8 ## Address Size (in bytes) + .byte 1 ## Abbrev [1] 0xb:0xbe DW_TAG_compile_unit + .long 0 ## DW_AT_producer + .short 12 ## DW_AT_language + .long 55 ## DW_AT_name +Lset5 = Lline_table_start0-Lsection_line ## DW_AT_stmt_list + .long Lset5 + .long 66 ## DW_AT_comp_dir + ## DW_AT_APPLE_optimized + .quad Lfunc_begin0 ## DW_AT_low_pc +Lset6 = Lfunc_end1-Lfunc_begin0 ## DW_AT_high_pc + .long Lset6 + .byte 2 ## Abbrev [2] 0x2a:0x1d DW_TAG_subprogram + .quad Lfunc_begin0 ## DW_AT_low_pc +Lset7 = Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc + .long Lset7 + .byte 1 ## DW_AT_frame_base + .byte 86 + .long 70 ## DW_AT_abstract_origin + .byte 3 ## Abbrev [3] 0x3d:0x9 DW_TAG_formal_parameter +Lset8 = Ldebug_loc0-Lsection_debug_loc ## DW_AT_location + .long Lset8 + .long 83 ## DW_AT_abstract_origin + .byte 0 ## End Of Children Mark + .byte 4 ## Abbrev [4] 0x47:0x18 DW_TAG_subprogram + .long 88 ## DW_AT_name + .byte 1 ## DW_AT_decl_file + .byte 2 ## DW_AT_decl_line + ## DW_AT_prototyped + .long 95 ## DW_AT_type + ## DW_AT_external + ## DW_AT_APPLE_optimized + .byte 1 ## DW_AT_inline + .byte 5 ## Abbrev [5] 0x53:0xb DW_TAG_formal_parameter + .long 96 ## DW_AT_name + .byte 1 ## DW_AT_decl_file + .byte 2 ## DW_AT_decl_line + .long 95 ## DW_AT_type + .byte 0 ## End Of Children Mark + .byte 6 ## Abbrev [6] 0x5f:0x7 DW_TAG_base_type + .long 92 ## DW_AT_name + .byte 5 ## DW_AT_encoding + .byte 4 ## DW_AT_byte_size + .byte 7 ## Abbrev [7] 0x66:0x51 DW_TAG_subprogram + .quad Lfunc_begin1 ## DW_AT_low_pc +Lset9 = Lfunc_end1-Lfunc_begin1 ## DW_AT_high_pc + .long Lset9 + .byte 1 ## DW_AT_frame_base + .byte 86 + .long 98 ## DW_AT_name + .byte 1 ## DW_AT_decl_file + .byte 7 ## DW_AT_decl_line + ## DW_AT_prototyped + .long 95 ## DW_AT_type + ## DW_AT_external + ## DW_AT_APPLE_optimized + .byte 8 ## Abbrev [8] 0x7f:0xf DW_TAG_formal_parameter +Lset10 = Ldebug_loc1-Lsection_debug_loc ## DW_AT_location + .long Lset10 + .long 103 ## DW_AT_name + .byte 1 ## DW_AT_decl_file + .byte 7 ## DW_AT_decl_line + .long 95 ## DW_AT_type + .byte 9 ## Abbrev [9] 0x8e:0xd DW_TAG_formal_parameter + .byte 1 ## DW_AT_location + .byte 84 + .long 108 ## DW_AT_name + .byte 1 ## DW_AT_decl_file + .byte 7 ## DW_AT_decl_line + .long 183 ## DW_AT_type + .byte 10 ## Abbrev [10] 0x9b:0x1b DW_TAG_inlined_subroutine + .long 71 ## DW_AT_abstract_origin + .quad Ltmp2 ## DW_AT_low_pc +Lset11 = Ltmp3-Ltmp2 ## DW_AT_high_pc + .long Lset11 + .byte 1 ## DW_AT_call_file + .byte 9 ## DW_AT_call_line + .byte 11 ## Abbrev [11] 0xae:0x7 DW_TAG_formal_parameter + .byte 1 ## DW_AT_location + .byte 85 + .long 83 ## DW_AT_abstract_origin + .byte 0 ## End Of Children Mark + .byte 0 ## End Of Children Mark + .byte 12 ## Abbrev [12] 0xb7:0x5 DW_TAG_pointer_type + .long 188 ## DW_AT_type + .byte 12 ## Abbrev [12] 0xbc:0x5 DW_TAG_pointer_type + .long 193 ## DW_AT_type + .byte 6 ## Abbrev [6] 0xc1:0x7 DW_TAG_base_type + .long 113 ## DW_AT_name + .byte 6 ## DW_AT_encoding + .byte 1 ## DW_AT_byte_size + .byte 0 ## End Of Children Mark + .section __DWARF,__debug_ranges,regular,debug +Ldebug_range: + .section __DWARF,__debug_macinfo,regular,debug +Ldebug_macinfo: +Lcu_macro_begin0: + .byte 0 ## End Of Macro List Mark + .section __DWARF,__apple_names,regular,debug +Lnames_begin: + .long 1212240712 ## Header Magic + .short 1 ## Header Version + .short 0 ## Header Hash Function + .long 2 ## Header Bucket Count + .long 2 ## Header Hash Count + .long 12 ## Header Data Length + .long 0 ## HeaderData Die Offset Base + .long 1 ## HeaderData Atom Count + .short 1 ## DW_ATOM_die_offset + .short 6 ## DW_FORM_data4 + .long 0 ## Bucket 0 + .long 1 ## Bucket 1 + .long 2090499946 ## Hash in Bucket 0 + .long 193491849 ## Hash in Bucket 1 + .long LNames1-Lnames_begin ## Offset in Bucket 0 + .long LNames0-Lnames_begin ## Offset in Bucket 1 +LNames1: + .long 98 ## main + .long 1 ## Num DIEs + .long 102 + .long 0 +LNames0: + .long 88 ## foo + .long 2 ## Num DIEs + .long 42 + .long 155 + .long 0 + .section __DWARF,__apple_objc,regular,debug +Lobjc_begin: + .long 1212240712 ## Header Magic + .short 1 ## Header Version + .short 0 ## Header Hash Function + .long 1 ## Header Bucket Count + .long 0 ## Header Hash Count + .long 12 ## Header Data Length + .long 0 ## HeaderData Die Offset Base + .long 1 ## HeaderData Atom Count + .short 1 ## DW_ATOM_die_offset + .short 6 ## DW_FORM_data4 + .long -1 ## Bucket 0 + .section __DWARF,__apple_namespac,regular,debug +Lnamespac_begin: + .long 1212240712 ## Header Magic + .short 1 ## Header Version + .short 0 ## Header Hash Function + .long 1 ## Header Bucket Count + .long 0 ## Header Hash Count + .long 12 ## Header Data Length + .long 0 ## HeaderData Die Offset Base + .long 1 ## HeaderData Atom Count + .short 1 ## DW_ATOM_die_offset + .short 6 ## DW_FORM_data4 + .long -1 ## Bucket 0 + .section __DWARF,__apple_types,regular,debug +Ltypes_begin: + .long 1212240712 ## Header Magic + .short 1 ## Header Version + .short 0 ## Header Hash Function + .long 2 ## Header Bucket Count + .long 2 ## Header Hash Count + .long 20 ## Header Data Length + .long 0 ## HeaderData Die Offset Base + .long 3 ## HeaderData Atom Count + .short 1 ## DW_ATOM_die_offset + .short 6 ## DW_FORM_data4 + .short 3 ## DW_ATOM_die_tag + .short 5 ## DW_FORM_data2 + .short 4 ## DW_ATOM_type_flags + .short 11 ## DW_FORM_data1 + .long 0 ## Bucket 0 + .long 1 ## Bucket 1 + .long 193495088 ## Hash in Bucket 0 + .long 2090147939 ## Hash in Bucket 1 + .long Ltypes0-Ltypes_begin ## Offset in Bucket 0 + .long Ltypes1-Ltypes_begin ## Offset in Bucket 1 +Ltypes0: + .long 92 ## int + .long 1 ## Num DIEs + .long 95 + .short 36 + .byte 0 + .long 0 +Ltypes1: + .long 113 ## char + .long 1 ## Num DIEs + .long 193 + .short 36 + .byte 0 + .long 0 + +.subsections_via_symbols + .section __DWARF,__debug_line,regular,debug +Lsection_line: +Lline_table_start0: Index: tools/dsymutil/DwarfLinker.cpp =================================================================== --- tools/dsymutil/DwarfLinker.cpp +++ tools/dsymutil/DwarfLinker.cpp @@ -1496,7 +1496,8 @@ if ((RefCU = getUnitForOffset(Units, RefOffset))) if (const auto RefDie = RefCU->getOrigUnit().getDIEForOffset(RefOffset)) - return RefDie; + if(!RefDie.isNULL()) + return RefDie; Linker.reportWarning("could not find referenced DIE", &DIE); return DWARFDie();