]> granicus.if.org Git - llvm/commitdiff
Extend the DWARFExpression address handling to support 16-bit addresses
authorDylan McKay <me@dylanmckay.io>
Sat, 1 Jun 2019 09:18:26 +0000 (09:18 +0000)
committerDylan McKay <me@dylanmckay.io>
Sat, 1 Jun 2019 09:18:26 +0000 (09:18 +0000)
This allows the DWARFExpression class to handle addresses without
crashing on targets with 16-bit pointers like AVR.

This is required in order to generate assembly from clang via the '-S'
flag.

This fixes an error with the following message:

clang: llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h:132: llvm::DWARFExpression::DWARFExpression(llvm::DataExtractor, uint16_t, uint8_t):
       Assertion `AddressSize == 8 || AddressSize == 4' failed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362290 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DWARF/DWARFExpression.h
lib/DebugInfo/DWARF/DWARFExpression.cpp
test/MC/AVR/dwarf-asm-no-code.s [new file with mode: 0644]

index 21b138676bd3d2a6bc266f2d3157db0998691494..f066dd58d606910dbef2f086c0553d36dbdbf074 100644 (file)
@@ -129,7 +129,7 @@ public:
 
   DWARFExpression(DataExtractor Data, uint16_t Version, uint8_t AddressSize)
       : Data(Data), Version(Version), AddressSize(AddressSize) {
-    assert(AddressSize == 8 || AddressSize == 4);
+    assert(AddressSize == 8 || AddressSize == 4 || AddressSize == 2);
   }
 
   iterator begin() const { return iterator(this, 0); }
index 133b85a096985dfde35c053e771a76c311d689ca..644075011a3d23be609e2385b2b3290b379a1a0e 100644 (file)
@@ -155,17 +155,21 @@ bool DWARFExpression::Operation::extract(DataExtractor Data, uint16_t Version,
     case Operation::SizeAddr:
       if (AddressSize == 8) {
         Operands[Operand] = Data.getU64(&Offset);
-      } else {
-        assert(AddressSize == 4);
+      } else if (AddressSize == 4) {
         Operands[Operand] = Data.getU32(&Offset);
+      } else {
+        assert(AddressSize == 2);
+        Operands[Operand] = Data.getU16(&Offset);
       }
       break;
     case Operation::SizeRefAddr:
       if (getRefAddrSize(AddressSize, Version) == 8) {
         Operands[Operand] = Data.getU64(&Offset);
-      } else {
-        assert(getRefAddrSize(AddressSize, Version) == 4);
+      } else if (getRefAddrSize(AddressSize, Version) == 4) {
         Operands[Operand] = Data.getU32(&Offset);
+      } else {
+        assert(getRefAddrSize(AddressSize, Version) == 2);
+        Operands[Operand] = Data.getU16(&Offset);
       }
       break;
     case Operation::SizeLEB:
diff --git a/test/MC/AVR/dwarf-asm-no-code.s b/test/MC/AVR/dwarf-asm-no-code.s
new file mode 100644 (file)
index 0000000..cbe0bf4
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: llvm-mc < %s -triple=avr -filetype=obj -o %t -g -fdebug-compilation-dir=/tmp
+// RUN: llvm-dwarfdump -v %t | FileCheck -check-prefix DWARF %s
+// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC %s
+
+// If there is no code in an assembly file, no debug info is produced
+
+.section .data, "aw"
+a:
+.long 42
+
+// DWARF: ELF32-avr
+// DWARF-NOT: contents:
+// DWARF: .debug_line contents:
+
+// RELOC-NOT: RELOCATION RECORDS FOR [.rel.debug_info]:
+
+// RELOC-NOT: RELOCATION RECORDS FOR [.rel.debug_ranges]:
+
+// RELOC-NOT: RELOCATION RECORDS FOR [.rel.debug_aranges]: