From 07558093b87ddfa6feb917bad0bc87675a237b3d Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sat, 1 Jun 2019 09:18:26 +0000 Subject: [PATCH] Extend the DWARFExpression address handling to support 16-bit addresses 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 --- .../llvm/DebugInfo/DWARF/DWARFExpression.h | 2 +- lib/DebugInfo/DWARF/DWARFExpression.cpp | 12 ++++++++---- test/MC/AVR/dwarf-asm-no-code.s | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test/MC/AVR/dwarf-asm-no-code.s diff --git a/include/llvm/DebugInfo/DWARF/DWARFExpression.h b/include/llvm/DebugInfo/DWARF/DWARFExpression.h index 21b138676bd..f066dd58d60 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFExpression.h +++ b/include/llvm/DebugInfo/DWARF/DWARFExpression.h @@ -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); } diff --git a/lib/DebugInfo/DWARF/DWARFExpression.cpp b/lib/DebugInfo/DWARF/DWARFExpression.cpp index 133b85a0969..644075011a3 100644 --- a/lib/DebugInfo/DWARF/DWARFExpression.cpp +++ b/lib/DebugInfo/DWARF/DWARFExpression.cpp @@ -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 index 00000000000..cbe0bf49ad1 --- /dev/null +++ b/test/MC/AVR/dwarf-asm-no-code.s @@ -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]: -- 2.40.0