Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Regex.h"
#include <algorithm>
#include <functional>
Expand Down Expand Up @@ -1632,19 +1633,27 @@ void BinaryContext::preprocessDWODebugInfo() {
DwarfUnit->getUnitDIE().find(
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
"");
SmallString<16> AbsolutePath;
SmallString<16> AbsolutePath(DWOName);
std::string DWOCompDir = DwarfUnit->getCompilationDir();
if (!opts::CompDirOverride.empty()) {
sys::path::append(AbsolutePath, opts::CompDirOverride);
sys::path::append(AbsolutePath, DWOName);
DWOCompDir = opts::CompDirOverride;
} else if (!sys::fs::exists(DWOCompDir) && sys::fs::exists(DWOName)) {
DWOCompDir = ".";
this->outs()
<< "BOLT-WARNING: Debug Fission: Debug Compilation Dir wrong for "
<< DWOName << ". Relative path will be used for retrieving.\n";
}
// Prevent failures when DWOName is already an absolute path.
sys::fs::make_absolute(DWOCompDir, AbsolutePath);
DWARFUnit *DWOCU =
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
this->outs()
<< "BOLT-WARNING: Debug Fission: DWO debug information for "
<< DWOName
<< " was not retrieved and won't be updated. Please check "
"relative path.\n";
"relative path or use '--comp-dir-override' to specify the base "
"location.\n";
continue;
}
DWOCUs[*DWOId] = DWOCU;
Expand Down
9 changes: 5 additions & 4 deletions bolt/lib/Rewrite/DWARFRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1846,15 +1846,16 @@ void DWARFRewriter::writeDWOFiles(
}

std::string CompDir = CU.getCompilationDir();
SmallString<16> AbsolutePath(DWOName);

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);
else if (!sys::fs::exists(CompDir))
CompDir = ".";
// Prevent failures when DWOName is already an absolute path.
sys::fs::make_absolute(CompDir, AbsolutePath);

std::error_code EC;
std::unique_ptr<ToolOutputFile> TempOut =
Expand Down
13 changes: 13 additions & 0 deletions bolt/test/dwo-name-retrieving.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## This test checks retrieving dwo file diercetly with dwo name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify on why we are building main.exe twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

## if the Debug Compilation Dir does not exist.

# RUN: rm -rf %t && mkdir -p %t && cd %t
# RUN: %clang %cflags -g -gsplit-dwarf -fdebug-compilation-dir=/path/does/not/exist %p/Inputs/hello.c -o main.exe
# RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -update-debug-sections 2>&1 | FileCheck %s -check-prefix=DWO-NAME
# RUN: %clang %cflags -g -gsplit-dwarf -fdebug-compilation-dir=/path/does/not/exist %p/Inputs/hello.c -o %t/main.exe
# RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -update-debug-sections 2>&1 | FileCheck %s -check-prefix=DWO-NAME

# DWO-NAME: BOLT-WARNING: Debug Fission: Debug Compilation Dir wrong for
# DWO-NAMET-NOT: Debug Fission: DWO debug information for
# DWO-NAMET-NOT: Assertion `FD >= 0 && "File not yet open!"' failed.

Loading