From 0fd50382b0bf62ee8c78d21555885b6ada576075 Mon Sep 17 00:00:00 2001 From: huangjinjie Date: Tue, 18 Nov 2025 18:40:12 +0800 Subject: [PATCH 1/3] add more detail when incompatible version found --- llvm/lib/DWP/DWP.cpp | 4 +++- .../llvm-dwp/X86/incompatible_dwarf_version.test | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test diff --git a/llvm/lib/DWP/DWP.cpp b/llvm/lib/DWP/DWP.cpp index b565edbfe96db..a6624339f704f 100644 --- a/llvm/lib/DWP/DWP.cpp +++ b/llvm/lib/DWP/DWP.cpp @@ -709,7 +709,9 @@ Error write(MCStreamer &Out, ArrayRef Inputs, Version = Header.Version; IndexVersion = Version < 5 ? 2 : 5; } else if (Version != Header.Version) { - return make_error("incompatible DWARF compile unit versions."); + return make_error( + Input + ": incompatible DWARF compile unit version, found " + + utostr(Header.Version) + " and expecting " + utostr(Version)); } writeStringsAndOffsets(Out, Strings, StrOffsetSection, CurStrSection, diff --git a/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test b/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test new file mode 100644 index 0000000000000..886fe834a3263 --- /dev/null +++ b/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test @@ -0,0 +1,15 @@ +RUN: rm -rf %t && split-file %s %t && cd %t +RUN: clang++ -g -gsplit-dwarf -gdwarf-5 -c %t/a.cpp -o %t/a.o +RUN: clang++ -g -gsplit-dwarf -gdwarf-4 -c %t/b.cpp -o %t/b.o +RUN: clang++ %t/a.o %t/b.o -o %t/main.exe +RUN: not llvm-dwp -e %t/main.exe -o %t/main.exe.dwp 2>&1 | FileCheck %s + +# CHECK: error: {{.*}}b.dwo: incompatible DWARF compile unit version, found 4 and expecting 5 + +;--- a.cpp +int main() { + return 0; +} + +;--- b.cpp +void b() {} From 0bd6baa004a0572be6c5e426119263024fcbd48d Mon Sep 17 00:00:00 2001 From: huangjinjie Date: Tue, 18 Nov 2025 19:56:09 +0800 Subject: [PATCH 2/3] use the existing input as the test case --- .../X86/incompatible_dwarf_version.test | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test b/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test index 886fe834a3263..2258bf1ecbc1f 100644 --- a/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test +++ b/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test @@ -1,15 +1,6 @@ -RUN: rm -rf %t && split-file %s %t && cd %t -RUN: clang++ -g -gsplit-dwarf -gdwarf-5 -c %t/a.cpp -o %t/a.o -RUN: clang++ -g -gsplit-dwarf -gdwarf-4 -c %t/b.cpp -o %t/b.o -RUN: clang++ %t/a.o %t/b.o -o %t/main.exe -RUN: not llvm-dwp -e %t/main.exe -o %t/main.exe.dwp 2>&1 | FileCheck %s +RUN: rm -rf %t && mkdir -p %t && cd %t +RUN: llvm-mc --triple=x86_64-unknown-linux --filetype=obj --split-dwarf-file=%t/main_v5.dwo -dwarf-version=5 %p/../Inputs/overflow/main_v5.s -o %t/main_v5.o +RUN: llvm-mc --triple=x86_64-unknown-linux --filetype=obj --split-dwarf-file=%t/debug_info_v4.dwo -dwarf-version=4 %p/../Inputs/overflow/debug_info_v4.s -o %t/debug_info_v4.o +RUN: not llvm-dwp %t/main_v5.dwo %t/debug_info_v4.dwo -o main.dwp 2>&1 | FileCheck %s -# CHECK: error: {{.*}}b.dwo: incompatible DWARF compile unit version, found 4 and expecting 5 - -;--- a.cpp -int main() { - return 0; -} - -;--- b.cpp -void b() {} +# CHECK: error: {{.*}}debug_info_v4.dwo: incompatible DWARF compile unit version, found 4 and expecting 5 From 4f62636745ab13d53ef3d476c847aa6b56d10921 Mon Sep 17 00:00:00 2001 From: huangjinjie Date: Wed, 19 Nov 2025 11:32:59 +0800 Subject: [PATCH 3/3] add information of the first valid input --- llvm/lib/DWP/DWP.cpp | 7 +++++-- .../tools/llvm-dwp/X86/incompatible_dwarf_version.test | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/llvm/lib/DWP/DWP.cpp b/llvm/lib/DWP/DWP.cpp index a6624339f704f..ab73651846e45 100644 --- a/llvm/lib/DWP/DWP.cpp +++ b/llvm/lib/DWP/DWP.cpp @@ -650,6 +650,7 @@ Error write(MCStreamer &Out, ArrayRef Inputs, uint32_t ContributionOffsets[8] = {}; uint16_t Version = 0; uint32_t IndexVersion = 0; + StringRef FirstInput; bool AnySectionOverflow = false; DWPStringPool Strings(Out, StrSection); @@ -708,10 +709,12 @@ Error write(MCStreamer &Out, ArrayRef Inputs, if (Version == 0) { Version = Header.Version; IndexVersion = Version < 5 ? 2 : 5; + FirstInput = Input; } else if (Version != Header.Version) { return make_error( - Input + ": incompatible DWARF compile unit version, found " + - utostr(Header.Version) + " and expecting " + utostr(Version)); + "incompatible DWARF compile unit version: " + Input + " (version " + + utostr(Header.Version) + ") and " + FirstInput.str() + " (version " + + utostr(Version) + ")"); } writeStringsAndOffsets(Out, Strings, StrOffsetSection, CurStrSection, diff --git a/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test b/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test index 2258bf1ecbc1f..9f7da58c5d463 100644 --- a/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test +++ b/llvm/test/tools/llvm-dwp/X86/incompatible_dwarf_version.test @@ -3,4 +3,4 @@ RUN: llvm-mc --triple=x86_64-unknown-linux --filetype=obj --split-dwarf-file=%t/ RUN: llvm-mc --triple=x86_64-unknown-linux --filetype=obj --split-dwarf-file=%t/debug_info_v4.dwo -dwarf-version=4 %p/../Inputs/overflow/debug_info_v4.s -o %t/debug_info_v4.o RUN: not llvm-dwp %t/main_v5.dwo %t/debug_info_v4.dwo -o main.dwp 2>&1 | FileCheck %s -# CHECK: error: {{.*}}debug_info_v4.dwo: incompatible DWARF compile unit version, found 4 and expecting 5 +CHECK: error: incompatible DWARF compile unit version: {{.*}}debug_info_v4.dwo (version 4) and {{.*}}main_v5.dwo (version 5)