From 60e9df33625894a0827445e2b354fe870eb44b64 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 2 Oct 2019 06:41:52 +0000 Subject: [llvm-lib] Detect duplicate input files Differential Revision: https://reviews.llvm.org/D68320 llvm-svn: 373426 --- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp') diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp index 025b8a781d2..286191abff2 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 ArgsArr) { } std::vector> MBs; + StringSet<> Seen; std::vector Members; // Create a NewArchiveMember for each input file. @@ -326,6 +328,16 @@ int llvm::libDriverMain(ArrayRef 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> MOrErr = MemoryBuffer::getFile(Path, -1, false); -- cgit v1.2.3