[llvm-dwp] Get the DWO file from relative path if the absolute path is not valid

Extend the llvm-dwp to support searching the DWOs that from relative path for the
case that build from remote building system(different comp_dir).

Reviewd By: dblaikie

Differential Revision: https://reviews.llvm.org/D133480
This commit is contained in:
Zhang Qing Shan 2022-09-10 08:05:20 +08:00
parent 79fa0ec8c4
commit 4531f53851
5 changed files with 26 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,22 @@
RUN: rm -rf %t
RUN: mkdir %t
RUN: cd %t
RUN: cp %p/../Inputs/search_dwos/a.dwo a.dwo
RUN: cp %p/../Inputs/search_dwos/b.dwo b.dwo
RUN: cp %p/../Inputs/search_dwos/main main
RUN: llvm-dwp -e main -o %t.dwp
Search the DWO from relative path if absolute path is not valid.
Build commands for the test binaries:
clang++ -Xclang -fdebug-compilation-dir -Xclang "path-not-exists" -g -O0 -gsplit-dwarf a.cpp b.cpp -o main
sources:
a.cpp:
void a() {}
b.cpp:
void b() {}
int main() {
return 0;
}

View File

@ -71,7 +71,10 @@ getDWOFilenames(StringRef ExecFilename) {
if (!DWOCompDir.empty()) {
SmallString<16> DWOPath(std::move(DWOName));
sys::fs::make_absolute(DWOCompDir, DWOPath);
DWOPaths.emplace_back(DWOPath.data(), DWOPath.size());
if (!sys::fs::exists(DWOPath) && sys::fs::exists(DWOName))
DWOPaths.push_back(std::move(DWOName));
else
DWOPaths.emplace_back(DWOPath.data(), DWOPath.size());
} else {
DWOPaths.push_back(std::move(DWOName));
}