From 9bd3ff8bf9e05e7bf95a4a068aa3b50813a93975 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 26 May 2023 12:05:09 -0700 Subject: [PATCH] Fix -u option in dsymutil, to not emit an extra DW_LNE_set_address if the original line table was empty With dsymutil's -u option, only the accelerator tables should be updated, but with https://reviews.llvm.org/D150554 the -u option will still re-generate the line table. If the line table was empty, that is, it was a dummy line table, with no entries in it, dsymutil will always generate a line table with a DW_LNE_end_sequence, a funky side effect of this is that when the line table is re-generated, it will always emit a DW_LNE_set_address first, which will change the line table total size. This patch addresses this by making sure that if all the line table has in it is a DW_LNE_end_sequence, it is the same as a dummy entry. Differential Revision: https://reviews.llvm.org/D151579 --- llvm/lib/DWARFLinker/DWARFLinker.cpp | 4 + llvm/test/tools/dsymutil/ARM/fat-dylib-update.test | 155 +++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 llvm/test/tools/dsymutil/ARM/fat-dylib-update.test diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp index af2e0db..363cff4 100644 --- a/llvm/lib/DWARFLinker/DWARFLinker.cpp +++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp @@ -2082,6 +2082,10 @@ void DWARFLinker::DIECloner::generateLineTableForUnit(CompileUnit &Unit) { // Set Line Table Rows. if (Linker.Options.Update) { LineTable.Rows = LT->Rows; + // If all the line table contains is a DW_LNE_end_sequence, clear the line + // table rows, it will be inserted again in the DWARFStreamer. + if (LineTable.Rows.size() == 1 && LineTable.Rows[0].EndSequence) + LineTable.Rows.clear(); LineTable.Sequences = LT->Sequences; } else { diff --git a/llvm/test/tools/dsymutil/ARM/fat-dylib-update.test b/llvm/test/tools/dsymutil/ARM/fat-dylib-update.test new file mode 100644 index 0000000..fbe8f29 --- /dev/null +++ b/llvm/test/tools/dsymutil/ARM/fat-dylib-update.test @@ -0,0 +1,155 @@ +# REQUIRES: object-emission +# RUN: dsymutil -oso-prepend-path %p/.. %p/../Inputs/fat-test.arm.dylib -o %t.dSYM +# RUN: llvm-dwarfdump -a -v %t.dSYM/Contents/Resources/DWARF/fat-test.arm.dylib | FileCheck %s +# RUN: dsymutil -u %t.dSYM +# RUN: llvm-dwarfdump -a -v %t.dSYM/Contents/Resources/DWARF/fat-test.arm.dylib | FileCheck %s +# RUN: dsymutil -u %t.dSYM -o %t1.dSYM +# RUN: llvm-dwarfdump -a -v %t1.dSYM/Contents/Resources/DWARF/fat-test.arm.dylib | FileCheck %s + +CHECK: /Contents/Resources/DWARF/fat-test.arm.dylib(armv7): file format Mach-O arm + +CHECK: .debug_info contents: +CHECK: Compile Unit: length = 0x00000034, format = DWARF32, version = 0x0002, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x00000038) +CHECK: DW_TAG_compile_unit [1] * +CHECK: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000001] = "clang version 3.8.0 (trunk 243776)") +CHECK: DW_AT_language [DW_FORM_data2] (DW_LANG_C99) +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000024] = "fat-test.c") +CHECK: DW_AT_stmt_list [DW_FORM_data4] (0x00000000) +CHECK: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000002f] = "/Inputs") +CHECK: DW_TAG_variable [2] +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000037] = "armv7_var") +CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x0030 => {0x00000030} +CHECK: DW_AT_external [DW_FORM_flag] (0x01) +CHECK: DW_AT_decl_file [DW_FORM_data1] ("/Inputs/fat-test.c") +CHECK: DW_AT_decl_line [DW_FORM_data1] (23) +CHECK: DW_AT_location [DW_FORM_block1] (DW_OP_addr 0x1000) +CHECK: DW_TAG_base_type [3] +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000041] = "int") +CHECK: DW_AT_encoding [DW_FORM_data1] (DW_ATE_signed) +CHECK: DW_AT_byte_size [DW_FORM_data1] (0x04) +CHECK: NULL + + +CHECK: .debug_line contents: +CHECK: Line table prologue: +CHECK: total_length: 0x0000002a +CHECK: version: 2 +CHECK: prologue_length: 0x00000021 +CHECK: min_inst_length: 1 +CHECK: default_is_stmt: 1 +CHECK: line_base: -5 +CHECK: line_range: 14 +CHECK: opcode_base: 13 + +CHECK: .apple_names contents: +CHECK: String: 0x00000037 "armv7_var" +CHECK-NEXT: Data 0 [ +CHECK-NEXT: Atom[0]: 0x0000001e +CHECK-NEXT: ] + +CHECK: .apple_types contents: +CHECK: String: 0x00000041 "int" +CHECK-NEXT: Data 0 [ +CHECK-NEXT: Atom[0]: 0x00000030 +CHECK-NEXT: Atom[1]: 0x0024 +CHECK-NEXT: Atom[2]: 0x00 +CHECK-NEXT: Atom[3]: 0x0c3a28a4 +CHECK-NEXT: ] + +CHECK: /Contents/Resources/DWARF/fat-test.arm.dylib(armv7s): file format Mach-O arm + +CHECK: .debug_info contents: +CHECK: Compile Unit: length = 0x00000034, format = DWARF32, version = 0x0002, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x00000038) +CHECK: DW_TAG_compile_unit [1] * +CHECK: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000001] = "clang version 3.8.0 (trunk 243776)") +CHECK: DW_AT_language [DW_FORM_data2] (DW_LANG_C99) +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000024] = "fat-test.c") +CHECK: DW_AT_stmt_list [DW_FORM_data4] (0x00000000) +CHECK: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000002f] = "/Inputs") +CHECK: DW_TAG_variable [2] +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000037] = "armv7s_var") +CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x0030 => {0x00000030} +CHECK: DW_AT_external [DW_FORM_flag] (0x01) +CHECK: DW_AT_decl_file [DW_FORM_data1] ("/Inputs/fat-test.c") +CHECK: DW_AT_decl_line [DW_FORM_data1] (21) +CHECK: DW_AT_location [DW_FORM_block1] (DW_OP_addr 0x1000) +CHECK: DW_TAG_base_type [3] +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000042] = "int") +CHECK: DW_AT_encoding [DW_FORM_data1] (DW_ATE_signed) +CHECK: DW_AT_byte_size [DW_FORM_data1] (0x04) +CHECK: NULL + +CHECK: .debug_line contents: +CHECK: Line table prologue: +CHECK: total_length: 0x0000002a +CHECK: version: 2 +CHECK: prologue_length: 0x00000021 +CHECK: min_inst_length: 1 +CHECK: default_is_stmt: 1 +CHECK: line_base: -5 +CHECK: line_range: 14 +CHECK: opcode_base: 13 + +CHECK: .apple_names contents: +CHECK: String: 0x00000037 "armv7s_var" +CHECK-NEXT: Data 0 [ +CHECK-NEXT: Atom[0]: 0x0000001e +CHECK-NEXT: ] + +CHECK: .apple_types contents: +CHECK: String: 0x00000042 "int" +CHECK-NEXT: Data 0 [ +CHECK-NEXT: Atom[0]: 0x00000030 +CHECK-NEXT: Atom[1]: 0x0024 +CHECK-NEXT: Atom[2]: 0x00 +CHECK-NEXT: Atom[3]: 0x0c3a28a4 +CHECK-NEXT: ] + +CHECK: /Contents/Resources/DWARF/fat-test.arm.dylib(arm64): file format Mach-O arm64 + +CHECK: .debug_info contents: +CHECK: Compile Unit: length = 0x00000038, format = DWARF32, version = 0x0002, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000003c) +CHECK: DW_TAG_compile_unit [1] * +CHECK: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000001] = "clang version 3.8.0 (trunk 243776)") +CHECK: DW_AT_language [DW_FORM_data2] (DW_LANG_C99) +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000024] = "fat-test.c") +CHECK: DW_AT_stmt_list [DW_FORM_data4] (0x00000000) +CHECK: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000002f] = "/Inputs") +CHECK: DW_TAG_variable [2] +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000037] = "arm64_var") +CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x0034 => {0x00000034} +CHECK: DW_AT_external [DW_FORM_flag] (0x01) +CHECK: DW_AT_decl_file [DW_FORM_data1] ("/Inputs/fat-test.c") +CHECK: DW_AT_decl_line [DW_FORM_data1] (25) +CHECK: DW_AT_location [DW_FORM_block1] (DW_OP_addr 0x4000) +CHECK: DW_TAG_base_type [3] +CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000041] = "int") +CHECK: DW_AT_encoding [DW_FORM_data1] (DW_ATE_signed) +CHECK: DW_AT_byte_size [DW_FORM_data1] (0x04) +CHECK: NULL + +CHECK: .debug_line contents: +CHECK: Line table prologue: +CHECK: total_length: 0x0000002a +CHECK: version: 2 +CHECK: prologue_length: 0x00000021 +CHECK: min_inst_length: 1 +CHECK: default_is_stmt: 1 +CHECK: line_base: -5 +CHECK: line_range: 14 +CHECK: opcode_base: 13 + +CHECK: .apple_names contents: +CHECK: String: 0x00000037 "arm64_var" +CHECK-NEXT: Data 0 [ +CHECK-NEXT: Atom[0]: 0x0000001e +CHECK-NEXT: ] + +CHECK: .apple_types contents: +CHECK: String: 0x00000041 "int" +CHECK-NEXT: Data 0 [ +CHECK-NEXT: Atom[0]: 0x00000034 +CHECK-NEXT: Atom[1]: 0x0024 +CHECK-NEXT: Atom[2]: 0x00 +CHECK-NEXT: Atom[3]: 0x0c3a28a4 +CHECK-NEXT: ] -- 2.7.4