diff options
| author | Rui Ueyama <ruiu@google.com> | 2017-03-07 21:26:10 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2017-03-07 21:26:10 +0000 |
| commit | 9accea6febaedb4b6c4083c7fbe96ea62b4467f2 (patch) | |
| tree | be35369ebce2369a07d0cc8a2733f0bbf451fb22 | |
| parent | a64fafc7b666fd4ea94b1c733f277903b7bd3fdb (diff) | |
| download | bcm5719-llvm-9accea6febaedb4b6c4083c7fbe96ea62b4467f2.tar.gz bcm5719-llvm-9accea6febaedb4b6c4083c7fbe96ea62b4467f2.zip | |
Pass archive files to link.exe if they contain at least one native object file.
Some archive files created during chromium build contains both BC
and native files. If that's the case, we want to pass the archive
file to link.exe. Otherwise, the MSVC linker would complain that
there's an unresolved symbol in a given set of files.
I cannot explain why link.exe doesn't complain about the presence
of bitcode files in this case, but it seems link.exe doesn't touch BC.
llvm-svn: 297229
| -rw-r--r-- | lld/COFF/Driver.cpp | 12 | ||||
| -rw-r--r-- | lld/test/COFF/msvclto-archive.ll | 15 |
2 files changed, 18 insertions, 9 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 0d14ca40671..51f0b72339a 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -418,8 +418,8 @@ static std::string getMapFile(const opt::InputArgList &Args) { } // Returns true if a given file is a LLVM bitcode file. If it is a -// static library, this function look at the first file in the archive -// to determine if it's a bitcode file. +// static library, this function returns true if all files in the +// archive are bitcode files. static bool isBitcodeFile(StringRef Path) { using namespace sys::fs; @@ -433,14 +433,18 @@ static bool isBitcodeFile(StringRef Path) { if (Magic == file_magic::archive) { std::unique_ptr<Archive> File = check(Archive::create(MB->getMemBufferRef())); + Error Err = Error::success(); for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) { if (Err) - return true; + return false; Archive::Child C = check(COrErr); MemoryBufferRef MBRef = check(C.getMemoryBufferRef()); - return identify_magic(MBRef.getBuffer()) == file_magic::bitcode; + if (identify_magic(MBRef.getBuffer()) != file_magic::bitcode) + return false; } + if (Err) + return false; return true; } diff --git a/lld/test/COFF/msvclto-archive.ll b/lld/test/COFF/msvclto-archive.ll index b525fad3709..937ef5325bf 100644 --- a/lld/test/COFF/msvclto-archive.ll +++ b/lld/test/COFF/msvclto-archive.ll @@ -1,14 +1,19 @@ -;; Make sure we do not pass archive files containing bitcode files. +;; Make sure we do not pass archive files containing only bitcode files. ; RUN: llvm-as -o %t.obj %s -; RUN: llvm-ar cru %t-main.a %t.obj +; RUN: llvm-ar cru %t-main1.a %t.obj ; RUN: mkdir -p %t.dir ; RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t.dir/bitcode.obj %p/Inputs/msvclto.s -; RUN: lld-link %t-main.a %t.dir/bitcode.obj /msvclto /out:%t.exe /opt:lldlto=1 /opt:icf \ +; RUN: lld-link %t-main1.a %t.dir/bitcode.obj /msvclto /out:%t.exe /opt:lldlto=1 /opt:icf \ ; RUN: /entry:main /verbose > %t.log || true -; RUN: FileCheck %s < %t.log +; RUN: FileCheck -check-prefix=BC %s < %t.log +; BC-NOT: link.exe {{.*}}-main1.a -; CHECK-NOT: link.exe {{.*}}t-main.a +; RUN: llvm-ar cru %t-main2.a %t.obj %t.dir/bitcode.obj +; RUN: lld-link %t.dir/bitcode.obj %t-main2.a /msvclto /out:%t.exe /opt:lldlto=1 /opt:icf \ +; RUN: /entry:main /verbose > %t.log || true +; RUN: FileCheck -check-prefix=OBJ %s < %t.log +; OBJ: link.exe {{.*}}-main2.a target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-pc-windows-msvc" |

