[llvm] 6770349 - [DWARFYAML][debug_info] Fix array index out of bounds error
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 20 00:04:23 PDT 2020
Author: Xing GUO
Date: 2020-06-20T15:08:24+08:00
New Revision: 677034959285b9250c7b562d2602594719581463
URL: https://github.com/llvm/llvm-project/commit/677034959285b9250c7b562d2602594719581463
DIFF: https://github.com/llvm/llvm-project/commit/677034959285b9250c7b562d2602594719581463.diff
LOG: [DWARFYAML][debug_info] Fix array index out of bounds error
This patch is trying to fix the array index out of bounds error. I observed it in (https://reviews.llvm.org/harbormaster/unit/view/99638/).
Reviewed By: jhenderson, MaskRay
Differential Revision: https://reviews.llvm.org/D82139
Added:
Modified:
llvm/lib/ObjectYAML/DWARFVisitor.cpp
llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
Removed:
################################################################################
diff --git a/llvm/lib/ObjectYAML/DWARFVisitor.cpp b/llvm/lib/ObjectYAML/DWARFVisitor.cpp
index ecb5967ac532..fa443cf9e00d 100644
--- a/llvm/lib/ObjectYAML/DWARFVisitor.cpp
+++ b/llvm/lib/ObjectYAML/DWARFVisitor.cpp
@@ -46,6 +46,8 @@ static unsigned getRefSize(const DWARFYAML::Unit &Unit) {
template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
for (auto &Unit : DebugInfo.CompileUnits) {
onStartCompileUnit(Unit);
+ if (Unit.Entries.empty())
+ continue;
auto FirstAbbrevCode = Unit.Entries[0].AbbrCode;
for (auto &Entry : Unit.Entries) {
diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
index 08a8906239e0..4811992e91e5 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
@@ -548,3 +548,30 @@ DWARF:
Entries:
- AbbrCode: 0
Values: []
+
+## h) Test that yaml2obj doesn't crash when the 'Entries' of a compilation unit is empty.
+
+# RUN: yaml2obj --docnum=8 %s -o %t8.o
+# RUN: llvm-readelf --hex-dump=.debug_info %t8.o | \
+# RUN: FileCheck %s --check-prefix=EMPTY-ENTRIES --match-full-lines
+
+# EMPTY-ENTRIES: Hex dump of section '.debug_info':
+# EMPTY-ENTRIES-NEXT: 0x00000000 34120000 05000204 34120000 4.......4...
+# EMPTY-ENTRIES-EMPTY:
+## ^- 'Entries' is empty
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+DWARF:
+ debug_info:
+ - Length:
+ TotalLength: 0x1234
+ Version: 5
+ UnitType: DW_UT_type
+ AbbrOffset: 0x1234
+ AddrSize: 4
+ Entries: []
More information about the llvm-commits
mailing list