[llvm] 359fae6 - [DebugInfo] Explicitly permit addr_size = 0x02 when parsing DWARF data

Anton Korobeynikov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 03:12:04 PDT 2020


Author: Anatoly Trosinenko
Date: 2020-06-22T13:11:55+03:00
New Revision: 359fae6eb094e8eacc466b9ce5802563771a3cb9

URL: https://github.com/llvm/llvm-project/commit/359fae6eb094e8eacc466b9ce5802563771a3cb9
DIFF: https://github.com/llvm/llvm-project/commit/359fae6eb094e8eacc466b9ce5802563771a3cb9.diff

LOG: [DebugInfo] Explicitly permit addr_size = 0x02 when parsing DWARF data

Current LLVM implementation uses `MCAsmInfo::CodePointerSize` as addr_size when emitting the DWARF data. llvm-dwarfdump, on the other hand, handles `addr_size`s of 4 and 8 properly and considers all other sizes as an error. This works for most of mainline targets except for MSP430 and AVR.

msp430-gcc v8.3.1 emits DWARF32 with addr_size = 4 (DWARF32 does not imply addr_size = 4, 32 refers to internal offset width of 4 bytes) that is handled by llvm-dwarfdump already. Still, emitting 2-byte target pointers on MSP430 seems correct as well (but not for MSP430X that is supported by msp430-gcc but not by LLVM and has 20-bit address space).

This patch make it possible for MSP430 debug info support to be tested with llvm-dwarfdump.

Differential Revision: https://reviews.llvm.org/D82055

Added: 
    llvm/test/DebugInfo/Inputs/dwarfdump-16bit-addr.o
    llvm/test/DebugInfo/dwarfdump-16bit-addr.test

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
    llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
    llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index b36505760e46..97903a96b3fc 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -362,6 +362,10 @@ class DWARFContext : public DIContext {
     return version == 2 || version == 3 || version == 4 || version == 5;
   }
 
+  static bool isAddressSizeSupported(unsigned AddressSize) {
+    return AddressSize == 2 || AddressSize == 4 || AddressSize == 8;
+  }
+
   std::shared_ptr<DWARFContext> getDWOContext(StringRef AbsolutePath);
 
   const MCRegisterInfo *getRegisterInfo() const { return RegInfo.get(); }

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
index f90204167050..a6d44f04e468 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -300,7 +300,7 @@ bool DWARFUnitHeader::extract(DWARFContext &Context,
                 TypeOffset < getLength() + getUnitLengthFieldByteSize();
   bool LengthOK = debug_info.isValidOffset(getNextUnitOffset() - 1);
   bool VersionOK = DWARFContext::isSupportedVersion(getVersion());
-  bool AddrSizeOK = getAddressByteSize() == 4 || getAddressByteSize() == 8;
+  bool AddrSizeOK = DWARFContext::isAddressSizeSupported(getAddressByteSize());
 
   if (!LengthOK || !VersionOK || !AddrSizeOK || !TypeOffsetOK)
     return false;

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index d5b016728c71..a6dadd7f8021 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -133,7 +133,7 @@ bool DWARFVerifier::verifyUnitHeader(const DWARFDataExtractor DebugInfoData,
 
   ValidLength = DebugInfoData.isValidOffset(OffsetStart + Length + 3);
   ValidVersion = DWARFContext::isSupportedVersion(Version);
-  ValidAddrSize = AddrSize == 4 || AddrSize == 8;
+  ValidAddrSize = DWARFContext::isAddressSizeSupported(AddrSize);
   if (!ValidLength || !ValidVersion || !ValidAddrSize || !ValidAbbrevOffset ||
       !ValidType) {
     Success = false;

diff  --git a/llvm/test/DebugInfo/Inputs/dwarfdump-16bit-addr.o b/llvm/test/DebugInfo/Inputs/dwarfdump-16bit-addr.o
new file mode 100644
index 000000000000..9777911b726a
Binary files /dev/null and b/llvm/test/DebugInfo/Inputs/dwarfdump-16bit-addr.o 
diff er

diff  --git a/llvm/test/DebugInfo/dwarfdump-16bit-addr.test b/llvm/test/DebugInfo/dwarfdump-16bit-addr.test
new file mode 100644
index 000000000000..9c4dbca5215d
--- /dev/null
+++ b/llvm/test/DebugInfo/dwarfdump-16bit-addr.test
@@ -0,0 +1,34 @@
+; Test that llvm-dwarfdump can handle DWARF32 v3 with addr_size = 0x02
+; Input object file was produced from source containing just "int x;" with
+;   clang -target avr -gdwarf-3 -c dwarfdump-16bit-addr.c
+
+; REQUIRES: avr-registered-target
+; RUN: llvm-dwarfdump --debug-info %S/Inputs/dwarfdump-16bit-addr.o | FileCheck %s
+; RUN: llvm-dwarfdump --verify %S/Inputs/dwarfdump-16bit-addr.o
+
+; CHECK: Inputs/dwarfdump-16bit-addr.o:  file format elf32-avr
+
+; CHECK: .debug_info contents:
+; CHECK: 0x00000000: Compile Unit: length = 0x00000032, format = DWARF32, version = 0x0003, abbr_offset = 0x0000, addr_size = 0x02 (next unit at 0x00000036)
+
+; CHECK: 0x0000000b: DW_TAG_compile_unit
+; CHECK:               DW_AT_producer    ("clang version 10.0.0-4ubuntu1 ")
+; CHECK:               DW_AT_language    (DW_LANG_C99)
+; CHECK:               DW_AT_name        ("dwarfdump-16bit-addr.c")
+; CHECK:               DW_AT_stmt_list   (0x00000000)
+; CHECK:               DW_AT_comp_dir    ("/tmp")
+
+; CHECK: 0x0000001e:   DW_TAG_variable
+; CHECK:                 DW_AT_name      ("x")
+; CHECK:                 DW_AT_type      (0x0000002e "int")
+; CHECK:                 DW_AT_external  (0x01)
+; CHECK:                 DW_AT_decl_file ("/tmp{{[/\\]}}dwarfdump-16bit-addr.c")
+; CHECK:                 DW_AT_decl_line (1)
+; CHECK:                 DW_AT_location  (DW_OP_addr 0x0)
+
+; CHECK: 0x0000002e:   DW_TAG_base_type
+; CHECK:                 DW_AT_name      ("int")
+; CHECK:                 DW_AT_encoding  (DW_ATE_signed)
+; CHECK:                 DW_AT_byte_size (0x02)
+
+; CHECK: 0x00000035:   NULL


        


More information about the llvm-commits mailing list