[llvm-dwp] Get the DWO file from relative path if the absolute path is not valid
authorZhang Qing Shan <zhangqingshan.zll@bytedance.com>
Sat, 10 Sep 2022 00:05:20 +0000 (08:05 +0800)
committerZhang Qing Shan <zhangqingshan.zll@bytedance.com>
Tue, 13 Sep 2022 05:45:51 +0000 (13:45 +0800)
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

llvm/test/tools/llvm-dwp/Inputs/search_dwos/a.dwo [new file with mode: 0644]
llvm/test/tools/llvm-dwp/Inputs/search_dwos/b.dwo [new file with mode: 0644]
llvm/test/tools/llvm-dwp/Inputs/search_dwos/main [new file with mode: 0755]
llvm/test/tools/llvm-dwp/X86/search_dwos.test [new file with mode: 0644]
llvm/tools/llvm-dwp/llvm-dwp.cpp

diff --git a/llvm/test/tools/llvm-dwp/Inputs/search_dwos/a.dwo b/llvm/test/tools/llvm-dwp/Inputs/search_dwos/a.dwo
new file mode 100644 (file)
index 0000000..56c6f41
Binary files /dev/null and b/llvm/test/tools/llvm-dwp/Inputs/search_dwos/a.dwo differ
diff --git a/llvm/test/tools/llvm-dwp/Inputs/search_dwos/b.dwo b/llvm/test/tools/llvm-dwp/Inputs/search_dwos/b.dwo
new file mode 100644 (file)
index 0000000..c72acbd
Binary files /dev/null and b/llvm/test/tools/llvm-dwp/Inputs/search_dwos/b.dwo differ
diff --git a/llvm/test/tools/llvm-dwp/Inputs/search_dwos/main b/llvm/test/tools/llvm-dwp/Inputs/search_dwos/main
new file mode 100755 (executable)
index 0000000..f39d615
Binary files /dev/null and b/llvm/test/tools/llvm-dwp/Inputs/search_dwos/main differ
diff --git a/llvm/test/tools/llvm-dwp/X86/search_dwos.test b/llvm/test/tools/llvm-dwp/X86/search_dwos.test
new file mode 100644 (file)
index 0000000..bf45bba
--- /dev/null
@@ -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;
+  }
index 7d1dd61..f9d1dc4 100644 (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));
     }