Skip to content

Commit 7d27272

Browse files
authored
[BOLT][DWARF] Add option to specify DW_AT_comp_dir (#79395)
Added an --comp-dir-override option that overrides DW_AT_comp_dir in the unit die. This allows for llvm-bolt to be invoked from any category and still find .dwo files.
1 parent 7f54266 commit 7d27272

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ PrintMemData("print-mem-data",
7272
cl::ZeroOrMore,
7373
cl::cat(BoltCategory));
7474

75+
cl::opt<std::string> CompDirOverride(
76+
"comp-dir-override",
77+
cl::desc("overrides DW_AT_comp_dir, and provides an alterantive base "
78+
"location, which is used with DW_AT_dwo_name to construct a path "
79+
"to *.dwo files."),
80+
cl::Hidden, cl::init(""), cl::cat(BoltCategory));
7581
} // namespace opts
7682

7783
namespace llvm {
@@ -1574,12 +1580,18 @@ void BinaryContext::preprocessDWODebugInfo() {
15741580
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
15751581
DWARFUnit *const DwarfUnit = CU.get();
15761582
if (std::optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
1577-
DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
1583+
std::string DWOName = dwarf::toString(
1584+
DwarfUnit->getUnitDIE().find(
1585+
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
1586+
"");
1587+
SmallString<16> AbsolutePath;
1588+
if (!opts::CompDirOverride.empty()) {
1589+
sys::path::append(AbsolutePath, opts::CompDirOverride);
1590+
sys::path::append(AbsolutePath, DWOName);
1591+
}
1592+
DWARFUnit *DWOCU =
1593+
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
15781594
if (!DWOCU->isDWOUnit()) {
1579-
std::string DWOName = dwarf::toString(
1580-
DwarfUnit->getUnitDIE().find(
1581-
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
1582-
"");
15831595
outs() << "BOLT-WARNING: Debug Fission: DWO debug information for "
15841596
<< DWOName
15851597
<< " was not retrieved and won't be updated. Please check "

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ static cl::opt<bool> AlwaysConvertToRanges(
366366
cl::desc("This option is for testing purposes only. It forces BOLT to "
367367
"convert low_pc/high_pc to ranges always."),
368368
cl::ReallyHidden, cl::init(false), cl::cat(BoltCategory));
369+
370+
extern cl::opt<std::string> CompDirOverride;
369371
} // namespace opts
370372

371373
static bool getLowAndHighPC(const DIE &Die, const DWARFUnit &DU,
@@ -1991,14 +1993,20 @@ void DWARFRewriter::writeDWOFiles(
19911993
return;
19921994
}
19931995

1994-
std::string CompDir = opts::DwarfOutputPath.empty()
1995-
? CU.getCompilationDir()
1996-
: opts::DwarfOutputPath.c_str();
1997-
auto FullPath = CompDir.append("/").append(DWOName);
1996+
std::string CompDir = CU.getCompilationDir();
1997+
1998+
if (!opts::DwarfOutputPath.empty())
1999+
CompDir = opts::DwarfOutputPath.c_str();
2000+
else if (!opts::CompDirOverride.empty())
2001+
CompDir = opts::CompDirOverride;
2002+
2003+
SmallString<16> AbsolutePath;
2004+
sys::path::append(AbsolutePath, CompDir);
2005+
sys::path::append(AbsolutePath, DWOName);
19982006

19992007
std::error_code EC;
20002008
std::unique_ptr<ToolOutputFile> TempOut =
2001-
std::make_unique<ToolOutputFile>(FullPath, EC, sys::fs::OF_None);
2009+
std::make_unique<ToolOutputFile>(AbsolutePath, EC, sys::fs::OF_None);
20022010

20032011
const DWARFUnitIndex::Entry *CUDWOEntry = nullptr;
20042012
if (IsDWP)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; REQUIRES: system-linux
2+
3+
; RUN: rm -rf %t
4+
; RUN: mkdir %t
5+
; RUN: cd %t
6+
; RUN: mkdir temp
7+
; RUN: llvm-mc -dwarf-version=4 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf4-df-basic.s \
8+
; RUN: -split-dwarf-file=main.dwo -o main.o
9+
; RUN: %clang %cflags -gdwarf-4 -gsplit-dwarf=split main.o -o main.exe
10+
; RUN: cd temp
11+
; RUN: llvm-bolt ../main.exe -o ../main.exe.bolt --update-debug-sections -v 1 --comp-dir-override=%t
12+
; RUN: cd ..
13+
; RUN: ls -lat | FileCheck %s -check-prefix=BOLT-CHECK
14+
15+
;; Tests that BOLT processes .dwo files with --comp-dir-override.
16+
17+
; BOLT-CHECK: main.dwo.dwo
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; REQUIRES: system-linux
2+
3+
; RUN: rm -rf %t
4+
; RUN: mkdir %t
5+
; RUN: cd %t
6+
; RUN: mkdir temp
7+
; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-df-input-lowpc-ranges-main.s \
8+
; RUN: -split-dwarf-file=main.dwo -o main.o
9+
; RUN: %clang %cflags -gdwarf-5 -gsplit-dwarf=split main.o -o main.exe
10+
; RUN: cd temp
11+
; RUN: llvm-bolt ../main.exe -o ../main.exe.bolt --update-debug-sections -v 1 --comp-dir-override=%t
12+
; RUN: cd ..
13+
; RUN: ls -lat | FileCheck %s -check-prefix=BOLT-CHECK
14+
15+
;; Tests that BOLT processes .dwo files with --comp-dir-override.
16+
17+
; BOLT-CHECK: main.dwo.dwo

0 commit comments

Comments
 (0)