Skip to content

Commit 6324588

Browse files
committed
use make_absolute to prevent failures when DWOName is already an absolute path
1 parent 2d35fcb commit 6324588

File tree

4 files changed

+21
-43
lines changed

4 files changed

+21
-43
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,25 +1633,27 @@ void BinaryContext::preprocessDWODebugInfo() {
16331633
DwarfUnit->getUnitDIE().find(
16341634
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
16351635
"");
1636-
SmallString<16> AbsolutePath;
1636+
SmallString<16> AbsolutePath(DWOName);
1637+
std::string DWOCompDir = DwarfUnit->getCompilationDir();
16371638
if (!opts::CompDirOverride.empty()) {
1638-
sys::path::append(AbsolutePath, opts::CompDirOverride);
1639-
sys::path::append(AbsolutePath, DWOName);
1640-
} else if (!sys::fs::exists(DwarfUnit->getCompilationDir()) &&
1641-
sys::fs::exists(DWOName)) {
1639+
DWOCompDir = opts::CompDirOverride;
1640+
} else if (!sys::fs::exists(DWOCompDir) && sys::fs::exists(DWOName)) {
1641+
DWOCompDir = ".";
16421642
this->outs()
16431643
<< "BOLT-WARNING: Debug Fission: Debug Compilation Dir wrong for "
1644-
<< DWOName << ". DWO Name will be directly used for retrieving.\n";
1645-
AbsolutePath = DWOName;
1644+
<< DWOName << ". Relative path will be used for retrieving.\n";
16461645
}
1646+
// Prevent failures when DWOName is already an absolute path.
1647+
sys::fs::make_absolute(DWOCompDir, AbsolutePath);
16471648
DWARFUnit *DWOCU =
16481649
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
16491650
if (!DWOCU->isDWOUnit()) {
16501651
this->outs()
16511652
<< "BOLT-WARNING: Debug Fission: DWO debug information for "
16521653
<< DWOName
16531654
<< " was not retrieved and won't be updated. Please check "
1654-
"relative path.\n";
1655+
"relative path or use '--comp-dir-override' to specify the base "
1656+
"location.\n";
16551657
continue;
16561658
}
16571659
DWOCUs[*DWOId] = DWOCU;

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,17 +1846,16 @@ void DWARFRewriter::writeDWOFiles(
18461846
}
18471847

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

18501851
if (!opts::DwarfOutputPath.empty())
18511852
CompDir = opts::DwarfOutputPath.c_str();
18521853
else if (!opts::CompDirOverride.empty())
18531854
CompDir = opts::CompDirOverride;
1854-
else if (!sys::fs::exists(CompDir) && sys::fs::exists(DWOName))
1855-
CompDir = "";
1856-
1857-
SmallString<16> AbsolutePath;
1858-
sys::path::append(AbsolutePath, CompDir);
1859-
sys::path::append(AbsolutePath, DWOName);
1855+
else if (!sys::fs::exists(CompDir))
1856+
CompDir = ".";
1857+
// Prevent failures when DWOName is already an absolute path.
1858+
sys::fs::make_absolute(CompDir, AbsolutePath);
18601859

18611860
std::error_code EC;
18621861
std::unique_ptr<ToolOutputFile> TempOut =

bolt/test/dwo-name-retrieving.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

bolt/test/dwo-name-retrieving.test

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
## if the Debug Compilation Dir does not exist.
33

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

1410
# DWO-NAME: BOLT-WARNING: Debug Fission: Debug Compilation Dir wrong for
15-
# DWO-NAMET-NOT: Debug Fission: DWO debug information for/data00/home/huangjinjie/llvm-project/bolt/test/dwo-name-retrieving.test
16-
11+
# DWO-NAMET-NOT: Debug Fission: DWO debug information for
12+
# DWO-NAMET-NOT: Assertion `FD >= 0 && "File not yet open!"' failed.
1713

0 commit comments

Comments
 (0)