[llvm] c5a45b2 - Do not emit a .debug_addr section if the DW_AT_addr_base is not set.
Shubham Sandeep Rastogi via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 22 10:49:21 PDT 2023
Author: Shubham Sandeep Rastogi
Date: 2023-07-22T10:41:44-07:00
New Revision: c5a45b2515e6d2c3d29e86ad41c9be5a88f172d4
URL: https://github.com/llvm/llvm-project/commit/c5a45b2515e6d2c3d29e86ad41c9be5a88f172d4
DIFF: https://github.com/llvm/llvm-project/commit/c5a45b2515e6d2c3d29e86ad41c9be5a88f172d4.diff
LOG: Do not emit a .debug_addr section if the DW_AT_addr_base is not set.
If the DW_AT_addr_base is not set, dsymutil should not copy any addrx
attributes into the cloned DIE, which will result in no .debug_addr
section being emitted.
Differential Revision: https://reviews.llvm.org/D155666
Added:
llvm/test/tools/dsymutil/dwarf5-addrbase-broken.test
Modified:
llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/test/tools/dsymutil/Inputs/invalid.o
Removed:
################################################################################
diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp
index 82984436470b87..d16af3b322d1dd 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -1364,7 +1364,7 @@ unsigned DWARFLinker::DIECloner::cloneAddressAttribute(
std::optional<uint64_t> Addr = AddrAttribute->getAsAddress();
if (!Addr) {
Linker.reportWarning("Cann't read address attribute value.", ObjFile);
- Addr = 0;
+ return 0;
}
if (InputDIE.getTag() == dwarf::DW_TAG_compile_unit &&
diff --git a/llvm/test/tools/dsymutil/Inputs/invalid.o b/llvm/test/tools/dsymutil/Inputs/invalid.o
old mode 100755
new mode 100644
index c009b48d023abb..be9e9f9ba99a4a
Binary files a/llvm/test/tools/dsymutil/Inputs/invalid.o and b/llvm/test/tools/dsymutil/Inputs/invalid.o
diff er
diff --git a/llvm/test/tools/dsymutil/dwarf5-addrbase-broken.test b/llvm/test/tools/dsymutil/dwarf5-addrbase-broken.test
new file mode 100644
index 00000000000000..e648ae0df62483
--- /dev/null
+++ b/llvm/test/tools/dsymutil/dwarf5-addrbase-broken.test
@@ -0,0 +1,284 @@
+## This test checks handling of DWARFv5 address attribute.
+## It contains two compile units. One is a good one and
+## should be processed correctly. Second is a bad - it
+## missing DW_AT_addr_base attribute. All address attributes
+## inside this unit should be skipped.
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: echo '---' > %t2.map
+# RUN: echo "triple: 'x86_64-apple-darwin'" >> %t2.map
+# RUN: echo 'objects:' >> %t2.map
+# RUN: echo " - filename: '%t.o'" >> %t2.map
+# RUN: echo ' symbols:' >> %t2.map
+# RUN: echo ' - { sym: __Z3foov, objAddr: 0x0, binAddr: 0x10000, size: 0x10 }' >> %t2.map
+# RUN: echo '...' >> %t2.map
+# RUN: dsymutil -y %t2.map -f -o - | llvm-dwarfdump -a - | FileCheck %s
+
+# CHECK: file format Mach-O 64-bit x86-64
+# CHECK: .debug_info contents:
+# CHECK: Compile Unit:
+# CHECK: DW_TAG_compile_unit
+# CHECK: DW_AT_name{{.*}}"GoodCU"
+# CHECK: DW_AT_low_pc
+# CHECK: DW_TAG_subprogram
+# CHECK: DW_AT_name{{.*}}"foo"
+# CHECK: DW_TAG_variable
+# CHECK: DW_AT_name{{.*}}"var1"
+# CHECK: DW_AT_location (DW_OP_addr
+# CHECK: 0x0000004e: NULL
+# CHECK: Compile Unit:
+# CHECK: DW_TAG_compile_unit
+# CHECK-NOT: DW_AT_low_pc
+# CHECK: DW_AT_name{{.*}}"BadCU"
+# CHECK-NOT: DW_TAG_subprogram
+# CHECK-NOT: DW_TAG_variable
+# CHECK: 0x0000006b: NULL
+
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x00000003
+ filetype: 0x00000001
+ ncmds: 2
+ sizeofcmds: 472
+ flags: 0x00002000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 312
+ segname: ''
+ vmaddr: 0x00
+ vmsize: 0x300
+ fileoff: 0x300
+ filesize: 0x300
+ maxprot: 7
+ initprot: 7
+ nsects: 3
+ flags: 0
+ Sections:
+ - sectname: __debug_abbrev
+ segname: __DWARF
+ addr: 0x000000000000000F
+ size: 0x60
+ offset: 0x00000210
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __debug_info
+ segname: __DWARF
+ addr: 0x000000000000100
+ size: 0x9e
+ offset: 0x00000310
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __debug_addr
+ segname: __DWARF
+ addr: 0x0000000000000200
+ size: 0x30
+ offset: 0x00000400
+ align: 0
+ reloff: 0x00000600
+ nreloc: 2
+ flags: 0x02000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ relocations:
+ - address: 0x8
+ symbolnum: 1
+ pcrel: true
+ length: 3
+ extern: true
+ type: 0
+ scattered: false
+ value: 0
+ - address: 0x1c
+ symbolnum: 1
+ pcrel: true
+ length: 3
+ extern: true
+ type: 0
+ scattered: false
+ value: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 0x700
+ nsyms: 2
+ stroff: 0x720
+ strsize: 10
+LinkEditData:
+ NameList:
+ - n_strx: 1
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ - n_strx: 1
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ StringTable:
+ - ''
+ - '__Z3foov'
+ - ''
+DWARF:
+ debug_abbrev:
+ - Table:
+ - Tag: DW_TAG_compile_unit
+ Children: DW_CHILDREN_yes
+ Attributes:
+ - Attribute: DW_AT_producer
+ Form: DW_FORM_string
+ - Attribute: DW_AT_language
+ Form: DW_FORM_data2
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addrx
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data8
+ - Attribute: DW_AT_addr_base
+ Form: DW_FORM_sec_offset
+ - Tag: DW_TAG_subprogram
+ Children: DW_CHILDREN_yes
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addrx
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data8
+ - Attribute: DW_AT_type
+ Form: DW_FORM_ref4
+ - Tag: DW_TAG_base_type
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Tag: DW_TAG_variable
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_type
+ Form: DW_FORM_ref4
+ - Attribute: DW_AT_location
+ Form: DW_FORM_exprloc
+ - Table:
+ - Tag: DW_TAG_compile_unit
+ Children: DW_CHILDREN_yes
+ Attributes:
+ - Attribute: DW_AT_producer
+ Form: DW_FORM_string
+ - Attribute: DW_AT_language
+ Form: DW_FORM_data2
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addrx
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data8
+ - Tag: DW_TAG_subprogram
+ Children: DW_CHILDREN_yes
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addrx
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data8
+ - Attribute: DW_AT_type
+ Form: DW_FORM_ref4
+ - Tag: DW_TAG_base_type
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Tag: DW_TAG_variable
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_type
+ Form: DW_FORM_ref4
+ - Attribute: DW_AT_location
+ Form: DW_FORM_exprloc
+ debug_info:
+ - Version: 5
+ UnitType: DW_UT_compile
+ Entries:
+ - AbbrCode: 1
+ Values:
+ - CStr: by_hand
+ - Value: 0x04
+ - CStr: GoodCU
+ - Value: 0x0
+ - Value: 0x10
+ - Value: 0x8
+ - AbbrCode: 2
+ Values:
+ - CStr: foo
+ - Value: 0x0
+ - Value: 0x10
+ - Value: 0x3e
+ - AbbrCode: 0
+ - AbbrCode: 3
+ Values:
+ - CStr: int
+ - AbbrCode: 4
+ Values:
+ - CStr: var1
+ - Value: 0x0000003e
+ - BlockData:
+ - 0xa1
+ - 0x00
+ - AbbrCode: 0
+ - Version: 5
+ UnitType: DW_UT_compile
+ Entries:
+ - AbbrCode: 1
+ Values:
+ - CStr: by_hand
+ - Value: 0x04
+ - CStr: BadCU
+ - Value: 0x0
+ - Value: 0x10
+ - AbbrCode: 2
+ Values:
+ - CStr: foo1
+ - Value: 0x0
+ - Value: 0x10
+ - Value: 0x3e
+ - AbbrCode: 0
+ - AbbrCode: 3
+ Values:
+ - CStr: int
+ - AbbrCode: 4
+ Values:
+ - CStr: var1
+ - Value: 0x0000003e
+ - BlockData:
+ - 0xa1
+ - 0x00
+ - AbbrCode: 0
+ debug_addr:
+ - Version: 5
+ AddressSize: 0x08
+ Entries:
+ - Address: 0x1130
+ - Version: 5
+ AddressSize: 0x08
+ Entries:
+ - Address: 0x10
+...
More information about the llvm-commits
mailing list