Skip to content

Commit 60e9df3

Browse files
committed
[llvm-lib] Detect duplicate input files
Differential Revision: https://reviews.llvm.org/D68320 llvm-svn: 373426
1 parent 36b12a8 commit 60e9df3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "llvm/ToolDrivers/llvm-lib/LibDriver.h"
1515
#include "llvm/ADT/STLExtras.h"
16+
#include "llvm/ADT/StringSet.h"
1617
#include "llvm/BinaryFormat/COFF.h"
1718
#include "llvm/BinaryFormat/Magic.h"
1819
#include "llvm/Bitcode/BitcodeReader.h"
@@ -315,6 +316,7 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
315316
}
316317

317318
std::vector<std::unique_ptr<MemoryBuffer>> MBs;
319+
StringSet<> Seen;
318320
std::vector<NewArchiveMember> Members;
319321

320322
// Create a NewArchiveMember for each input file.
@@ -326,6 +328,16 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
326328
return 1;
327329
}
328330

331+
// Input files are uniquified by pathname. If you specify the exact same
332+
// path more than once, all but the first one are ignored.
333+
//
334+
// Note that there's a loophole in the rule; you can prepend `.\` or
335+
// something like that to a path to make it look different, and they are
336+
// handled as if they were different files. This behavior is compatible with
337+
// Microsoft lib.exe.
338+
if (!Seen.insert(Path).second)
339+
continue;
340+
329341
// Open a file.
330342
ErrorOr<std::unique_ptr<MemoryBuffer>> MOrErr =
331343
MemoryBuffer::getFile(Path, -1, false);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
If the same file is specified more than once as an input file,
2+
llvm-lib should ignore all but the first occurrence of the file.
3+
4+
RUN: rm -rf %t
5+
RUN: mkdir -p %t
6+
7+
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/foo.o %S/Inputs/a.s
8+
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/bar.o %S/Inputs/b.s
9+
RUN: llvm-lib -out:%t/foo.lib %t/foo.o %t/foo.o %t/bar.o
10+
11+
RUN: llvm-ar t %t/foo.lib | FileCheck %s
12+
CHECK: foo.o
13+
CHECK-NOT: foo.o
14+
CHECK: bar.o

0 commit comments

Comments
 (0)