Do not read the same .lib file more than once.

In the following command line,

  lld-link foo/bar.lib /defaultlib:bar.lib

"/defaultlib:bar.lib" should be a nop even if a file with the same
name exists in other library search path.

Fixes https://bugs.llvm.org/show_bug.cgi?id=35476

Differential Revision: https://reviews.llvm.org/D41094

llvm-svn: 320434
This commit is contained in:
Rui Ueyama 2017-12-11 23:09:18 +00:00
parent 9d8ce23c9c
commit b59ceb1068
2 changed files with 10 additions and 0 deletions

View File

@ -315,6 +315,8 @@ Optional<StringRef> LinkerDriver::findFile(StringRef Filename) {
bool Seen = !VisitedFiles.insert(Path.lower()).second;
if (Seen)
return None;
if (Path.endswith_lower(".lib"))
VisitedLibs.insert(sys::path::filename(Path));
return Path;
}

View File

@ -16,3 +16,11 @@ CHECK1: b{{[/\\]}}std64.lib
# RUN: FileCheck -check-prefix=CHECK2 %s < %t.log
CHECK2: a{{[/\\]}}std64.lib
# RUN: lld-link /out:%t.exe /entry:main /verbose \
# RUN: %t/a/std64.lib /subsystem:console %p/Inputs/hello64.obj \
# RUN: /libpath:%t/b /verbose > %t.log 2>&1
# RUN: FileCheck -check-prefix=CHECK3 %s < %t.log
CHECK3: Reading {{.*}}a/std64.lib
CHECK3-NOT: Reading {{.*}}b/std64.lib