[llvm] a0fb387 - [DebugInfo] Give warning instead of error for premature terminator in .debug_aranges section.

Hongtao Yu via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 15:22:08 PDT 2022


Author: Junfeng Dong
Date: 2022-05-04T15:21:58-07:00
New Revision: a0fb387941cd26c9fbaa695dd7ddbfdc9a48eb46

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

LOG: [DebugInfo] Give warning instead of error for premature terminator in .debug_aranges section.

llvm-profgen gives error message when the input binary contains premature terminator in .debug_aranges section. These zero length items point to some rodata with zero size type in embed Rust Library. Considering Zero-Sized Types are a valid feature in Rust. They are not real error. This change makes the "error:" message into a warning to avoid misleading.

Why do we still want a warning on such case? because it doesn't follow dwarf standard.  https://bugs.llvm.org/show_bug.cgi?id=46805 contains early discussion.

Reviewed By: jhenderson

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

Added: 
    llvm/test/tools/llvm-symbolizer/debug-aranges-premature-end.yaml

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h
    llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h
index a3783c61c2396..068674cfae5c5 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAranges.h
@@ -28,7 +28,8 @@ class DWARFDebugAranges {
 private:
   void clear();
   void extract(DWARFDataExtractor DebugArangesData,
-               function_ref<void(Error)> RecoverableErrorHandler);
+               function_ref<void(Error)> RecoverableErrorHandler,
+               function_ref<void(Error)> WarningHandler);
 
   /// Call appendRange multiple times and then call construct.
   void appendRange(uint64_t CUOffset, uint64_t LowPC, uint64_t HighPC);

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
index 1fde9991895a1..49ee27db6d542 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
@@ -22,15 +22,15 @@ using namespace llvm;
 
 void DWARFDebugAranges::extract(
     DWARFDataExtractor DebugArangesData,
-    function_ref<void(Error)> RecoverableErrorHandler) {
+    function_ref<void(Error)> RecoverableErrorHandler,
+    function_ref<void(Error)> WarningHandler) {
   if (!DebugArangesData.isValidOffset(0))
     return;
   uint64_t Offset = 0;
   DWARFDebugArangeSet Set;
 
   while (DebugArangesData.isValidOffset(Offset)) {
-    if (Error E =
-            Set.extract(DebugArangesData, &Offset, RecoverableErrorHandler)) {
+    if (Error E = Set.extract(DebugArangesData, &Offset, WarningHandler)) {
       RecoverableErrorHandler(std::move(E));
       return;
     }
@@ -52,7 +52,8 @@ void DWARFDebugAranges::generate(DWARFContext *CTX) {
   // Extract aranges from .debug_aranges section.
   DWARFDataExtractor ArangesData(CTX->getDWARFObj().getArangesSection(),
                                  CTX->isLittleEndian(), 0);
-  extract(ArangesData, CTX->getRecoverableErrorHandler());
+  extract(ArangesData, CTX->getRecoverableErrorHandler(),
+          CTX->getWarningHandler());
 
   // Generate aranges from DIEs: even if .debug_aranges section is present,
   // it may describe only a small subset of compilation units, so we need to

diff  --git a/llvm/test/tools/llvm-symbolizer/debug-aranges-premature-end.yaml b/llvm/test/tools/llvm-symbolizer/debug-aranges-premature-end.yaml
new file mode 100644
index 0000000000000..c18afa41a5255
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/debug-aranges-premature-end.yaml
@@ -0,0 +1,19 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-symbolizer 0xa --obj=%t 2>&1 | FileCheck %s
+
+# CHECK: warning: address range table at offset 0x0 has a premature terminator entry at offset 0x10
+
+--- !ELF
+FileHeader:
+  Class: ELFCLASS64
+  Data:  ELFDATA2LSB
+  Type:  ET_EXEC
+DWARF:
+  debug_aranges:
+    - Version:  2
+      CuOffset: 0
+      Descriptors:
+        - Address: 0
+          Length:  0
+        - Address: 0x5678
+          Length:  0x20


        


More information about the llvm-commits mailing list