From 0f0347373785b27ebdabb01555077267e0733593 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 15 Nov 2016 21:36:35 +0000 Subject: [PATCH] Object: replace backslashes with slashes in embedded relative thin archive paths on Windows. This makes these thin archives portable between *nix and Windows. Differential Revision: https://reviews.llvm.org/D26696 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287038 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/ArchiveWriter.cpp | 6 ++++++ test/Object/archive-thin-paths.test | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/Object/archive-thin-paths.test diff --git a/lib/Object/ArchiveWriter.cpp b/lib/Object/ArchiveWriter.cpp index a7cd95f5fdb..64d04a0c729 100644 --- a/lib/Object/ArchiveWriter.cpp +++ b/lib/Object/ArchiveWriter.cpp @@ -205,6 +205,12 @@ static std::string computeRelativePath(StringRef From, StringRef To) { for (auto ToE = sys::path::end(To); ToI != ToE; ++ToI) sys::path::append(Relative, *ToI); +#ifdef LLVM_ON_WIN32 + // Replace backslashes with slashes so that the path is portable between *nix + // and Windows. + std::replace(Relative.begin(), Relative.end(), '\\', '/'); +#endif + return Relative.str(); } diff --git a/test/Object/archive-thin-paths.test b/test/Object/archive-thin-paths.test new file mode 100644 index 00000000000..21788b47acc --- /dev/null +++ b/test/Object/archive-thin-paths.test @@ -0,0 +1,9 @@ +REQUIRES: system-windows + +RUN: cd %T +RUN: mkdir -p archive-thin-paths.dir +RUN: echo foo > archive-thin-paths.dir/foo.o + +RUN: rm -f archive-thin-paths.a +RUN: llvm-ar rcsT archive-thin-paths.a archive-thin-paths.dir\foo.o +RUN: grep archive-thin-paths.dir/foo.o archive-thin-paths.a -- 2.40.0