[llvm] [BOLT] Fix failing tests by refactoring access to FileNameEntry to make it DWARF version agnostic (PR #151401)
Grigory Pastukhov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 19 20:00:37 PDT 2025
https://github.com/grigorypas updated https://github.com/llvm/llvm-project/pull/151401
>From 68d2ebc3cb59a5b4c9336552031097e973ebaa9f Mon Sep 17 00:00:00 2001
From: Grigory Pastukhov <gpastukhov at meta.com>
Date: Wed, 30 Jul 2025 14:44:29 -0700
Subject: [PATCH 1/3] Use getFileNameEntry for retrieving FileNameEntry DWARF
version agnositc way
---
bolt/lib/Core/BinaryContext.cpp | 18 +++++++-----------
bolt/test/perf2bolt/Inputs/perf_test.lds | 11 +++++------
2 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index da59a188c6b60..dd0d041692484 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -1568,23 +1568,19 @@ unsigned BinaryContext::addDebugFilenameToUnit(const uint32_t DestCUID,
DWARFCompileUnit *SrcUnit = DwCtx->getCompileUnitForOffset(SrcCUID);
const DWARFDebugLine::LineTable *LineTable =
DwCtx->getLineTableForUnit(SrcUnit);
- const std::vector<DWARFDebugLine::FileNameEntry> &FileNames =
- LineTable->Prologue.FileNames;
- // Dir indexes start at 1, as DWARF file numbers, and a dir index 0
+ const DWARFDebugLine::FileNameEntry &FileNameEntry =
+ LineTable->Prologue.getFileNameEntry(FileIndex);
+ // Dir indexes start at 1 and a dir index 0
// means empty dir.
- assert(FileIndex > 0 && FileIndex <= FileNames.size() &&
- "FileIndex out of range for the compilation unit.");
StringRef Dir = "";
- if (FileNames[FileIndex - 1].DirIdx != 0) {
+ if (FileNameEntry.DirIdx != 0) {
if (std::optional<const char *> DirName = dwarf::toString(
- LineTable->Prologue
- .IncludeDirectories[FileNames[FileIndex - 1].DirIdx - 1])) {
+ LineTable->Prologue.IncludeDirectories[FileNameEntry.DirIdx - 1])) {
Dir = *DirName;
}
}
StringRef FileName = "";
- if (std::optional<const char *> FName =
- dwarf::toString(FileNames[FileIndex - 1].Name))
+ if (std::optional<const char *> FName = dwarf::toString(FileNameEntry.Name))
FileName = *FName;
assert(FileName != "");
DWARFCompileUnit *DstUnit = DwCtx->getCompileUnitForOffset(DestCUID);
@@ -1925,7 +1921,7 @@ static void printDebugInfo(raw_ostream &OS, const MCInst &Instruction,
const DWARFDebugLine::Row &Row = LineTable->Rows[RowRef.RowIndex - 1];
StringRef FileName = "";
if (std::optional<const char *> FName =
- dwarf::toString(LineTable->Prologue.FileNames[Row.File - 1].Name))
+ dwarf::toString(LineTable->Prologue.getFileNameEntry(Row.File).Name))
FileName = *FName;
OS << " # debug line " << FileName << ":" << Row.Line;
if (Row.Column)
diff --git a/bolt/test/perf2bolt/Inputs/perf_test.lds b/bolt/test/perf2bolt/Inputs/perf_test.lds
index 66d925a05bebc..c2704d73a638c 100644
--- a/bolt/test/perf2bolt/Inputs/perf_test.lds
+++ b/bolt/test/perf2bolt/Inputs/perf_test.lds
@@ -1,13 +1,12 @@
SECTIONS {
- . = SIZEOF_HEADERS;
+ . = 0x400000 + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
- . = 0x212e8;
.dynsym : { *(.dynsym) }
- . = 0x31860;
+ . = 0x801000;
.text : { *(.text*) }
- . = 0x41c20;
+ . = 0x803000;
.fini_array : { *(.fini_array) }
- . = 0x54e18;
+ . = 0x805000;
.data : { *(.data) }
-}
\ No newline at end of file
+}
>From aa4926bec8f74df90a9044e9dd4ff88ac1d79442 Mon Sep 17 00:00:00 2001
From: Grigory Pastukhov <gpastukhov at meta.com>
Date: Mon, 18 Aug 2025 16:35:14 -0700
Subject: [PATCH 2/3] Drop changes to perf_test.lds
---
bolt/test/perf2bolt/Inputs/perf_test.lds | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/bolt/test/perf2bolt/Inputs/perf_test.lds b/bolt/test/perf2bolt/Inputs/perf_test.lds
index c2704d73a638c..66d925a05bebc 100644
--- a/bolt/test/perf2bolt/Inputs/perf_test.lds
+++ b/bolt/test/perf2bolt/Inputs/perf_test.lds
@@ -1,12 +1,13 @@
SECTIONS {
- . = 0x400000 + SIZEOF_HEADERS;
+ . = SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
+ . = 0x212e8;
.dynsym : { *(.dynsym) }
- . = 0x801000;
+ . = 0x31860;
.text : { *(.text*) }
- . = 0x803000;
+ . = 0x41c20;
.fini_array : { *(.fini_array) }
- . = 0x805000;
+ . = 0x54e18;
.data : { *(.data) }
-}
+}
\ No newline at end of file
>From 680f03ff37ab7e6eef4ed9029cac4f172f12710e Mon Sep 17 00:00:00 2001
From: Grigory Pastukhov <gpastukhov at meta.com>
Date: Tue, 19 Aug 2025 20:00:04 -0700
Subject: [PATCH 3/3] Add tests that trigger DWARF4 vs DWARF5 bug explicitly
---
bolt/test/X86/Inputs/dwarf5-two-cus-foo.cpp | 5 +++++
bolt/test/X86/dwarf5-debug-line-print.test | 14 ++++++++++++++
bolt/test/X86/dwarf5-two-cus.test | 20 ++++++++++++++++++++
3 files changed, 39 insertions(+)
create mode 100644 bolt/test/X86/Inputs/dwarf5-two-cus-foo.cpp
create mode 100644 bolt/test/X86/dwarf5-debug-line-print.test
create mode 100644 bolt/test/X86/dwarf5-two-cus.test
diff --git a/bolt/test/X86/Inputs/dwarf5-two-cus-foo.cpp b/bolt/test/X86/Inputs/dwarf5-two-cus-foo.cpp
new file mode 100644
index 0000000000000..82ad1783267b2
--- /dev/null
+++ b/bolt/test/X86/Inputs/dwarf5-two-cus-foo.cpp
@@ -0,0 +1,5 @@
+#include <cstdio>
+
+extern "C" void foo() {
+ printf("Hello from second CU!\n");
+}
diff --git a/bolt/test/X86/dwarf5-debug-line-print.test b/bolt/test/X86/dwarf5-debug-line-print.test
new file mode 100644
index 0000000000000..917249c95e0bd
--- /dev/null
+++ b/bolt/test/X86/dwarf5-debug-line-print.test
@@ -0,0 +1,14 @@
+// Check that BOLT correctly generates debug line comments for DWARF-5.
+
+// REQUIRES: system-linux
+
+// RUN: %clang -g -gdwarf-5 -O0 -xc++ %s -o %t.exe
+// RUN: llvm-bolt %t.exe --update-debug-sections --print-debug-info \
+// RUN: --print-after-lowering -o %t.bolt | FileCheck %s
+
+// CHECK: pushq %rbp # debug line {{.*}}dwarf5-debug-line-print.test:11
+
+int main(){
+ int x = 0;
+ return 0;
+}
diff --git a/bolt/test/X86/dwarf5-two-cus.test b/bolt/test/X86/dwarf5-two-cus.test
new file mode 100644
index 0000000000000..69a8731e8c246
--- /dev/null
+++ b/bolt/test/X86/dwarf5-two-cus.test
@@ -0,0 +1,20 @@
+// Check that BOLT correctly handles two CUs with DWARF-5 debug info (does not crash).
+
+// REQUIRES: system-linux
+
+// RUN: %clang -g -gdwarf-5 -O1 -xc++ %s -o %t-main.o -c
+// RUN: %clang -g -gdwarf-5 -O1 -xc++ %S/Inputs/dwarf5-two-cus-foo.cpp -o %t-foo.o -c
+// RUN: %clang %t-main.o %t-foo.o -o %t.exe
+// RUN: llvm-bolt %t.exe --update-debug-sections --force-inline=foo \
+// RUN: -o %t.bolt | FileCheck %s
+
+// CHECK-NOT: BOLT-ERROR
+// CHECK-NOT: BOLT-WARNING
+// CHECK: BOLT-INFO: inlined {{[1-9][0-9]*}} calls at {{[1-9][0-9]*}} call sites
+
+extern "C" void foo();
+
+int main() {
+ foo();
+ return 0;
+}
More information about the llvm-commits
mailing list