LLVM  7.0.0svn
JITSymbol.cpp
Go to the documentation of this file.
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 
15 #include "llvm/IR/GlobalValue.h"
17 
18 using namespace llvm;
19 
22  if (GV.hasWeakLinkage() || GV.hasLinkOnceLinkage())
23  Flags |= JITSymbolFlags::Weak;
24  if (GV.hasCommonLinkage())
25  Flags |= JITSymbolFlags::Common;
26  if (!GV.hasLocalLinkage() && !GV.hasHiddenVisibility())
27  Flags |= JITSymbolFlags::Exported;
28  return Flags;
29 }
30 
35  Flags |= JITSymbolFlags::Weak;
37  Flags |= JITSymbolFlags::Common;
39  Flags |= JITSymbolFlags::Exported;
40  return Flags;
41 }
42 
45  ARMJITSymbolFlags Flags;
47  Flags |= ARMJITSymbolFlags::Thumb;
48  return Flags;
49 }
50 
51 /// Performs lookup by, for each symbol, first calling
52 /// findSymbolInLogicalDylib and if that fails calling
53 /// findSymbol.
57  for (auto &Symbol : Symbols) {
58  std::string SymName = Symbol.str();
59  if (auto Sym = findSymbolInLogicalDylib(SymName)) {
60  if (auto AddrOrErr = Sym.getAddress())
61  Result[Symbol] = JITEvaluatedSymbol(*AddrOrErr, Sym.getFlags());
62  else
63  return AddrOrErr.takeError();
64  } else if (auto Err = Sym.takeError())
65  return std::move(Err);
66  else {
67  // findSymbolInLogicalDylib failed. Lets try findSymbol.
68  if (auto Sym = findSymbol(SymName)) {
69  if (auto AddrOrErr = Sym.getAddress())
70  Result[Symbol] = JITEvaluatedSymbol(*AddrOrErr, Sym.getFlags());
71  else
72  return AddrOrErr.takeError();
73  } else if (auto Err = Sym.takeError())
74  return std::move(Err);
75  else
76  return make_error<StringError>("Symbol not found: " + Symbol,
78  }
79  }
80 
81  return std::move(Result);
82 }
83 
84 /// Performs flags lookup by calling findSymbolInLogicalDylib and
85 /// returning the flags value for that symbol.
89 
90  for (auto &Symbol : Symbols) {
91  std::string SymName = Symbol.str();
92  if (auto Sym = findSymbolInLogicalDylib(SymName))
93  Result[Symbol] = Sym.getFlags();
94  else if (auto Err = Sym.takeError())
95  return std::move(Err);
96  }
97 
98  return std::move(Result);
99 }
std::map< StringRef, JITSymbolFlags > LookupFlagsResult
Definition: JITSymbol.h:296
bool hasLocalLinkage() const
Definition: GlobalValue.h:435
static JITSymbolFlags fromGlobalValue(const GlobalValue &GV)
Construct a JITSymbolFlags value based on the flags of the given global value.
Definition: JITSymbol.cpp:20
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
std::set< StringRef > LookupSet
Definition: JITSymbol.h:294
Expected< LookupResult > lookup(const LookupSet &Symbols) final
Performs lookup by, for each symbol, first calling findSymbolInLogicalDylib and if that fails calling...
Definition: JITSymbol.cpp:55
Expected< LookupFlagsResult > lookupFlags(const LookupSet &Symbols) final
Performs flags lookup by calling findSymbolInLogicalDylib and returning the flags value for that symb...
Definition: JITSymbol.cpp:87
virtual JITSymbol findSymbol(const std::string &Name)=0
This method returns the address of the specified function or variable.
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
bool hasCommonLinkage() const
Definition: GlobalValue.h:439
bool hasLinkOnceLinkage() const
Definition: GlobalValue.h:425
virtual JITSymbol findSymbolInLogicalDylib(const std::string &Name)=0
This method returns the address of the specified symbol if it exists within the logical dynamic libra...
Flags for symbols in the JIT.
Definition: JITSymbol.h:43
static JITSymbolFlags fromObjectSymbol(const object::BasicSymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
Definition: JITSymbol.cpp:32
bool hasWeakLinkage() const
Definition: GlobalValue.h:429
Represents a symbol that has been evaluated to an address already.
Definition: JITSymbol.h:157
bool hasHiddenVisibility() const
Definition: GlobalValue.h:234
uint32_t getFlags() const
Get symbol flags (bitwise OR of SymbolRef::Flags)
Definition: SymbolicFile.h:201
This is a value type class that represents a single symbol in the list of symbols in the object file...
Definition: SymbolicFile.h:99
std::map< StringRef, JITEvaluatedSymbol > LookupResult
Definition: JITSymbol.h:295
ARM-specific JIT symbol flags.
Definition: JITSymbol.h:139
static ARMJITSymbolFlags fromObjectSymbol(const object::BasicSymbolRef &Symbol)
Definition: JITSymbol.cpp:43
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:73