LCOV - code coverage report
Current view: top level - lib/ExecutionEngine/RuntimeDyld - JITSymbol.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 27 34 79.4 %
Date: 2018-02-23 15:42:53 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===----------- JITSymbol.cpp - JITSymbol class implementation -----------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // JITSymbol class implementation plus helper functions.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/ExecutionEngine/JITSymbol.h"
      15             : #include "llvm/IR/GlobalValue.h"
      16             : #include "llvm/Object/SymbolicFile.h"
      17             : 
      18             : using namespace llvm;
      19             : 
      20         107 : JITSymbolFlags llvm::JITSymbolFlags::fromGlobalValue(const GlobalValue &GV) {
      21             :   JITSymbolFlags Flags = JITSymbolFlags::None;
      22         106 :   if (GV.hasWeakLinkage() || GV.hasLinkOnceLinkage())
      23             :     Flags |= JITSymbolFlags::Weak;
      24         107 :   if (GV.hasCommonLinkage())
      25           0 :     Flags |= JITSymbolFlags::Common;
      26         106 :   if (!GV.hasLocalLinkage() && !GV.hasHiddenVisibility())
      27         102 :     Flags |= JITSymbolFlags::Exported;
      28         107 :   return Flags;
      29             : }
      30             : 
      31             : JITSymbolFlags
      32        2022 : llvm::JITSymbolFlags::fromObjectSymbol(const object::BasicSymbolRef &Symbol) {
      33             :   JITSymbolFlags Flags = JITSymbolFlags::None;
      34        2022 :   if (Symbol.getFlags() & object::BasicSymbolRef::SF_Weak)
      35             :     Flags |= JITSymbolFlags::Weak;
      36        2022 :   if (Symbol.getFlags() & object::BasicSymbolRef::SF_Common)
      37         106 :     Flags |= JITSymbolFlags::Common;
      38        2022 :   if (Symbol.getFlags() & object::BasicSymbolRef::SF_Exported)
      39         826 :     Flags |= JITSymbolFlags::Exported;
      40        2022 :   return Flags;
      41             : }
      42             : 
      43          25 : ARMJITSymbolFlags llvm::ARMJITSymbolFlags::fromObjectSymbol(
      44             :                                          const object::BasicSymbolRef &Symbol) {
      45             :   ARMJITSymbolFlags Flags;
      46          25 :   if (Symbol.getFlags() & object::BasicSymbolRef::SF_Thumb)
      47             :     Flags |= ARMJITSymbolFlags::Thumb;
      48          25 :   return Flags;
      49             : }
      50             : 
      51             : /// @brief Performs lookup by, for each symbol, first calling
      52             : ///        findSymbolInLogicalDylib and if that fails calling
      53             : ///        findSymbol.
      54             : Expected<JITSymbolResolver::LookupResult>
      55          57 : LegacyJITSymbolResolver::lookup(const LookupSet &Symbols) {
      56             :   JITSymbolResolver::LookupResult Result;
      57         153 :   for (auto &Symbol : Symbols) {
      58             :     std::string SymName = Symbol.str();
      59         192 :     if (auto Sym = findSymbolInLogicalDylib(SymName)) {
      60           0 :       if (auto AddrOrErr = Sym.getAddress())
      61           0 :         Result[Symbol] = JITEvaluatedSymbol(*AddrOrErr, Sym.getFlags());
      62             :       else
      63             :         return AddrOrErr.takeError();
      64          96 :     } else if (auto Err = Sym.takeError())
      65             :       return std::move(Err);
      66             :     else {
      67             :       // findSymbolInLogicalDylib failed. Lets try findSymbol.
      68         192 :       if (auto Sym = findSymbol(SymName)) {
      69         192 :         if (auto AddrOrErr = Sym.getAddress())
      70          96 :           Result[Symbol] = JITEvaluatedSymbol(*AddrOrErr, Sym.getFlags());
      71             :         else
      72             :           return AddrOrErr.takeError();
      73           0 :       } else if (auto Err = Sym.takeError())
      74             :         return std::move(Err);
      75             :       else
      76           0 :         return make_error<StringError>("Symbol not found: " + Symbol,
      77           0 :                                        inconvertibleErrorCode());
      78             :     }
      79             :   }
      80             : 
      81             :   return std::move(Result);
      82             : }
      83             : 
      84             : /// @brief Performs flags lookup by calling findSymbolInLogicalDylib and
      85             : ///        returning the flags value for that symbol.
      86             : Expected<JITSymbolResolver::LookupFlagsResult>
      87         209 : LegacyJITSymbolResolver::lookupFlags(const LookupSet &Symbols) {
      88             :   JITSymbolResolver::LookupFlagsResult Result;
      89             : 
      90         244 :   for (auto &Symbol : Symbols) {
      91             :     std::string SymName = Symbol.str();
      92          70 :     if (auto Sym = findSymbolInLogicalDylib(SymName))
      93           0 :       Result[Symbol] = Sym.getFlags();
      94          35 :     else if (auto Err = Sym.takeError())
      95             :       return std::move(Err);
      96             :   }
      97             : 
      98             :   return std::move(Result);
      99             : }

Generated by: LCOV version 1.13