Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 15 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,29 @@ 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 Directory of "
<< DWOName
<< " does not exist. Relative path will be used to process .dwo "
"files.\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
19 changes: 19 additions & 0 deletions bolt/test/dwo-name-retrieving.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Test DWO retrieval via relative path with a missing CompDir.
## Also, verify no crash for an absolute DWOName path.

## The case where DWOName is a relative path, and debug compilation directory 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-REL

# DWO-NAME-REL: BOLT-WARNING: Debug Fission: Debug Compilation Directory of main.exe-hello.dwo does not exist.
# DWO-NAME-REL-NOT: Debug Fission: DWO debug information for

## The case where DWOName is a absolute path, and a dwp file is provided.
# RUN: %clang %cflags -g -gsplit-dwarf %p/Inputs/hello.c -o %t/main.exe
# RUN: llvm-dwp -e %t/main.exe -o %t/main.exe.dwp
# RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -update-debug-sections -dwp=%t/main.exe.dwp 2>&1 | FileCheck %s -check-prefix=DWO-NAME-ABS

# DWO-NAME-ABS-NOT: BOLT-WARNING: Debug Fission: Debug Compilation Directory of {{.*}}/main.exe-hello.dwo does not exist.
# DWO-NAME-ABS-NOT: Debug Fission: DWO debug information for
# DWO-NAME-ABS-NOT: Assertion `FD >= 0 && "File not yet open!"' failed.
Loading