forked from OSchip/llvm-project
[ORC] Add a 'Callable' flag to JITSymbolFlags.
The callable flag can be used to indicate that a symbol is callable. If present, the symbol is callable. If absent, the symbol may or may not be callable (the client must determine this by context, for example by examining the program representation that will provide the symbol definition). This flag will be used in the near future to enable creation of lazy compilation stubs based on SymbolFlagsMap instances only (without having to provide additional information to determine which symbols need stubs). llvm-svn: 338649
This commit is contained in:
parent
54d251b901
commit
bfea8cdc69
|
@ -32,7 +32,7 @@ class GlobalValue;
|
|||
|
||||
namespace object {
|
||||
|
||||
class BasicSymbolRef;
|
||||
class SymbolRef;
|
||||
|
||||
} // end namespace object
|
||||
|
||||
|
@ -52,8 +52,9 @@ public:
|
|||
Common = 1U << 2,
|
||||
Absolute = 1U << 3,
|
||||
Exported = 1U << 4,
|
||||
Lazy = 1U << 5,
|
||||
Materializing = 1U << 6
|
||||
Callable = 1U << 5,
|
||||
Lazy = 1U << 6,
|
||||
Materializing = 1U << 7
|
||||
};
|
||||
|
||||
static JITSymbolFlags stripTransientFlags(JITSymbolFlags Orig) {
|
||||
|
@ -109,6 +110,9 @@ public:
|
|||
return (Flags & Exported) == Exported;
|
||||
}
|
||||
|
||||
/// Returns true if the given symbol is known to be callable.
|
||||
bool isCallable() const { return (Flags & Callable) == Callable; }
|
||||
|
||||
/// Implicitly convert to the underlying flags type.
|
||||
operator UnderlyingType&() { return Flags; }
|
||||
|
||||
|
@ -127,7 +131,8 @@ public:
|
|||
|
||||
/// Construct a JITSymbolFlags value based on the flags of the given libobject
|
||||
/// symbol.
|
||||
static JITSymbolFlags fromObjectSymbol(const object::BasicSymbolRef &Symbol);
|
||||
static Expected<JITSymbolFlags>
|
||||
fromObjectSymbol(const object::SymbolRef &Symbol);
|
||||
|
||||
private:
|
||||
UnderlyingType Flags = None;
|
||||
|
@ -147,8 +152,8 @@ public:
|
|||
|
||||
operator JITSymbolFlags::TargetFlagsType&() { return Flags; }
|
||||
|
||||
static ARMJITSymbolFlags fromObjectSymbol(
|
||||
const object::BasicSymbolRef &Symbol);
|
||||
static ARMJITSymbolFlags fromObjectSymbol(const object::SymbolRef &Symbol);
|
||||
|
||||
private:
|
||||
JITSymbolFlags::TargetFlagsType Flags = 0;
|
||||
};
|
||||
|
|
|
@ -106,15 +106,14 @@ private:
|
|||
/// instance) by calling 'emit' on the given ObjectLayer.
|
||||
class BasicObjectLayerMaterializationUnit : public MaterializationUnit {
|
||||
public:
|
||||
|
||||
|
||||
/// The MemoryBuffer should represent a valid object file.
|
||||
/// If there is any chance that the file is invalid it should be validated
|
||||
/// prior to constructing a BasicObjectLayerMaterializationUnit.
|
||||
BasicObjectLayerMaterializationUnit(ObjectLayer &L, VModuleKey K,
|
||||
std::unique_ptr<MemoryBuffer> O);
|
||||
static Expected<std::unique_ptr<BasicObjectLayerMaterializationUnit>>
|
||||
Create(ObjectLayer &L, VModuleKey K, std::unique_ptr<MemoryBuffer> O);
|
||||
|
||||
private:
|
||||
BasicObjectLayerMaterializationUnit(SymbolFlagsMap SymbolFlags,
|
||||
ObjectLayer &L, VModuleKey K,
|
||||
std::unique_ptr<MemoryBuffer> O);
|
||||
|
||||
void materialize(MaterializationResponsibility R) override;
|
||||
void discard(const VSO &V, SymbolStringPtr Name) override;
|
||||
|
||||
|
|
|
@ -249,9 +249,14 @@ private:
|
|||
consumeError(SymbolName.takeError());
|
||||
continue;
|
||||
}
|
||||
// FIXME: Raise an error for bad symbols.
|
||||
auto Flags = JITSymbolFlags::fromObjectSymbol(Symbol);
|
||||
if (!Flags) {
|
||||
consumeError(Flags.takeError());
|
||||
continue;
|
||||
}
|
||||
SymbolTable.insert(
|
||||
std::make_pair(*SymbolName, JITEvaluatedSymbol(0, Flags)));
|
||||
std::make_pair(*SymbolName, JITEvaluatedSymbol(0, *Flags)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,29 +68,46 @@ ObjectLayer::ObjectLayer(ExecutionSession &ES) : ES(ES) {}
|
|||
ObjectLayer::~ObjectLayer() {}
|
||||
|
||||
Error ObjectLayer::add(VSO &V, VModuleKey K, std::unique_ptr<MemoryBuffer> O) {
|
||||
return V.define(llvm::make_unique<BasicObjectLayerMaterializationUnit>(
|
||||
*this, std::move(K), std::move(O)));
|
||||
auto ObjMU = BasicObjectLayerMaterializationUnit::Create(*this, std::move(K),
|
||||
std::move(O));
|
||||
if (!ObjMU)
|
||||
return ObjMU.takeError();
|
||||
return V.define(std::move(*ObjMU));
|
||||
}
|
||||
|
||||
BasicObjectLayerMaterializationUnit::BasicObjectLayerMaterializationUnit(
|
||||
ObjectLayer &L, VModuleKey K, std::unique_ptr<MemoryBuffer> O)
|
||||
: MaterializationUnit(SymbolFlagsMap()), L(L), K(std::move(K)),
|
||||
O(std::move(O)) {
|
||||
|
||||
Expected<std::unique_ptr<BasicObjectLayerMaterializationUnit>>
|
||||
BasicObjectLayerMaterializationUnit::Create(ObjectLayer &L, VModuleKey K,
|
||||
std::unique_ptr<MemoryBuffer> O) {
|
||||
auto &ES = L.getExecutionSession();
|
||||
auto Obj = cantFail(
|
||||
object::ObjectFile::createObjectFile(this->O->getMemBufferRef()));
|
||||
auto Obj = object::ObjectFile::createObjectFile(O->getMemBufferRef());
|
||||
|
||||
for (auto &Sym : Obj->symbols()) {
|
||||
if (!Obj)
|
||||
return Obj.takeError();
|
||||
|
||||
SymbolFlagsMap SymbolFlags;
|
||||
for (auto &Sym : (*Obj)->symbols()) {
|
||||
if (!(Sym.getFlags() & object::BasicSymbolRef::SF_Undefined) &&
|
||||
(Sym.getFlags() & object::BasicSymbolRef::SF_Exported)) {
|
||||
auto InternedName =
|
||||
ES.getSymbolStringPool().intern(cantFail(Sym.getName()));
|
||||
SymbolFlags[InternedName] = JITSymbolFlags::fromObjectSymbol(Sym);
|
||||
auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
|
||||
if (!SymFlags)
|
||||
return SymFlags.takeError();
|
||||
SymbolFlags[InternedName] = std::move(*SymFlags);
|
||||
}
|
||||
}
|
||||
|
||||
return std::unique_ptr<BasicObjectLayerMaterializationUnit>(
|
||||
new BasicObjectLayerMaterializationUnit(std::move(SymbolFlags), L, K,
|
||||
std::move(O)));
|
||||
}
|
||||
|
||||
BasicObjectLayerMaterializationUnit::BasicObjectLayerMaterializationUnit(
|
||||
SymbolFlagsMap SymbolFlags, ObjectLayer &L, VModuleKey K,
|
||||
std::unique_ptr<MemoryBuffer> O)
|
||||
: MaterializationUnit(std::move(SymbolFlags)), L(L), K(std::move(K)),
|
||||
O(std::move(O)) {}
|
||||
|
||||
void BasicObjectLayerMaterializationUnit::materialize(
|
||||
MaterializationResponsibility R) {
|
||||
L.emit(std::move(R), std::move(K), std::move(O));
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ExecutionEngine/JITSymbol.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/GlobalValue.h"
|
||||
#include "llvm/Object/SymbolicFile.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
|
@ -25,11 +26,13 @@ JITSymbolFlags llvm::JITSymbolFlags::fromGlobalValue(const GlobalValue &GV) {
|
|||
Flags |= JITSymbolFlags::Common;
|
||||
if (!GV.hasLocalLinkage() && !GV.hasHiddenVisibility())
|
||||
Flags |= JITSymbolFlags::Exported;
|
||||
if (isa<Function>(GV))
|
||||
Flags |= JITSymbolFlags::Callable;
|
||||
return Flags;
|
||||
}
|
||||
|
||||
JITSymbolFlags
|
||||
llvm::JITSymbolFlags::fromObjectSymbol(const object::BasicSymbolRef &Symbol) {
|
||||
Expected<JITSymbolFlags>
|
||||
llvm::JITSymbolFlags::fromObjectSymbol(const object::SymbolRef &Symbol) {
|
||||
JITSymbolFlags Flags = JITSymbolFlags::None;
|
||||
if (Symbol.getFlags() & object::BasicSymbolRef::SF_Weak)
|
||||
Flags |= JITSymbolFlags::Weak;
|
||||
|
@ -37,11 +40,19 @@ llvm::JITSymbolFlags::fromObjectSymbol(const object::BasicSymbolRef &Symbol) {
|
|||
Flags |= JITSymbolFlags::Common;
|
||||
if (Symbol.getFlags() & object::BasicSymbolRef::SF_Exported)
|
||||
Flags |= JITSymbolFlags::Exported;
|
||||
|
||||
auto SymbolType = Symbol.getType();
|
||||
if (!SymbolType)
|
||||
return SymbolType.takeError();
|
||||
|
||||
if (*SymbolType & object::SymbolRef::ST_Function)
|
||||
Flags |= JITSymbolFlags::Callable;
|
||||
|
||||
return Flags;
|
||||
}
|
||||
|
||||
ARMJITSymbolFlags llvm::ARMJITSymbolFlags::fromObjectSymbol(
|
||||
const object::BasicSymbolRef &Symbol) {
|
||||
ARMJITSymbolFlags
|
||||
llvm::ARMJITSymbolFlags::fromObjectSymbol(const object::SymbolRef &Symbol) {
|
||||
ARMJITSymbolFlags Flags;
|
||||
if (Symbol.getFlags() & object::BasicSymbolRef::SF_Thumb)
|
||||
Flags |= ARMJITSymbolFlags::Thumb;
|
||||
|
|
|
@ -249,13 +249,15 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
|
|||
return NameOrErr.takeError();
|
||||
|
||||
// Compute JIT symbol flags.
|
||||
JITSymbolFlags JITSymFlags = getJITSymbolFlags(*I);
|
||||
auto JITSymFlags = getJITSymbolFlags(*I);
|
||||
if (!JITSymFlags)
|
||||
return JITSymFlags.takeError();
|
||||
|
||||
// If this is a weak definition, check to see if there's a strong one.
|
||||
// If there is, skip this symbol (we won't be providing it: the strong
|
||||
// definition will). If there's no strong definition, make this definition
|
||||
// strong.
|
||||
if (JITSymFlags.isWeak() || JITSymFlags.isCommon()) {
|
||||
if (JITSymFlags->isWeak() || JITSymFlags->isCommon()) {
|
||||
// First check whether there's already a definition in this instance.
|
||||
// FIXME: Override existing weak definitions with strong ones.
|
||||
if (GlobalSymbolTable.count(Name))
|
||||
|
@ -265,12 +267,12 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
|
|||
// flags lookup earlier.
|
||||
auto FlagsI = SymbolFlags.find(Name);
|
||||
if (FlagsI == SymbolFlags.end() ||
|
||||
(JITSymFlags.isWeak() && !FlagsI->second.isStrong()) ||
|
||||
(JITSymFlags.isCommon() && FlagsI->second.isCommon())) {
|
||||
if (JITSymFlags.isWeak())
|
||||
JITSymFlags &= ~JITSymbolFlags::Weak;
|
||||
if (JITSymFlags.isCommon()) {
|
||||
JITSymFlags &= ~JITSymbolFlags::Common;
|
||||
(JITSymFlags->isWeak() && !FlagsI->second.isStrong()) ||
|
||||
(JITSymFlags->isCommon() && FlagsI->second.isCommon())) {
|
||||
if (JITSymFlags->isWeak())
|
||||
*JITSymFlags &= ~JITSymbolFlags::Weak;
|
||||
if (JITSymFlags->isCommon()) {
|
||||
*JITSymFlags &= ~JITSymbolFlags::Common;
|
||||
uint32_t Align = I->getAlignment();
|
||||
uint64_t Size = I->getCommonSize();
|
||||
if (!CommonAlign)
|
||||
|
@ -296,7 +298,7 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
|
|||
<< " SID: " << SectionID
|
||||
<< " Offset: " << format("%p", (uintptr_t)Addr)
|
||||
<< " flags: " << Flags << "\n");
|
||||
GlobalSymbolTable[Name] = SymbolTableEntry(SectionID, Addr, JITSymFlags);
|
||||
GlobalSymbolTable[Name] = SymbolTableEntry(SectionID, Addr, *JITSymFlags);
|
||||
} else if (SymType == object::SymbolRef::ST_Function ||
|
||||
SymType == object::SymbolRef::ST_Data ||
|
||||
SymType == object::SymbolRef::ST_Unknown ||
|
||||
|
@ -329,7 +331,7 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) {
|
|||
<< " Offset: " << format("%p", (uintptr_t)SectOffset)
|
||||
<< " flags: " << Flags << "\n");
|
||||
GlobalSymbolTable[Name] =
|
||||
SymbolTableEntry(SectionID, SectOffset, JITSymFlags);
|
||||
SymbolTableEntry(SectionID, SectOffset, *JITSymFlags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -642,7 +644,8 @@ void RuntimeDyldImpl::writeBytesUnaligned(uint64_t Value, uint8_t *Dst,
|
|||
}
|
||||
}
|
||||
|
||||
JITSymbolFlags RuntimeDyldImpl::getJITSymbolFlags(const BasicSymbolRef &SR) {
|
||||
Expected<JITSymbolFlags>
|
||||
RuntimeDyldImpl::getJITSymbolFlags(const SymbolRef &SR) {
|
||||
return JITSymbolFlags::fromObjectSymbol(SR);
|
||||
}
|
||||
|
||||
|
@ -683,11 +686,15 @@ Error RuntimeDyldImpl::emitCommonSymbols(const ObjectFile &Obj,
|
|||
Addr += AlignOffset;
|
||||
Offset += AlignOffset;
|
||||
}
|
||||
JITSymbolFlags JITSymFlags = getJITSymbolFlags(Sym);
|
||||
auto JITSymFlags = getJITSymbolFlags(Sym);
|
||||
|
||||
if (!JITSymFlags)
|
||||
return JITSymFlags.takeError();
|
||||
|
||||
LLVM_DEBUG(dbgs() << "Allocating common symbol " << Name << " address "
|
||||
<< format("%p", Addr) << "\n");
|
||||
GlobalSymbolTable[Name] =
|
||||
SymbolTableEntry(SectionID, Offset, JITSymFlags);
|
||||
SymbolTableEntry(SectionID, Offset, std::move(*JITSymFlags));
|
||||
Offset += Size;
|
||||
Addr += Size;
|
||||
}
|
||||
|
|
|
@ -370,7 +370,7 @@ protected:
|
|||
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const;
|
||||
|
||||
/// Generate JITSymbolFlags from a libObject symbol.
|
||||
virtual JITSymbolFlags getJITSymbolFlags(const BasicSymbolRef &Sym);
|
||||
virtual Expected<JITSymbolFlags> getJITSymbolFlags(const SymbolRef &Sym);
|
||||
|
||||
/// Modify the given target address based on the given symbol flags.
|
||||
/// This can be used by subclasses to tweak addresses based on symbol flags,
|
||||
|
|
|
@ -34,9 +34,11 @@ public:
|
|||
|
||||
unsigned getStubAlignment() override { return 4; }
|
||||
|
||||
JITSymbolFlags getJITSymbolFlags(const BasicSymbolRef &SR) override {
|
||||
Expected<JITSymbolFlags> getJITSymbolFlags(const SymbolRef &SR) override {
|
||||
auto Flags = RuntimeDyldImpl::getJITSymbolFlags(SR);
|
||||
Flags.getTargetFlags() = ARMJITSymbolFlags::fromObjectSymbol(SR);
|
||||
if (!Flags)
|
||||
return Flags.takeError();
|
||||
Flags->getTargetFlags() = ARMJITSymbolFlags::fromObjectSymbol(SR);
|
||||
return Flags;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue