mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 19:07:53 +08:00
[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.
This commit is contained in:
committed by
GitHub
parent
7f542662ce
commit
7d272722fb
@@ -72,6 +72,12 @@ PrintMemData("print-mem-data",
|
||||
cl::ZeroOrMore,
|
||||
cl::cat(BoltCategory));
|
||||
|
||||
cl::opt<std::string> CompDirOverride(
|
||||
"comp-dir-override",
|
||||
cl::desc("overrides DW_AT_comp_dir, and provides an alterantive base "
|
||||
"location, which is used with DW_AT_dwo_name to construct a path "
|
||||
"to *.dwo files."),
|
||||
cl::Hidden, cl::init(""), cl::cat(BoltCategory));
|
||||
} // namespace opts
|
||||
|
||||
namespace llvm {
|
||||
@@ -1574,12 +1580,18 @@ void BinaryContext::preprocessDWODebugInfo() {
|
||||
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
|
||||
DWARFUnit *const DwarfUnit = CU.get();
|
||||
if (std::optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
|
||||
DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
|
||||
std::string DWOName = dwarf::toString(
|
||||
DwarfUnit->getUnitDIE().find(
|
||||
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
|
||||
"");
|
||||
SmallString<16> AbsolutePath;
|
||||
if (!opts::CompDirOverride.empty()) {
|
||||
sys::path::append(AbsolutePath, opts::CompDirOverride);
|
||||
sys::path::append(AbsolutePath, DWOName);
|
||||
}
|
||||
DWARFUnit *DWOCU =
|
||||
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
|
||||
if (!DWOCU->isDWOUnit()) {
|
||||
std::string DWOName = dwarf::toString(
|
||||
DwarfUnit->getUnitDIE().find(
|
||||
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
|
||||
"");
|
||||
outs() << "BOLT-WARNING: Debug Fission: DWO debug information for "
|
||||
<< DWOName
|
||||
<< " was not retrieved and won't be updated. Please check "
|
||||
|
||||
@@ -366,6 +366,8 @@ static cl::opt<bool> AlwaysConvertToRanges(
|
||||
cl::desc("This option is for testing purposes only. It forces BOLT to "
|
||||
"convert low_pc/high_pc to ranges always."),
|
||||
cl::ReallyHidden, cl::init(false), cl::cat(BoltCategory));
|
||||
|
||||
extern cl::opt<std::string> CompDirOverride;
|
||||
} // namespace opts
|
||||
|
||||
static bool getLowAndHighPC(const DIE &Die, const DWARFUnit &DU,
|
||||
@@ -1991,14 +1993,20 @@ void DWARFRewriter::writeDWOFiles(
|
||||
return;
|
||||
}
|
||||
|
||||
std::string CompDir = opts::DwarfOutputPath.empty()
|
||||
? CU.getCompilationDir()
|
||||
: opts::DwarfOutputPath.c_str();
|
||||
auto FullPath = CompDir.append("/").append(DWOName);
|
||||
std::string CompDir = CU.getCompilationDir();
|
||||
|
||||
if (!opts::DwarfOutputPath.empty())
|
||||
CompDir = opts::DwarfOutputPath.c_str();
|
||||
else if (!opts::CompDirOverride.empty())
|
||||
CompDir = opts::CompDirOverride;
|
||||
|
||||
SmallString<16> AbsolutePath;
|
||||
sys::path::append(AbsolutePath, CompDir);
|
||||
sys::path::append(AbsolutePath, DWOName);
|
||||
|
||||
std::error_code EC;
|
||||
std::unique_ptr<ToolOutputFile> TempOut =
|
||||
std::make_unique<ToolOutputFile>(FullPath, EC, sys::fs::OF_None);
|
||||
std::make_unique<ToolOutputFile>(AbsolutePath, EC, sys::fs::OF_None);
|
||||
|
||||
const DWARFUnitIndex::Entry *CUDWOEntry = nullptr;
|
||||
if (IsDWP)
|
||||
|
||||
17
bolt/test/X86/dwarf4-override-comp-dir.test
Normal file
17
bolt/test/X86/dwarf4-override-comp-dir.test
Normal file
@@ -0,0 +1,17 @@
|
||||
; REQUIRES: system-linux
|
||||
|
||||
; RUN: rm -rf %t
|
||||
; RUN: mkdir %t
|
||||
; RUN: cd %t
|
||||
; RUN: mkdir temp
|
||||
; RUN: llvm-mc -dwarf-version=4 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf4-df-basic.s \
|
||||
; RUN: -split-dwarf-file=main.dwo -o main.o
|
||||
; RUN: %clang %cflags -gdwarf-4 -gsplit-dwarf=split main.o -o main.exe
|
||||
; RUN: cd temp
|
||||
; RUN: llvm-bolt ../main.exe -o ../main.exe.bolt --update-debug-sections -v 1 --comp-dir-override=%t
|
||||
; RUN: cd ..
|
||||
; RUN: ls -lat | FileCheck %s -check-prefix=BOLT-CHECK
|
||||
|
||||
;; Tests that BOLT processes .dwo files with --comp-dir-override.
|
||||
|
||||
; BOLT-CHECK: main.dwo.dwo
|
||||
17
bolt/test/X86/dwarf5-override-comp-dir.test
Normal file
17
bolt/test/X86/dwarf5-override-comp-dir.test
Normal file
@@ -0,0 +1,17 @@
|
||||
; REQUIRES: system-linux
|
||||
|
||||
; RUN: rm -rf %t
|
||||
; RUN: mkdir %t
|
||||
; RUN: cd %t
|
||||
; RUN: mkdir temp
|
||||
; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-df-input-lowpc-ranges-main.s \
|
||||
; RUN: -split-dwarf-file=main.dwo -o main.o
|
||||
; RUN: %clang %cflags -gdwarf-5 -gsplit-dwarf=split main.o -o main.exe
|
||||
; RUN: cd temp
|
||||
; RUN: llvm-bolt ../main.exe -o ../main.exe.bolt --update-debug-sections -v 1 --comp-dir-override=%t
|
||||
; RUN: cd ..
|
||||
; RUN: ls -lat | FileCheck %s -check-prefix=BOLT-CHECK
|
||||
|
||||
;; Tests that BOLT processes .dwo files with --comp-dir-override.
|
||||
|
||||
; BOLT-CHECK: main.dwo.dwo
|
||||
Reference in New Issue
Block a user