aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2019-10-02 06:41:52 +0000
committerRui Ueyama <ruiu@google.com>2019-10-02 06:41:52 +0000
commit60e9df33625894a0827445e2b354fe870eb44b64 (patch)
tree1f765adfb59422cd3e7c1174ef426eb3b119680b /llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
parent36b12a861c4f769c1a5fd2fa8107f7dc7ad0d1a4 (diff)
downloadllvm-60e9df33625894a0827445e2b354fe870eb44b64.zip
llvm-60e9df33625894a0827445e2b354fe870eb44b64.tar.gz
llvm-60e9df33625894a0827445e2b354fe870eb44b64.tar.bz2
[llvm-lib] Detect duplicate input files
Differential Revision: https://reviews.llvm.org/D68320 llvm-svn: 373426
Diffstat (limited to 'llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp')
-rw-r--r--llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
index 025b8a78..286191a 100644
--- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -13,6 +13,7 @@
#include "llvm/ToolDrivers/llvm-lib/LibDriver.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Bitcode/BitcodeReader.h"
@@ -315,6 +316,7 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
}
std::vector<std::unique_ptr<MemoryBuffer>> MBs;
+ StringSet<> Seen;
std::vector<NewArchiveMember> Members;
// Create a NewArchiveMember for each input file.
@@ -326,6 +328,16 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
return 1;
}
+ // Input files are uniquified by pathname. If you specify the exact same
+ // path more than once, all but the first one are ignored.
+ //
+ // Note that there's a loophole in the rule; you can prepend `.\` or
+ // something like that to a path to make it look different, and they are
+ // handled as if they were different files. This behavior is compatible with
+ // Microsoft lib.exe.
+ if (!Seen.insert(Path).second)
+ continue;
+
// Open a file.
ErrorOr<std::unique_ptr<MemoryBuffer>> MOrErr =
MemoryBuffer::getFile(Path, -1, false);