Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-gsymutil] Don't warn about duplicate debug info for merged functions #122973

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alx32
Copy link
Contributor

@alx32 alx32 commented Jan 14, 2025

When the input has merged functions, it's expected for the same address range to contain duplicate (and different) debug information. Don't warn about this when merged functions are expected in the input.

@alx32 alx32 marked this pull request as ready for review January 14, 2025 21:33
@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2025

@llvm/pr-subscribers-debuginfo

Author: None (alx32)

Changes

When the input has merged functions, it's expected for the same address range to contain duplicate (and different) debug information. Don't warn about this when merged functions are expected in the input.


Full diff: https://github.com/llvm/llvm-project/pull/122973.diff

4 Files Affected:

  • (modified) llvm/include/llvm/DebugInfo/GSYM/GsymCreator.h (+8-2)
  • (modified) llvm/lib/DebugInfo/GSYM/GsymCreator.cpp (+13-8)
  • (modified) llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-merged-funcs-dwarf.yaml (+4-2)
  • (modified) llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp (+1-1)
diff --git a/llvm/include/llvm/DebugInfo/GSYM/GsymCreator.h b/llvm/include/llvm/DebugInfo/GSYM/GsymCreator.h
index 0d098da96dd278..4433111327d67a 100644
--- a/llvm/include/llvm/DebugInfo/GSYM/GsymCreator.h
+++ b/llvm/include/llvm/DebugInfo/GSYM/GsymCreator.h
@@ -147,7 +147,8 @@ class GsymCreator {
   bool IsSegment = false;
   bool Finalized = false;
   bool Quiet;
-
+  // Specifies weather the input might contain merged functions
+  bool InputHasMergedFunctions;
 
   /// Get the first function start address.
   ///
@@ -292,7 +293,12 @@ class GsymCreator {
   }
 
 public:
-  GsymCreator(bool Quiet = false);
+  /// Construct a GsymCreator object.
+  ///
+  /// \param Quiet Whether to suppress warning messages
+  /// \param InputHasMergedFunctions Weather the input might contain merged
+  /// functions - functions with identical address ranges.
+  GsymCreator(bool Quiet = false, bool InputHasMergedFunctions = false);
 
   /// Save a GSYM file to a stand alone file.
   ///
diff --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
index 14078f5aaf9a46..8c8892cace8538 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -21,8 +21,9 @@
 using namespace llvm;
 using namespace gsym;
 
-GsymCreator::GsymCreator(bool Quiet)
-    : StrTab(StringTableBuilder::ELF), Quiet(Quiet) {
+GsymCreator::GsymCreator(bool Quiet, bool InputHasMergedFunctions)
+    : StrTab(StringTableBuilder::ELF), Quiet(Quiet),
+      InputHasMergedFunctions(InputHasMergedFunctions) {
   insertFile(StringRef());
 }
 
@@ -314,12 +315,16 @@ llvm::Error GsymCreator::finalize(OutputAggregator &Out) {
               std::swap(Prev, Curr);
             }
           } else {
-            Out.Report("Overlapping function ranges", [&](raw_ostream &OS) {
-              // print warnings about overlaps
-              OS << "warning: function ranges overlap:\n"
-                << Prev << "\n"
-                << Curr << "\n";
-            });
+            // Equal ranges are invalid only in the case where merged functions
+            // are not expected.
+            if (!InputHasMergedFunctions) {
+              Out.Report("Overlapping function ranges", [&](raw_ostream &OS) {
+                // print warnings about overlaps
+                OS << "warning: function ranges overlap:\n"
+                   << Prev << "\n"
+                   << Curr << "\n";
+              });
+            }
             FinalizedFuncs.emplace_back(std::move(Curr));
           }
         } else {
diff --git a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-merged-funcs-dwarf.yaml b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-merged-funcs-dwarf.yaml
index 6bf359cbe1ee15..1fe0127bee3412 100644
--- a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-merged-funcs-dwarf.yaml
+++ b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-merged-funcs-dwarf.yaml
@@ -1,16 +1,18 @@
 # RUN: yaml2obj %s -o %t.dSYM
 
 ## Verify that we don't keep merged functions by default
-# RUN: llvm-gsymutil --num-threads=1 --convert %t.dSYM --out-file=%t.default.gSYM
+# RUN: llvm-gsymutil --num-threads=1 --convert %t.dSYM --out-file=%t.default.gSYM | FileCheck --check-prefix=CHECK-GSYM-CREATE-NOMERGE %s
 # RUN: llvm-gsymutil --verify --verbose %t.default.gSYM | FileCheck --check-prefix=CHECK-GSYM-DEFAULT %s
 
 ## Verify that we keep merged functions when specyfing --merged-functions
-# RUN: llvm-gsymutil --num-threads=1 --convert %t.dSYM --out-file=%t.keep.gSYM --merged-functions
+# RUN: llvm-gsymutil --num-threads=1 --convert %t.dSYM --out-file=%t.keep.gSYM --merged-functions | FileCheck --check-prefix=CHECK-GSYM-CREATE-MERGE %s
 # RUN: llvm-gsymutil --verify --verbose %t.keep.gSYM | FileCheck --check-prefix=CHECK-GSYM-KEEP %s
 
 ## Note: For identical functions, the dSYM / gSYM cannot be counted on to be deterministic.
 ## So we can only match the general structure, not exact function names / offsets
 
+# CHECK-GSYM-CREATE-NOMERGE: warning: same address range contains different debug info.
+# CHECK-GSYM-CREATE-MERGE-NOT: warning: same address range contains different debug info.
 
 # CHECK-GSYM-DEFAULT-NOT: Merged FunctionInfos
 # CHECK-GSYM-DEFAULT:      FunctionInfo @ 0x{{[0-9a-fA-F]+}}: [0x{{[0-9a-fA-F]+}} - 0x{{[0-9a-fA-F]+}}) "my_func_03"
diff --git a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
index 654da68bb69600..6cafe68aaca18e 100644
--- a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
+++ b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
@@ -330,7 +330,7 @@ static llvm::Error handleObjectFile(ObjectFile &Obj, const std::string &OutFile,
   auto ThreadCount =
       NumThreads > 0 ? NumThreads : std::thread::hardware_concurrency();
 
-  GsymCreator Gsym(Quiet);
+  GsymCreator Gsym(Quiet, UseMergedFunctions);
 
   // See if we can figure out the base address for a given object file, and if
   // we can, then set the base address to use to this value. This will ease

@alx32 alx32 requested a review from kyulee-com January 18, 2025 00:13
@alx32 alx32 force-pushed the 15_no_dup_dbg_warn branch from 2db4c32 to 456ca4a Compare January 21, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants