xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/COFF.cpp (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===------------------ COFF.cpp - COFF format utilities ------------------===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric 
9*700637cbSDimitry Andric #include "llvm/ExecutionEngine/Orc/COFF.h"
10*700637cbSDimitry Andric #include "llvm/Object/Binary.h"
11*700637cbSDimitry Andric 
12*700637cbSDimitry Andric #define DEBUG_TYPE "orc"
13*700637cbSDimitry Andric 
14*700637cbSDimitry Andric namespace llvm::orc {
15*700637cbSDimitry Andric 
operator ()(object::Archive & A,MemoryBufferRef MemberBuf,size_t Index) const16*700637cbSDimitry Andric Expected<bool> COFFImportFileScanner::operator()(object::Archive &A,
17*700637cbSDimitry Andric                                                  MemoryBufferRef MemberBuf,
18*700637cbSDimitry Andric                                                  size_t Index) const {
19*700637cbSDimitry Andric   // Try to build a binary for the member.
20*700637cbSDimitry Andric   auto Bin = object::createBinary(MemberBuf);
21*700637cbSDimitry Andric   if (!Bin) {
22*700637cbSDimitry Andric     // If we can't then consume the error and return false (i.e. not loadable).
23*700637cbSDimitry Andric     consumeError(Bin.takeError());
24*700637cbSDimitry Andric     return false;
25*700637cbSDimitry Andric   }
26*700637cbSDimitry Andric 
27*700637cbSDimitry Andric   // If this is a COFF import file then handle it and return false (not
28*700637cbSDimitry Andric   // loadable).
29*700637cbSDimitry Andric   if ((*Bin)->isCOFFImportFile()) {
30*700637cbSDimitry Andric     ImportedDynamicLibraries.insert((*Bin)->getFileName().str());
31*700637cbSDimitry Andric     return false;
32*700637cbSDimitry Andric   }
33*700637cbSDimitry Andric 
34*700637cbSDimitry Andric   // Otherwise the member is loadable (at least as far as COFFImportFileScanner
35*700637cbSDimitry Andric   // is concerned), so return true;
36*700637cbSDimitry Andric   return true;
37*700637cbSDimitry Andric }
38*700637cbSDimitry Andric 
39*700637cbSDimitry Andric } // namespace llvm::orc
40