forked from OSchip/llvm-project
[JITLink] Update JITLink to use ExecutorAddr rather than JITTargetAddress.
ExecutorAddr is the preferred representation for executor process addresses now.
This commit is contained in:
parent
9e2cfb061a
commit
133f86e954
|
@ -100,14 +100,15 @@ private:
|
|||
return;
|
||||
}
|
||||
|
||||
JITTargetAddress InitAddr = B.getAddress() & ~(LineWidth - 1);
|
||||
JITTargetAddress StartAddr = B.getAddress();
|
||||
JITTargetAddress EndAddr = B.getAddress() + B.getSize();
|
||||
ExecutorAddr InitAddr(B.getAddress().getValue() & ~(LineWidth - 1));
|
||||
ExecutorAddr StartAddr = B.getAddress();
|
||||
ExecutorAddr EndAddr = B.getAddress() + B.getSize();
|
||||
auto *Data = reinterpret_cast<const uint8_t *>(B.getContent().data());
|
||||
|
||||
for (JITTargetAddress CurAddr = InitAddr; CurAddr != EndAddr; ++CurAddr) {
|
||||
for (ExecutorAddr CurAddr = InitAddr; CurAddr != EndAddr; ++CurAddr) {
|
||||
if (CurAddr % LineWidth == 0)
|
||||
outs() << " " << formatv("{0:x16}", CurAddr) << ": ";
|
||||
outs() << " " << formatv("{0:x16}", CurAddr.getValue())
|
||||
<< ": ";
|
||||
if (CurAddr < StartAddr)
|
||||
outs() << " ";
|
||||
else
|
||||
|
|
|
@ -25,25 +25,24 @@ namespace jitlink {
|
|||
class EHFrameRegistrar {
|
||||
public:
|
||||
virtual ~EHFrameRegistrar();
|
||||
virtual Error registerEHFrames(JITTargetAddress EHFrameSectionAddr,
|
||||
virtual Error registerEHFrames(orc::ExecutorAddr EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) = 0;
|
||||
virtual Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr,
|
||||
virtual Error deregisterEHFrames(orc::ExecutorAddr EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) = 0;
|
||||
};
|
||||
|
||||
/// Registers / Deregisters EH-frames in the current process.
|
||||
class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
|
||||
public:
|
||||
Error registerEHFrames(JITTargetAddress EHFrameSectionAddr,
|
||||
Error registerEHFrames(orc::ExecutorAddr EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) override;
|
||||
|
||||
Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr,
|
||||
Error deregisterEHFrames(orc::ExecutorAddr EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) override;
|
||||
};
|
||||
|
||||
using StoreFrameRangeFunction =
|
||||
std::function<void(JITTargetAddress EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize)>;
|
||||
using StoreFrameRangeFunction = std::function<void(
|
||||
orc::ExecutorAddr EHFrameSectionAddr, size_t EHFrameSectionSize)>;
|
||||
|
||||
/// Creates a pass that records the address and size of the EH frame section.
|
||||
/// If no eh-frame section is found then the address and size will both be given
|
||||
|
|
|
@ -104,10 +104,10 @@ class Addressable {
|
|||
friend class LinkGraph;
|
||||
|
||||
protected:
|
||||
Addressable(JITTargetAddress Address, bool IsDefined)
|
||||
Addressable(orc::ExecutorAddr Address, bool IsDefined)
|
||||
: Address(Address), IsDefined(IsDefined), IsAbsolute(false) {}
|
||||
|
||||
Addressable(JITTargetAddress Address)
|
||||
Addressable(orc::ExecutorAddr Address)
|
||||
: Address(Address), IsDefined(false), IsAbsolute(true) {
|
||||
assert(!(IsDefined && IsAbsolute) &&
|
||||
"Block cannot be both defined and absolute");
|
||||
|
@ -119,8 +119,8 @@ public:
|
|||
Addressable(Addressable &&) = delete;
|
||||
Addressable &operator=(Addressable &&) = default;
|
||||
|
||||
JITTargetAddress getAddress() const { return Address; }
|
||||
void setAddress(JITTargetAddress Address) { this->Address = Address; }
|
||||
orc::ExecutorAddr getAddress() const { return Address; }
|
||||
void setAddress(orc::ExecutorAddr Address) { this->Address = Address; }
|
||||
|
||||
/// Returns true if this is a defined addressable, in which case you
|
||||
/// can downcast this to a Block.
|
||||
|
@ -133,7 +133,7 @@ private:
|
|||
this->IsAbsolute = IsAbsolute;
|
||||
}
|
||||
|
||||
JITTargetAddress Address = 0;
|
||||
orc::ExecutorAddr Address;
|
||||
uint64_t IsDefined : 1;
|
||||
uint64_t IsAbsolute : 1;
|
||||
|
||||
|
@ -152,7 +152,7 @@ class Block : public Addressable {
|
|||
|
||||
private:
|
||||
/// Create a zero-fill defined addressable.
|
||||
Block(Section &Parent, JITTargetAddress Size, JITTargetAddress Address,
|
||||
Block(Section &Parent, orc::ExecutorAddrDiff Size, orc::ExecutorAddr Address,
|
||||
uint64_t Alignment, uint64_t AlignmentOffset)
|
||||
: Addressable(Address, true), Parent(&Parent), Size(Size) {
|
||||
assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
|
||||
|
@ -168,7 +168,7 @@ private:
|
|||
/// Create a defined addressable for the given content.
|
||||
/// The Content is assumed to be non-writable, and will be copied when
|
||||
/// mutations are required.
|
||||
Block(Section &Parent, ArrayRef<char> Content, JITTargetAddress Address,
|
||||
Block(Section &Parent, ArrayRef<char> Content, orc::ExecutorAddr Address,
|
||||
uint64_t Alignment, uint64_t AlignmentOffset)
|
||||
: Addressable(Address, true), Parent(&Parent), Data(Content.data()),
|
||||
Size(Content.size()) {
|
||||
|
@ -188,7 +188,7 @@ private:
|
|||
/// The standard way to achieve this is to allocate it on the Graph's
|
||||
/// allocator.
|
||||
Block(Section &Parent, MutableArrayRef<char> Content,
|
||||
JITTargetAddress Address, uint64_t Alignment, uint64_t AlignmentOffset)
|
||||
orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
|
||||
: Addressable(Address, true), Parent(&Parent), Data(Content.data()),
|
||||
Size(Content.size()) {
|
||||
assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
|
||||
|
@ -328,7 +328,7 @@ public:
|
|||
|
||||
/// Returns the address of the fixup for the given edge, which is equal to
|
||||
/// this block's address plus the edge's offset.
|
||||
JITTargetAddress getFixupAddress(const Edge &E) const {
|
||||
orc::ExecutorAddr getFixupAddress(const Edge &E) const {
|
||||
return getAddress() + E.getOffset();
|
||||
}
|
||||
|
||||
|
@ -343,12 +343,17 @@ private:
|
|||
std::vector<Edge> Edges;
|
||||
};
|
||||
|
||||
// Align a JITTargetAddress to conform with block alignment requirements.
|
||||
inline JITTargetAddress alignToBlock(JITTargetAddress Addr, Block &B) {
|
||||
// Align an address to conform with block alignment requirements.
|
||||
inline uint64_t alignToBlock(uint64_t Addr, Block &B) {
|
||||
uint64_t Delta = (B.getAlignmentOffset() - Addr) % B.getAlignment();
|
||||
return Addr + Delta;
|
||||
}
|
||||
|
||||
// Align a orc::ExecutorAddr to conform with block alignment requirements.
|
||||
inline orc::ExecutorAddr alignToBlock(orc::ExecutorAddr Addr, Block &B) {
|
||||
return orc::ExecutorAddr(alignToBlock(Addr.getValue(), B));
|
||||
}
|
||||
|
||||
/// Describes symbol linkage. This can be used to make resolve definition
|
||||
/// clashes.
|
||||
enum class Linkage : uint8_t {
|
||||
|
@ -391,8 +396,8 @@ class Symbol {
|
|||
friend class LinkGraph;
|
||||
|
||||
private:
|
||||
Symbol(Addressable &Base, JITTargetAddress Offset, StringRef Name,
|
||||
JITTargetAddress Size, Linkage L, Scope S, bool IsLive,
|
||||
Symbol(Addressable &Base, orc::ExecutorAddrDiff Offset, StringRef Name,
|
||||
orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive,
|
||||
bool IsCallable)
|
||||
: Name(Name), Base(&Base), Offset(Offset), Size(Size) {
|
||||
assert(Offset <= MaxOffset && "Offset out of range");
|
||||
|
@ -403,7 +408,8 @@ private:
|
|||
}
|
||||
|
||||
static Symbol &constructCommon(void *SymStorage, Block &Base, StringRef Name,
|
||||
JITTargetAddress Size, Scope S, bool IsLive) {
|
||||
orc::ExecutorAddrDiff Size, Scope S,
|
||||
bool IsLive) {
|
||||
assert(SymStorage && "Storage cannot be null");
|
||||
assert(!Name.empty() && "Common symbol name cannot be empty");
|
||||
assert(Base.isDefined() &&
|
||||
|
@ -416,7 +422,7 @@ private:
|
|||
}
|
||||
|
||||
static Symbol &constructExternal(void *SymStorage, Addressable &Base,
|
||||
StringRef Name, JITTargetAddress Size,
|
||||
StringRef Name, orc::ExecutorAddrDiff Size,
|
||||
Linkage L) {
|
||||
assert(SymStorage && "Storage cannot be null");
|
||||
assert(!Base.isDefined() &&
|
||||
|
@ -428,7 +434,7 @@ private:
|
|||
}
|
||||
|
||||
static Symbol &constructAbsolute(void *SymStorage, Addressable &Base,
|
||||
StringRef Name, JITTargetAddress Size,
|
||||
StringRef Name, orc::ExecutorAddrDiff Size,
|
||||
Linkage L, Scope S, bool IsLive) {
|
||||
assert(SymStorage && "Storage cannot be null");
|
||||
assert(!Base.isDefined() &&
|
||||
|
@ -439,8 +445,8 @@ private:
|
|||
}
|
||||
|
||||
static Symbol &constructAnonDef(void *SymStorage, Block &Base,
|
||||
JITTargetAddress Offset,
|
||||
JITTargetAddress Size, bool IsCallable,
|
||||
orc::ExecutorAddrDiff Offset,
|
||||
orc::ExecutorAddrDiff Size, bool IsCallable,
|
||||
bool IsLive) {
|
||||
assert(SymStorage && "Storage cannot be null");
|
||||
assert((Offset + Size) <= Base.getSize() &&
|
||||
|
@ -452,9 +458,9 @@ private:
|
|||
}
|
||||
|
||||
static Symbol &constructNamedDef(void *SymStorage, Block &Base,
|
||||
JITTargetAddress Offset, StringRef Name,
|
||||
JITTargetAddress Size, Linkage L, Scope S,
|
||||
bool IsLive, bool IsCallable) {
|
||||
orc::ExecutorAddrDiff Offset, StringRef Name,
|
||||
orc::ExecutorAddrDiff Size, Linkage L,
|
||||
Scope S, bool IsLive, bool IsCallable) {
|
||||
assert(SymStorage && "Storage cannot be null");
|
||||
assert((Offset + Size) <= Base.getSize() &&
|
||||
"Symbol extends past end of block");
|
||||
|
@ -552,16 +558,16 @@ public:
|
|||
}
|
||||
|
||||
/// Returns the offset for this symbol within the underlying addressable.
|
||||
JITTargetAddress getOffset() const { return Offset; }
|
||||
orc::ExecutorAddrDiff getOffset() const { return Offset; }
|
||||
|
||||
/// Returns the address of this symbol.
|
||||
JITTargetAddress getAddress() const { return Base->getAddress() + Offset; }
|
||||
orc::ExecutorAddr getAddress() const { return Base->getAddress() + Offset; }
|
||||
|
||||
/// Returns the size of this symbol.
|
||||
JITTargetAddress getSize() const { return Size; }
|
||||
orc::ExecutorAddrDiff getSize() const { return Size; }
|
||||
|
||||
/// Set the size of this symbol.
|
||||
void setSize(JITTargetAddress Size) {
|
||||
void setSize(orc::ExecutorAddrDiff Size) {
|
||||
assert(Base && "Cannot set size for null Symbol");
|
||||
assert((Size == 0 || Base->isDefined()) &&
|
||||
"Non-zero size can only be set for defined symbols");
|
||||
|
@ -622,7 +628,7 @@ private:
|
|||
|
||||
void setBlock(Block &B) { Base = &B; }
|
||||
|
||||
void setOffset(uint64_t NewOffset) {
|
||||
void setOffset(orc::ExecutorAddrDiff NewOffset) {
|
||||
assert(NewOffset <= MaxOffset && "Offset out of range");
|
||||
Offset = NewOffset;
|
||||
}
|
||||
|
@ -637,7 +643,7 @@ private:
|
|||
uint64_t S : 2;
|
||||
uint64_t IsLive : 1;
|
||||
uint64_t IsCallable : 1;
|
||||
JITTargetAddress Size = 0;
|
||||
orc::ExecutorAddrDiff Size = 0;
|
||||
};
|
||||
|
||||
raw_ostream &operator<<(raw_ostream &OS, const Symbol &A);
|
||||
|
@ -783,13 +789,13 @@ public:
|
|||
assert((First || !Last) && "Last can not be null if start is non-null");
|
||||
return !First;
|
||||
}
|
||||
JITTargetAddress getStart() const {
|
||||
return First ? First->getAddress() : 0;
|
||||
orc::ExecutorAddr getStart() const {
|
||||
return First ? First->getAddress() : orc::ExecutorAddr();
|
||||
}
|
||||
JITTargetAddress getEnd() const {
|
||||
return Last ? Last->getAddress() + Last->getSize() : 0;
|
||||
orc::ExecutorAddr getEnd() const {
|
||||
return Last ? Last->getAddress() + Last->getSize() : orc::ExecutorAddr();
|
||||
}
|
||||
uint64_t getSize() const { return getEnd() - getStart(); }
|
||||
orc::ExecutorAddrDiff getSize() const { return getEnd() - getStart(); }
|
||||
|
||||
private:
|
||||
Block *First = nullptr;
|
||||
|
@ -995,7 +1001,7 @@ public:
|
|||
|
||||
/// Create a content block.
|
||||
Block &createContentBlock(Section &Parent, ArrayRef<char> Content,
|
||||
uint64_t Address, uint64_t Alignment,
|
||||
orc::ExecutorAddr Address, uint64_t Alignment,
|
||||
uint64_t AlignmentOffset) {
|
||||
return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
|
||||
}
|
||||
|
@ -1003,15 +1009,17 @@ public:
|
|||
/// Create a content block with initially mutable data.
|
||||
Block &createMutableContentBlock(Section &Parent,
|
||||
MutableArrayRef<char> MutableContent,
|
||||
uint64_t Address, uint64_t Alignment,
|
||||
orc::ExecutorAddr Address,
|
||||
uint64_t Alignment,
|
||||
uint64_t AlignmentOffset) {
|
||||
return createBlock(Parent, MutableContent, Address, Alignment,
|
||||
AlignmentOffset);
|
||||
}
|
||||
|
||||
/// Create a zero-fill block.
|
||||
Block &createZeroFillBlock(Section &Parent, uint64_t Size, uint64_t Address,
|
||||
uint64_t Alignment, uint64_t AlignmentOffset) {
|
||||
Block &createZeroFillBlock(Section &Parent, orc::ExecutorAddrDiff Size,
|
||||
orc::ExecutorAddr Address, uint64_t Alignment,
|
||||
uint64_t AlignmentOffset) {
|
||||
return createBlock(Parent, Size, Address, Alignment, AlignmentOffset);
|
||||
}
|
||||
|
||||
|
@ -1061,22 +1069,24 @@ public:
|
|||
/// present during lookup: Externals with strong linkage must be found or
|
||||
/// an error will be emitted. Externals with weak linkage are permitted to
|
||||
/// be undefined, in which case they are assigned a value of 0.
|
||||
Symbol &addExternalSymbol(StringRef Name, uint64_t Size, Linkage L) {
|
||||
Symbol &addExternalSymbol(StringRef Name, orc::ExecutorAddrDiff Size,
|
||||
Linkage L) {
|
||||
assert(llvm::count_if(ExternalSymbols,
|
||||
[&](const Symbol *Sym) {
|
||||
return Sym->getName() == Name;
|
||||
}) == 0 &&
|
||||
"Duplicate external symbol");
|
||||
auto &Sym =
|
||||
Symbol::constructExternal(Allocator.Allocate<Symbol>(),
|
||||
createAddressable(0, false), Name, Size, L);
|
||||
auto &Sym = Symbol::constructExternal(
|
||||
Allocator.Allocate<Symbol>(),
|
||||
createAddressable(orc::ExecutorAddr(), false), Name, Size, L);
|
||||
ExternalSymbols.insert(&Sym);
|
||||
return Sym;
|
||||
}
|
||||
|
||||
/// Add an absolute symbol.
|
||||
Symbol &addAbsoluteSymbol(StringRef Name, JITTargetAddress Address,
|
||||
uint64_t Size, Linkage L, Scope S, bool IsLive) {
|
||||
Symbol &addAbsoluteSymbol(StringRef Name, orc::ExecutorAddr Address,
|
||||
orc::ExecutorAddrDiff Size, Linkage L, Scope S,
|
||||
bool IsLive) {
|
||||
assert(llvm::count_if(AbsoluteSymbols,
|
||||
[&](const Symbol *Sym) {
|
||||
return Sym->getName() == Name;
|
||||
|
@ -1091,7 +1101,7 @@ public:
|
|||
|
||||
/// Convenience method for adding a weak zero-fill symbol.
|
||||
Symbol &addCommonSymbol(StringRef Name, Scope S, Section &Section,
|
||||
JITTargetAddress Address, uint64_t Size,
|
||||
orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size,
|
||||
uint64_t Alignment, bool IsLive) {
|
||||
assert(llvm::count_if(defined_symbols(),
|
||||
[&](const Symbol *Sym) {
|
||||
|
@ -1107,8 +1117,8 @@ public:
|
|||
}
|
||||
|
||||
/// Add an anonymous symbol.
|
||||
Symbol &addAnonymousSymbol(Block &Content, JITTargetAddress Offset,
|
||||
JITTargetAddress Size, bool IsCallable,
|
||||
Symbol &addAnonymousSymbol(Block &Content, orc::ExecutorAddrDiff Offset,
|
||||
orc::ExecutorAddrDiff Size, bool IsCallable,
|
||||
bool IsLive) {
|
||||
auto &Sym = Symbol::constructAnonDef(Allocator.Allocate<Symbol>(), Content,
|
||||
Offset, Size, IsCallable, IsLive);
|
||||
|
@ -1117,9 +1127,9 @@ public:
|
|||
}
|
||||
|
||||
/// Add a named symbol.
|
||||
Symbol &addDefinedSymbol(Block &Content, JITTargetAddress Offset,
|
||||
StringRef Name, JITTargetAddress Size, Linkage L,
|
||||
Scope S, bool IsCallable, bool IsLive) {
|
||||
Symbol &addDefinedSymbol(Block &Content, orc::ExecutorAddrDiff Offset,
|
||||
StringRef Name, orc::ExecutorAddrDiff Size,
|
||||
Linkage L, Scope S, bool IsCallable, bool IsLive) {
|
||||
assert((S == Scope::Local || llvm::count_if(defined_symbols(),
|
||||
[&](const Symbol *Sym) {
|
||||
return Sym->getName() == Name;
|
||||
|
@ -1193,7 +1203,7 @@ public:
|
|||
assert(Sym.isDefined() && "Sym is not a defined symbol");
|
||||
Section &Sec = Sym.getBlock().getSection();
|
||||
Sec.removeSymbol(Sym);
|
||||
Sym.makeExternal(createAddressable(0, false));
|
||||
Sym.makeExternal(createAddressable(orc::ExecutorAddr(), false));
|
||||
}
|
||||
ExternalSymbols.insert(&Sym);
|
||||
}
|
||||
|
@ -1203,7 +1213,7 @@ public:
|
|||
///
|
||||
/// Symbol size, linkage, scope, and callability, and liveness will be left
|
||||
/// unchanged. Symbol offset will be reset to 0.
|
||||
void makeAbsolute(Symbol &Sym, JITTargetAddress Address) {
|
||||
void makeAbsolute(Symbol &Sym, orc::ExecutorAddr Address) {
|
||||
assert(!Sym.isAbsolute() && "Symbol is already absolute");
|
||||
if (Sym.isExternal()) {
|
||||
assert(ExternalSymbols.count(&Sym) &&
|
||||
|
@ -1222,8 +1232,9 @@ public:
|
|||
|
||||
/// Turn an absolute or external symbol into a defined one by attaching it to
|
||||
/// a block. Symbol must not already be defined.
|
||||
void makeDefined(Symbol &Sym, Block &Content, JITTargetAddress Offset,
|
||||
JITTargetAddress Size, Linkage L, Scope S, bool IsLive) {
|
||||
void makeDefined(Symbol &Sym, Block &Content, orc::ExecutorAddrDiff Offset,
|
||||
orc::ExecutorAddrDiff Size, Linkage L, Scope S,
|
||||
bool IsLive) {
|
||||
assert(!Sym.isDefined() && "Sym is already a defined symbol");
|
||||
if (Sym.isAbsolute()) {
|
||||
assert(AbsoluteSymbols.count(&Sym) &&
|
||||
|
@ -1255,15 +1266,15 @@ public:
|
|||
///
|
||||
/// All other symbol attributes are unchanged.
|
||||
void transferDefinedSymbol(Symbol &Sym, Block &DestBlock,
|
||||
JITTargetAddress NewOffset,
|
||||
Optional<JITTargetAddress> ExplicitNewSize) {
|
||||
orc::ExecutorAddrDiff NewOffset,
|
||||
Optional<orc::ExecutorAddrDiff> ExplicitNewSize) {
|
||||
auto &OldSection = Sym.getBlock().getSection();
|
||||
Sym.setBlock(DestBlock);
|
||||
Sym.setOffset(NewOffset);
|
||||
if (ExplicitNewSize)
|
||||
Sym.setSize(*ExplicitNewSize);
|
||||
else {
|
||||
JITTargetAddress RemainingBlockSize = DestBlock.getSize() - NewOffset;
|
||||
auto RemainingBlockSize = DestBlock.getSize() - NewOffset;
|
||||
if (Sym.getSize() > RemainingBlockSize)
|
||||
Sym.setSize(RemainingBlockSize);
|
||||
}
|
||||
|
@ -1407,14 +1418,14 @@ inline MutableArrayRef<char> Block::getMutableContent(LinkGraph &G) {
|
|||
/// Enables easy lookup of blocks by addresses.
|
||||
class BlockAddressMap {
|
||||
public:
|
||||
using AddrToBlockMap = std::map<JITTargetAddress, Block *>;
|
||||
using AddrToBlockMap = std::map<orc::ExecutorAddr, Block *>;
|
||||
using const_iterator = AddrToBlockMap::const_iterator;
|
||||
|
||||
/// A block predicate that always adds all blocks.
|
||||
static bool includeAllBlocks(const Block &B) { return true; }
|
||||
|
||||
/// A block predicate that always includes blocks with non-null addresses.
|
||||
static bool includeNonNull(const Block &B) { return B.getAddress(); }
|
||||
static bool includeNonNull(const Block &B) { return !!B.getAddress(); }
|
||||
|
||||
BlockAddressMap() = default;
|
||||
|
||||
|
@ -1478,7 +1489,7 @@ public:
|
|||
|
||||
/// Returns the block starting at the given address, or nullptr if no such
|
||||
/// block exists.
|
||||
Block *getBlockAt(JITTargetAddress Addr) const {
|
||||
Block *getBlockAt(orc::ExecutorAddr Addr) const {
|
||||
auto I = AddrToBlock.find(Addr);
|
||||
if (I == AddrToBlock.end())
|
||||
return nullptr;
|
||||
|
@ -1487,7 +1498,7 @@ public:
|
|||
|
||||
/// Returns the block covering the given address, or nullptr if no such block
|
||||
/// exists.
|
||||
Block *getBlockCovering(JITTargetAddress Addr) const {
|
||||
Block *getBlockCovering(orc::ExecutorAddr Addr) const {
|
||||
auto I = AddrToBlock.upper_bound(Addr);
|
||||
if (I == AddrToBlock.begin())
|
||||
return nullptr;
|
||||
|
@ -1504,10 +1515,11 @@ private:
|
|||
ExistingBlock.getAddress() + ExistingBlock.getSize();
|
||||
return make_error<JITLinkError>(
|
||||
"Block at " +
|
||||
formatv("{0:x16} -- {1:x16}", NewBlock.getAddress(), NewBlockEnd) +
|
||||
formatv("{0:x16} -- {1:x16}", NewBlock.getAddress().getValue(),
|
||||
NewBlockEnd.getValue()) +
|
||||
" overlaps " +
|
||||
formatv("{0:x16} -- {1:x16}", ExistingBlock.getAddress(),
|
||||
ExistingBlockEnd));
|
||||
formatv("{0:x16} -- {1:x16}", ExistingBlock.getAddress().getValue(),
|
||||
ExistingBlockEnd.getValue()));
|
||||
}
|
||||
|
||||
AddrToBlockMap AddrToBlock;
|
||||
|
@ -1532,7 +1544,7 @@ public:
|
|||
|
||||
/// Returns the list of symbols that start at the given address, or nullptr if
|
||||
/// no such symbols exist.
|
||||
const SymbolVector *getSymbolsAt(JITTargetAddress Addr) const {
|
||||
const SymbolVector *getSymbolsAt(orc::ExecutorAddr Addr) const {
|
||||
auto I = AddrToSymbols.find(Addr);
|
||||
if (I == AddrToSymbols.end())
|
||||
return nullptr;
|
||||
|
@ -1540,7 +1552,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::map<JITTargetAddress, SymbolVector> AddrToSymbols;
|
||||
std::map<orc::ExecutorAddr, SymbolVector> AddrToSymbols;
|
||||
};
|
||||
|
||||
/// A function for mutating LinkGraphs.
|
||||
|
|
|
@ -13,9 +13,10 @@
|
|||
#ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
|
||||
#define LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
|
||||
|
||||
#include "llvm/ADT/FunctionExtras.h"
|
||||
#include "llvm/ExecutionEngine/JITLink/JITLinkDylib.h"
|
||||
#include "llvm/ExecutionEngine/JITLink/MemoryFlags.h"
|
||||
#include "llvm/ExecutionEngine/JITSymbol.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/MSVCErrorWorkarounds.h"
|
||||
|
@ -49,9 +50,9 @@ class Section;
|
|||
/// executor-side implementation code is responsible for freeing the error
|
||||
/// string).
|
||||
struct AllocActionCall {
|
||||
JITTargetAddress FnAddr = 0;
|
||||
JITTargetAddress CtxAddr = 0;
|
||||
JITTargetAddress CtxSize = 0;
|
||||
orc::ExecutorAddr FnAddr;
|
||||
orc::ExecutorAddr CtxAddr;
|
||||
orc::ExecutorAddrDiff CtxSize;
|
||||
};
|
||||
|
||||
/// A pair of AllocActionCalls, one to be run at finalization time, one to be
|
||||
|
@ -93,47 +94,48 @@ public:
|
|||
class FinalizedAlloc {
|
||||
friend class JITLinkMemoryManager;
|
||||
|
||||
public:
|
||||
static constexpr JITTargetAddress InvalidAddr = ~JITTargetAddress(0);
|
||||
static constexpr auto InvalidAddr = ~uint64_t(0);
|
||||
|
||||
public:
|
||||
FinalizedAlloc() = default;
|
||||
explicit FinalizedAlloc(JITTargetAddress A) : A(A) {
|
||||
assert(A != 0 && "Explicitly creating an invalid allocation?");
|
||||
explicit FinalizedAlloc(orc::ExecutorAddr A) : A(A) {
|
||||
assert(A && "Explicitly creating an invalid allocation?");
|
||||
}
|
||||
FinalizedAlloc(const FinalizedAlloc &) = delete;
|
||||
FinalizedAlloc(FinalizedAlloc &&Other) : A(Other.A) {
|
||||
Other.A = InvalidAddr;
|
||||
Other.A.setValue(InvalidAddr);
|
||||
}
|
||||
FinalizedAlloc &operator=(const FinalizedAlloc &) = delete;
|
||||
FinalizedAlloc &operator=(FinalizedAlloc &&Other) {
|
||||
assert(A == InvalidAddr &&
|
||||
assert(A.getValue() == InvalidAddr &&
|
||||
"Cannot overwrite active finalized allocation");
|
||||
std::swap(A, Other.A);
|
||||
return *this;
|
||||
}
|
||||
~FinalizedAlloc() {
|
||||
assert(A == InvalidAddr && "Finalized allocation was not deallocated");
|
||||
assert(A.getValue() == InvalidAddr &&
|
||||
"Finalized allocation was not deallocated");
|
||||
}
|
||||
|
||||
/// FinalizedAllocs convert to false for default-constructed, and
|
||||
/// true otherwise. Default-constructed allocs need not be deallocated.
|
||||
explicit operator bool() const { return A != InvalidAddr; }
|
||||
explicit operator bool() const { return A.getValue() != InvalidAddr; }
|
||||
|
||||
/// Returns the address associated with this finalized allocation.
|
||||
/// The allocation is unmodified.
|
||||
JITTargetAddress getAddress() const { return A; }
|
||||
orc::ExecutorAddr getAddress() const { return A; }
|
||||
|
||||
/// Returns the address associated with this finalized allocation and
|
||||
/// resets this object to the default state.
|
||||
/// This should only be used by allocators when deallocating memory.
|
||||
JITTargetAddress release() {
|
||||
JITTargetAddress Tmp = A;
|
||||
A = InvalidAddr;
|
||||
orc::ExecutorAddr release() {
|
||||
orc::ExecutorAddr Tmp = A;
|
||||
A.setValue(InvalidAddr);
|
||||
return Tmp;
|
||||
}
|
||||
|
||||
private:
|
||||
JITTargetAddress A = InvalidAddr;
|
||||
orc::ExecutorAddr A{InvalidAddr};
|
||||
};
|
||||
|
||||
/// Represents an allocation which has not been finalized yet.
|
||||
|
@ -263,7 +265,7 @@ public:
|
|||
Align Alignment;
|
||||
size_t ContentSize;
|
||||
uint64_t ZeroFillSize;
|
||||
JITTargetAddress Addr;
|
||||
orc::ExecutorAddr Addr;
|
||||
char *WorkingMem = nullptr;
|
||||
|
||||
private:
|
||||
|
@ -341,7 +343,7 @@ public:
|
|||
|
||||
/// Describes the segment working memory and executor address.
|
||||
struct SegmentInfo {
|
||||
JITTargetAddress Addr = 0;
|
||||
orc::ExecutorAddr Addr;
|
||||
MutableArrayRef<char> WorkingMem;
|
||||
};
|
||||
|
||||
|
|
|
@ -368,18 +368,18 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
|
|||
|
||||
char *BlockWorkingMem = B.getAlreadyMutableContent().data();
|
||||
char *FixupPtr = BlockWorkingMem + E.getOffset();
|
||||
JITTargetAddress FixupAddress = B.getAddress() + E.getOffset();
|
||||
auto FixupAddress = B.getAddress() + E.getOffset();
|
||||
|
||||
switch (E.getKind()) {
|
||||
|
||||
case Pointer64: {
|
||||
uint64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
uint64_t Value = E.getTarget().getAddress().getValue() + E.getAddend();
|
||||
*(ulittle64_t *)FixupPtr = Value;
|
||||
break;
|
||||
}
|
||||
|
||||
case Pointer32: {
|
||||
uint64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
uint64_t Value = E.getTarget().getAddress().getValue() + E.getAddend();
|
||||
if (LLVM_LIKELY(isInRangeForImmU32(Value)))
|
||||
*(ulittle32_t *)FixupPtr = Value;
|
||||
else
|
||||
|
@ -387,7 +387,7 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
|
|||
break;
|
||||
}
|
||||
case Pointer32Signed: {
|
||||
int64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
int64_t Value = E.getTarget().getAddress().getValue() + E.getAddend();
|
||||
if (LLVM_LIKELY(isInRangeForImmS32(Value)))
|
||||
*(little32_t *)FixupPtr = Value;
|
||||
else
|
||||
|
@ -483,8 +483,8 @@ extern const char PointerJumpStubContent[6];
|
|||
inline Symbol &createAnonymousPointer(LinkGraph &G, Section &PointerSection,
|
||||
Symbol *InitialTarget = nullptr,
|
||||
uint64_t InitialAddend = 0) {
|
||||
auto &B =
|
||||
G.createContentBlock(PointerSection, NullPointerContent, ~7ULL, 8, 0);
|
||||
auto &B = G.createContentBlock(PointerSection, NullPointerContent,
|
||||
orc::ExecutorAddr(~uint64_t(7)), 8, 0);
|
||||
if (InitialTarget)
|
||||
B.addEdge(Pointer64, 0, *InitialTarget, InitialAddend);
|
||||
return G.addAnonymousSymbol(B, 0, 8, false, false);
|
||||
|
@ -498,8 +498,8 @@ inline Symbol &createAnonymousPointer(LinkGraph &G, Section &PointerSection,
|
|||
/// address: highest allowable: (~5U)
|
||||
inline Block &createPointerJumpStubBlock(LinkGraph &G, Section &StubSection,
|
||||
Symbol &PointerSymbol) {
|
||||
auto &B =
|
||||
G.createContentBlock(StubSection, PointerJumpStubContent, ~5ULL, 1, 0);
|
||||
auto &B = G.createContentBlock(StubSection, PointerJumpStubContent,
|
||||
orc::ExecutorAddr(~uint64_t(5)), 1, 0);
|
||||
B.addEdge(Delta32, 2, PointerSymbol, -4);
|
||||
return B;
|
||||
}
|
||||
|
@ -552,8 +552,7 @@ public:
|
|||
"Fell through switch, but no new kind to set");
|
||||
DEBUG_WITH_TYPE("jitlink", {
|
||||
dbgs() << " Fixing " << G.getEdgeKindName(E.getKind()) << " edge at "
|
||||
<< formatv("{0:x}", B->getFixupAddress(E)) << " ("
|
||||
<< formatv("{0:x}", B->getAddress()) << " + "
|
||||
<< B->getFixupAddress(E) << " (" << B->getAddress() << " + "
|
||||
<< formatv("{0:x}", E.getOffset()) << ")\n";
|
||||
});
|
||||
E.setKind(KindToSet);
|
||||
|
@ -586,8 +585,7 @@ public:
|
|||
if (E.getKind() == x86_64::BranchPCRel32 && !E.getTarget().isDefined()) {
|
||||
DEBUG_WITH_TYPE("jitlink", {
|
||||
dbgs() << " Fixing " << G.getEdgeKindName(E.getKind()) << " edge at "
|
||||
<< formatv("{0:x}", B->getFixupAddress(E)) << " ("
|
||||
<< formatv("{0:x}", B->getAddress()) << " + "
|
||||
<< B->getFixupAddress(E) << " (" << B->getAddress() << " + "
|
||||
<< formatv("{0:x}", E.getOffset()) << ")\n";
|
||||
});
|
||||
// Set the edge kind to Branch32ToPtrJumpStubBypassable to enable it to
|
||||
|
|
|
@ -236,7 +236,7 @@ private:
|
|||
DenseMap<JITDylib *, ELFNixJITDylibInitializers> InitSeqs;
|
||||
std::vector<ELFPerObjectSectionsToRegister> BootstrapPOSRs;
|
||||
|
||||
DenseMap<JITTargetAddress, JITDylib *> HandleAddrToJITDylib;
|
||||
DenseMap<ExecutorAddr, JITDylib *> HandleAddrToJITDylib;
|
||||
DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
|
||||
};
|
||||
|
||||
|
|
|
@ -39,9 +39,9 @@ public:
|
|||
: ES(ES), RegisterEHFrameWrapperFnAddr(RegisterEHFrameWrapperFnAddr),
|
||||
DeregisterEHFrameWrapperFnAddr(DeregisterEHFRameWrapperFnAddr) {}
|
||||
|
||||
Error registerEHFrames(JITTargetAddress EHFrameSectionAddr,
|
||||
Error registerEHFrames(ExecutorAddr EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) override;
|
||||
Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr,
|
||||
Error deregisterEHFrames(ExecutorAddr EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
ExecutorAddr A;
|
||||
if (!SPSArgList<SPSExecutorAddr>::deserialize(IB, A))
|
||||
return false;
|
||||
FA = jitlink::JITLinkMemoryManager::FinalizedAlloc(A.getValue());
|
||||
FA = jitlink::JITLinkMemoryManager::FinalizedAlloc(A);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -239,7 +239,7 @@ private:
|
|||
std::mutex PlatformMutex;
|
||||
DenseMap<JITDylib *, MachOJITDylibInitializers> InitSeqs;
|
||||
|
||||
DenseMap<JITTargetAddress, JITDylib *> HeaderAddrToJITDylib;
|
||||
DenseMap<ExecutorAddr, JITDylib *> HeaderAddrToJITDylib;
|
||||
DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
|
||||
};
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ public:
|
|||
private:
|
||||
|
||||
struct EHFrameRange {
|
||||
JITTargetAddress Addr = 0;
|
||||
orc::ExecutorAddr Addr;
|
||||
size_t Size;
|
||||
};
|
||||
|
||||
|
|
|
@ -13,7 +13,10 @@
|
|||
#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
|
||||
|
||||
#include "llvm/ADT/DenseMapInfo.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
@ -29,7 +32,7 @@ public:
|
|||
ExecutorAddr() = default;
|
||||
|
||||
/// Create an ExecutorAddr from the given value.
|
||||
explicit ExecutorAddr(uint64_t Addr) : Addr(Addr) {}
|
||||
explicit constexpr ExecutorAddr(uint64_t Addr) : Addr(Addr) {}
|
||||
|
||||
/// Create an ExecutorAddr from the given pointer.
|
||||
/// Warning: This should only be used when JITing in-process.
|
||||
|
@ -88,12 +91,12 @@ public:
|
|||
ExecutorAddr operator++(int) { return ExecutorAddr(Addr++); }
|
||||
ExecutorAddr operator--(int) { return ExecutorAddr(Addr--); }
|
||||
|
||||
ExecutorAddr &operator+=(const ExecutorAddrDiff Delta) {
|
||||
ExecutorAddr &operator+=(const ExecutorAddrDiff &Delta) {
|
||||
Addr += Delta;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ExecutorAddr &operator-=(const ExecutorAddrDiff Delta) {
|
||||
ExecutorAddr &operator-=(const ExecutorAddrDiff &Delta) {
|
||||
Addr -= Delta;
|
||||
return *this;
|
||||
}
|
||||
|
@ -120,6 +123,18 @@ inline ExecutorAddr operator+(const ExecutorAddrDiff &LHS,
|
|||
return ExecutorAddr(LHS + RHS.getValue());
|
||||
}
|
||||
|
||||
/// Subtracting an offset from an address yields an address.
|
||||
inline ExecutorAddr operator-(const ExecutorAddr &LHS,
|
||||
const ExecutorAddrDiff &RHS) {
|
||||
return ExecutorAddr(LHS.getValue() - RHS);
|
||||
}
|
||||
|
||||
/// Taking the modulus of an address and a diff yields a diff.
|
||||
inline ExecutorAddrDiff operator%(const ExecutorAddr &LHS,
|
||||
const ExecutorAddrDiff &RHS) {
|
||||
return ExecutorAddrDiff(LHS.getValue() % RHS);
|
||||
}
|
||||
|
||||
/// Represents an address range in the exceutor process.
|
||||
struct ExecutorAddrRange {
|
||||
ExecutorAddrRange() = default;
|
||||
|
@ -148,6 +163,10 @@ struct ExecutorAddrRange {
|
|||
ExecutorAddr End;
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS, const ExecutorAddr &A) {
|
||||
return OS << formatv("{0:x}", A.getValue());
|
||||
}
|
||||
|
||||
namespace shared {
|
||||
|
||||
class SPSExecutorAddr {};
|
||||
|
@ -198,6 +217,26 @@ using SPSExecutorAddrRangeSequence = SPSSequence<SPSExecutorAddrRange>;
|
|||
|
||||
} // End namespace shared.
|
||||
} // End namespace orc.
|
||||
|
||||
// Provide DenseMapInfo for ExecutorAddrs.
|
||||
template <> struct DenseMapInfo<orc::ExecutorAddr> {
|
||||
static inline orc::ExecutorAddr getEmptyKey() {
|
||||
return orc::ExecutorAddr(DenseMapInfo<uint64_t>::getEmptyKey());
|
||||
}
|
||||
static inline orc::ExecutorAddr getTombstoneKey() {
|
||||
return orc::ExecutorAddr(DenseMapInfo<uint64_t>::getTombstoneKey());
|
||||
}
|
||||
|
||||
static unsigned getHashValue(const orc::ExecutorAddr &Addr) {
|
||||
return DenseMapInfo<uint64_t>::getHashValue(Addr.getValue());
|
||||
}
|
||||
|
||||
static bool isEqual(const orc::ExecutorAddr &LHS,
|
||||
const orc::ExecutorAddr &RHS) {
|
||||
return DenseMapInfo<uint64_t>::isEqual(LHS.getValue(), RHS.getValue());
|
||||
}
|
||||
};
|
||||
|
||||
} // End namespace llvm.
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_EXECUTORADDRESS_H
|
||||
|
|
|
@ -52,13 +52,13 @@ public:
|
|||
auto &SR = getSectionRange(*D.Sec);
|
||||
if (D.IsStart) {
|
||||
if (SR.empty())
|
||||
G.makeAbsolute(*Sym, 0);
|
||||
G.makeAbsolute(*Sym, orc::ExecutorAddr());
|
||||
else
|
||||
G.makeDefined(*Sym, *SR.getFirstBlock(), 0, 0, Linkage::Strong,
|
||||
Scope::Local, false);
|
||||
} else {
|
||||
if (SR.empty())
|
||||
G.makeAbsolute(*Sym, 0);
|
||||
G.makeAbsolute(*Sym, orc::ExecutorAddr());
|
||||
else
|
||||
G.makeDefined(*Sym, *SR.getLastBlock(),
|
||||
SR.getLastBlock()->getSize(), 0, Linkage::Strong,
|
||||
|
|
|
@ -65,10 +65,7 @@ Error EHFrameSplitter::operator()(LinkGraph &G) {
|
|||
|
||||
Error EHFrameSplitter::processBlock(LinkGraph &G, Block &B,
|
||||
LinkGraph::SplitBlockCache &Cache) {
|
||||
LLVM_DEBUG({
|
||||
dbgs() << " Processing block at " << formatv("{0:x16}", B.getAddress())
|
||||
<< "\n";
|
||||
});
|
||||
LLVM_DEBUG(dbgs() << " Processing block at " << B.getAddress() << "\n");
|
||||
|
||||
// eh-frame should not contain zero-fill blocks.
|
||||
if (B.isZeroFill())
|
||||
|
@ -400,7 +397,7 @@ Error EHFrameEdgeFixer::processFDE(ParseContext &PC, Block &B,
|
|||
BlockEdgeMap &BlockEdges) {
|
||||
LLVM_DEBUG(dbgs() << " Record is FDE\n");
|
||||
|
||||
JITTargetAddress RecordAddress = B.getAddress() + RecordOffset;
|
||||
orc::ExecutorAddr RecordAddress = B.getAddress() + RecordOffset;
|
||||
|
||||
auto RecordContent = B.getContent().slice(RecordOffset, RecordLength);
|
||||
BinaryStreamReader RecordReader(
|
||||
|
@ -418,8 +415,8 @@ Error EHFrameEdgeFixer::processFDE(ParseContext &PC, Block &B,
|
|||
{
|
||||
// Process the CIE pointer field.
|
||||
auto CIEEdgeItr = BlockEdges.find(RecordOffset + CIEDeltaFieldOffset);
|
||||
JITTargetAddress CIEAddress =
|
||||
RecordAddress + CIEDeltaFieldOffset - CIEDelta;
|
||||
orc::ExecutorAddr CIEAddress =
|
||||
RecordAddress + orc::ExecutorAddrDiff(CIEDeltaFieldOffset - CIEDelta);
|
||||
if (CIEEdgeItr == BlockEdges.end()) {
|
||||
|
||||
LLVM_DEBUG({
|
||||
|
@ -456,7 +453,7 @@ Error EHFrameEdgeFixer::processFDE(ParseContext &PC, Block &B,
|
|||
{
|
||||
// Process the PC-Begin field.
|
||||
Block *PCBeginBlock = nullptr;
|
||||
JITTargetAddress PCBeginFieldOffset = RecordReader.getOffset();
|
||||
orc::ExecutorAddrDiff PCBeginFieldOffset = RecordReader.getOffset();
|
||||
auto PCEdgeItr = BlockEdges.find(RecordOffset + PCBeginFieldOffset);
|
||||
if (PCEdgeItr == BlockEdges.end()) {
|
||||
auto PCBeginPtrInfo =
|
||||
|
@ -464,12 +461,12 @@ Error EHFrameEdgeFixer::processFDE(ParseContext &PC, Block &B,
|
|||
RecordAddress + PCBeginFieldOffset, RecordReader);
|
||||
if (!PCBeginPtrInfo)
|
||||
return PCBeginPtrInfo.takeError();
|
||||
JITTargetAddress PCBegin = PCBeginPtrInfo->first;
|
||||
orc::ExecutorAddr PCBegin = PCBeginPtrInfo->first;
|
||||
Edge::Kind PCBeginEdgeKind = PCBeginPtrInfo->second;
|
||||
LLVM_DEBUG({
|
||||
dbgs() << " Adding edge at "
|
||||
<< formatv("{0:x16}", RecordAddress + PCBeginFieldOffset)
|
||||
<< " to PC at " << formatv("{0:x16}", PCBegin) << "\n";
|
||||
<< (RecordAddress + PCBeginFieldOffset) << " to PC at "
|
||||
<< formatv("{0:x16}", PCBegin) << "\n";
|
||||
});
|
||||
auto PCBeginSym = getOrCreateSymbol(PC, PCBegin);
|
||||
if (!PCBeginSym)
|
||||
|
@ -522,7 +519,7 @@ Error EHFrameEdgeFixer::processFDE(ParseContext &PC, Block &B,
|
|||
if (auto Err = RecordReader.readULEB128(AugmentationDataSize))
|
||||
return Err;
|
||||
|
||||
JITTargetAddress LSDAFieldOffset = RecordReader.getOffset();
|
||||
orc::ExecutorAddrDiff LSDAFieldOffset = RecordReader.getOffset();
|
||||
auto LSDAEdgeItr = BlockEdges.find(RecordOffset + LSDAFieldOffset);
|
||||
if (LSDAEdgeItr == BlockEdges.end()) {
|
||||
auto LSDAPointerInfo =
|
||||
|
@ -530,7 +527,7 @@ Error EHFrameEdgeFixer::processFDE(ParseContext &PC, Block &B,
|
|||
RecordAddress + LSDAFieldOffset, RecordReader);
|
||||
if (!LSDAPointerInfo)
|
||||
return LSDAPointerInfo.takeError();
|
||||
JITTargetAddress LSDA = LSDAPointerInfo->first;
|
||||
orc::ExecutorAddr LSDA = LSDAPointerInfo->first;
|
||||
Edge::Kind LSDAEdgeKind = LSDAPointerInfo->second;
|
||||
auto LSDASym = getOrCreateSymbol(PC, LSDA);
|
||||
if (!LSDASym)
|
||||
|
@ -645,12 +642,10 @@ unsigned EHFrameEdgeFixer::getPointerEncodingDataSize(uint8_t PointerEncoding) {
|
|||
}
|
||||
}
|
||||
|
||||
Expected<std::pair<JITTargetAddress, Edge::Kind>>
|
||||
Expected<std::pair<orc::ExecutorAddr, Edge::Kind>>
|
||||
EHFrameEdgeFixer::readEncodedPointer(uint8_t PointerEncoding,
|
||||
JITTargetAddress PointerFieldAddress,
|
||||
orc::ExecutorAddr PointerFieldAddress,
|
||||
BinaryStreamReader &RecordReader) {
|
||||
static_assert(sizeof(JITTargetAddress) == sizeof(uint64_t),
|
||||
"Result must be able to hold a uint64_t");
|
||||
assert(isSupportedPointerEncoding(PointerEncoding) &&
|
||||
"Unsupported pointer encoding");
|
||||
|
||||
|
@ -663,7 +658,7 @@ EHFrameEdgeFixer::readEncodedPointer(uint8_t PointerEncoding,
|
|||
if (EffectiveType == DW_EH_PE_absptr)
|
||||
EffectiveType = (PointerSize == 8) ? DW_EH_PE_udata8 : DW_EH_PE_udata4;
|
||||
|
||||
JITTargetAddress Addr;
|
||||
orc::ExecutorAddr Addr;
|
||||
Edge::Kind PointerEdgeKind = Edge::Invalid;
|
||||
switch (EffectiveType) {
|
||||
case DW_EH_PE_udata4: {
|
||||
|
@ -709,7 +704,7 @@ EHFrameEdgeFixer::readEncodedPointer(uint8_t PointerEncoding,
|
|||
}
|
||||
|
||||
Expected<Symbol &> EHFrameEdgeFixer::getOrCreateSymbol(ParseContext &PC,
|
||||
JITTargetAddress Addr) {
|
||||
orc::ExecutorAddr Addr) {
|
||||
Symbol *CanonicalSym = nullptr;
|
||||
|
||||
auto UpdateCanonicalSym = [&](Symbol *Sym) {
|
||||
|
@ -753,8 +748,9 @@ Error EHFrameNullTerminator::operator()(LinkGraph &G) {
|
|||
<< EHFrameSectionName << "\n";
|
||||
});
|
||||
|
||||
auto &NullTerminatorBlock = G.createContentBlock(
|
||||
*EHFrame, NullTerminatorBlockContent, 0xfffffffffffffffc, 1, 0);
|
||||
auto &NullTerminatorBlock =
|
||||
G.createContentBlock(*EHFrame, NullTerminatorBlockContent,
|
||||
orc::ExecutorAddr(~uint64_t(4)), 1, 0);
|
||||
G.addAnonymousSymbol(NullTerminatorBlock, 0, 4, false, true);
|
||||
return Error::success();
|
||||
}
|
||||
|
@ -762,17 +758,15 @@ Error EHFrameNullTerminator::operator()(LinkGraph &G) {
|
|||
EHFrameRegistrar::~EHFrameRegistrar() {}
|
||||
|
||||
Error InProcessEHFrameRegistrar::registerEHFrames(
|
||||
JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
|
||||
return orc::registerEHFrameSection(
|
||||
jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
|
||||
EHFrameSectionSize);
|
||||
orc::ExecutorAddr EHFrameSectionAddr, size_t EHFrameSectionSize) {
|
||||
return orc::registerEHFrameSection(EHFrameSectionAddr.toPtr<void *>(),
|
||||
EHFrameSectionSize);
|
||||
}
|
||||
|
||||
Error InProcessEHFrameRegistrar::deregisterEHFrames(
|
||||
JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
|
||||
return orc::deregisterEHFrameSection(
|
||||
jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
|
||||
EHFrameSectionSize);
|
||||
orc::ExecutorAddr EHFrameSectionAddr, size_t EHFrameSectionSize) {
|
||||
return orc::deregisterEHFrameSection(EHFrameSectionAddr.toPtr<void *>(),
|
||||
EHFrameSectionSize);
|
||||
}
|
||||
|
||||
LinkGraphPassFunction
|
||||
|
@ -789,14 +783,14 @@ createEHFrameRecorderPass(const Triple &TT,
|
|||
StoreFrameRange = std::move(StoreRangeAddress)](LinkGraph &G) -> Error {
|
||||
// Search for a non-empty eh-frame and record the address of the first
|
||||
// symbol in it.
|
||||
JITTargetAddress Addr = 0;
|
||||
orc::ExecutorAddr Addr;
|
||||
size_t Size = 0;
|
||||
if (auto *S = G.findSectionByName(EHFrameSectionName)) {
|
||||
auto R = SectionRange(*S);
|
||||
Addr = R.getStart();
|
||||
Size = R.getSize();
|
||||
}
|
||||
if (Addr == 0 && Size != 0)
|
||||
if (!Addr && Size != 0)
|
||||
return make_error<JITLinkError>(
|
||||
StringRef(EHFrameSectionName) +
|
||||
" section can not have zero address with non-zero size");
|
||||
|
|
|
@ -71,12 +71,12 @@ private:
|
|||
};
|
||||
|
||||
using BlockEdgeMap = DenseMap<Edge::OffsetT, EdgeTarget>;
|
||||
using CIEInfosMap = DenseMap<JITTargetAddress, CIEInformation>;
|
||||
using CIEInfosMap = DenseMap<orc::ExecutorAddr, CIEInformation>;
|
||||
|
||||
struct ParseContext {
|
||||
ParseContext(LinkGraph &G) : G(G) {}
|
||||
|
||||
Expected<CIEInformation *> findCIEInfo(JITTargetAddress Address) {
|
||||
Expected<CIEInformation *> findCIEInfo(orc::ExecutorAddr Address) {
|
||||
auto I = CIEInfos.find(Address);
|
||||
if (I == CIEInfos.end())
|
||||
return make_error<JITLinkError>("No CIE found at address " +
|
||||
|
@ -102,12 +102,13 @@ private:
|
|||
|
||||
static bool isSupportedPointerEncoding(uint8_t PointerEncoding);
|
||||
unsigned getPointerEncodingDataSize(uint8_t PointerEncoding);
|
||||
Expected<std::pair<JITTargetAddress, Edge::Kind>>
|
||||
Expected<std::pair<orc::ExecutorAddr, Edge::Kind>>
|
||||
readEncodedPointer(uint8_t PointerEncoding,
|
||||
JITTargetAddress PointerFieldAddress,
|
||||
orc::ExecutorAddr PointerFieldAddress,
|
||||
BinaryStreamReader &RecordReader);
|
||||
|
||||
Expected<Symbol &> getOrCreateSymbol(ParseContext &PC, JITTargetAddress Addr);
|
||||
Expected<Symbol &> getOrCreateSymbol(ParseContext &PC,
|
||||
orc::ExecutorAddr Addr);
|
||||
|
||||
StringRef EHFrameSectionName;
|
||||
unsigned PointerSize;
|
||||
|
|
|
@ -322,10 +322,12 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySections() {
|
|||
if (!Data)
|
||||
return Data.takeError();
|
||||
|
||||
G->createContentBlock(GraphSec, *Data, Sec.sh_addr, Sec.sh_addralign, 0);
|
||||
G->createContentBlock(GraphSec, *Data, orc::ExecutorAddr(Sec.sh_addr),
|
||||
Sec.sh_addralign, 0);
|
||||
} else
|
||||
G->createZeroFillBlock(GraphSec, Sec.sh_size, Sec.sh_addr,
|
||||
Sec.sh_addralign, 0);
|
||||
G->createZeroFillBlock(GraphSec, Sec.sh_size,
|
||||
orc::ExecutorAddr(Sec.sh_addr), Sec.sh_addralign,
|
||||
0);
|
||||
|
||||
setGraphSection(SecIndex, GraphSec);
|
||||
}
|
||||
|
@ -393,9 +395,9 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
|
|||
|
||||
// Handle common symbols specially.
|
||||
if (Sym.isCommon()) {
|
||||
Symbol &GSym =
|
||||
G->addCommonSymbol(*Name, Scope::Default, getCommonSection(), 0,
|
||||
Sym.st_size, Sym.getValue(), false);
|
||||
Symbol &GSym = G->addCommonSymbol(*Name, Scope::Default,
|
||||
getCommonSection(), orc::ExecutorAddr(),
|
||||
Sym.st_size, Sym.getValue(), false);
|
||||
setGraphSymbol(SymIndex, GSym);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -41,10 +41,11 @@ private:
|
|||
|
||||
char *BlockWorkingMem = B.getAlreadyMutableContent().data();
|
||||
char *FixupPtr = BlockWorkingMem + E.getOffset();
|
||||
JITTargetAddress FixupAddress = B.getAddress() + E.getOffset();
|
||||
auto FixupAddress = B.getAddress() + E.getOffset();
|
||||
switch (E.getKind()) {
|
||||
case aarch64::R_AARCH64_CALL26: {
|
||||
assert((FixupAddress & 0x3) == 0 && "Call-inst is not 32-bit aligned");
|
||||
assert((FixupAddress.getValue() & 0x3) == 0 &&
|
||||
"Call-inst is not 32-bit aligned");
|
||||
int64_t Value = E.getTarget().getAddress() - FixupAddress + E.getAddend();
|
||||
|
||||
if (static_cast<uint64_t>(Value) & 0x3)
|
||||
|
@ -124,7 +125,8 @@ private:
|
|||
|
||||
int64_t Addend = Rel.r_addend;
|
||||
Block *BlockToFix = *(GraphSection.blocks().begin());
|
||||
JITTargetAddress FixupAddress = FixupSect.sh_addr + Rel.r_offset;
|
||||
orc::ExecutorAddr FixupAddress =
|
||||
orc::ExecutorAddr(FixupSect.sh_addr) + Rel.r_offset;
|
||||
Edge::OffsetT Offset = FixupAddress - BlockToFix->getAddress();
|
||||
Edge GE(*Kind, Offset, *GraphSymbol, Addend);
|
||||
LLVM_DEBUG({
|
||||
|
|
|
@ -44,15 +44,16 @@ public:
|
|||
bool isGOTEdgeToFix(Edge &E) const { return E.getKind() == R_RISCV_GOT_HI20; }
|
||||
|
||||
Symbol &createGOTEntry(Symbol &Target) {
|
||||
Block &GOTBlock = G.createContentBlock(
|
||||
getGOTSection(), getGOTEntryBlockContent(), 0, G.getPointerSize(), 0);
|
||||
Block &GOTBlock =
|
||||
G.createContentBlock(getGOTSection(), getGOTEntryBlockContent(),
|
||||
orc::ExecutorAddr(), G.getPointerSize(), 0);
|
||||
GOTBlock.addEdge(isRV64() ? R_RISCV_64 : R_RISCV_32, 0, Target, 0);
|
||||
return G.addAnonymousSymbol(GOTBlock, 0, G.getPointerSize(), false, false);
|
||||
}
|
||||
|
||||
Symbol &createPLTStub(Symbol &Target) {
|
||||
Block &StubContentBlock =
|
||||
G.createContentBlock(getStubsSection(), getStubBlockContent(), 0, 4, 0);
|
||||
Block &StubContentBlock = G.createContentBlock(
|
||||
getStubsSection(), getStubBlockContent(), orc::ExecutorAddr(), 4, 0);
|
||||
auto &GOTEntrySymbol = getGOTEntry(Target);
|
||||
StubContentBlock.addEdge(R_RISCV_CALL, 0, GOTEntrySymbol, 0);
|
||||
return G.addAnonymousSymbol(StubContentBlock, 0, StubEntrySize, true,
|
||||
|
@ -134,13 +135,13 @@ static Expected<const Edge &> getRISCVPCRelHi20(const Edge &E) {
|
|||
|
||||
const Symbol &Sym = E.getTarget();
|
||||
const Block &B = Sym.getBlock();
|
||||
JITTargetAddress Offset = Sym.getOffset();
|
||||
orc::ExecutorAddrDiff Offset = Sym.getOffset();
|
||||
|
||||
struct Comp {
|
||||
bool operator()(const Edge &Lhs, JITTargetAddress Offset) {
|
||||
bool operator()(const Edge &Lhs, orc::ExecutorAddrDiff Offset) {
|
||||
return Lhs.getOffset() < Offset;
|
||||
}
|
||||
bool operator()(JITTargetAddress Offset, const Edge &Rhs) {
|
||||
bool operator()(orc::ExecutorAddrDiff Offset, const Edge &Rhs) {
|
||||
return Offset < Rhs.getOffset();
|
||||
}
|
||||
};
|
||||
|
@ -176,27 +177,27 @@ private:
|
|||
|
||||
char *BlockWorkingMem = B.getAlreadyMutableContent().data();
|
||||
char *FixupPtr = BlockWorkingMem + E.getOffset();
|
||||
JITTargetAddress FixupAddress = B.getAddress() + E.getOffset();
|
||||
orc::ExecutorAddr FixupAddress = B.getAddress() + E.getOffset();
|
||||
switch (E.getKind()) {
|
||||
case R_RISCV_32: {
|
||||
int64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
int64_t Value = (E.getTarget().getAddress() + E.getAddend()).getValue();
|
||||
*(little32_t *)FixupPtr = static_cast<uint32_t>(Value);
|
||||
break;
|
||||
}
|
||||
case R_RISCV_64: {
|
||||
int64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
int64_t Value = (E.getTarget().getAddress() + E.getAddend()).getValue();
|
||||
*(little64_t *)FixupPtr = static_cast<uint64_t>(Value);
|
||||
break;
|
||||
}
|
||||
case R_RISCV_HI20: {
|
||||
int64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
int64_t Value = (E.getTarget().getAddress() + E.getAddend()).getValue();
|
||||
int32_t Hi = (Value + 0x800) & 0xFFFFF000;
|
||||
uint32_t RawInstr = *(little32_t *)FixupPtr;
|
||||
*(little32_t *)FixupPtr = (RawInstr & 0xFFF) | static_cast<uint32_t>(Hi);
|
||||
break;
|
||||
}
|
||||
case R_RISCV_LO12_I: {
|
||||
int64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
int64_t Value = (E.getTarget().getAddress() + E.getAddend()).getValue();
|
||||
int32_t Lo = Value & 0xFFF;
|
||||
uint32_t RawInstr = *(little32_t *)FixupPtr;
|
||||
*(little32_t *)FixupPtr =
|
||||
|
@ -322,7 +323,7 @@ private:
|
|||
|
||||
int64_t Addend = Rel.r_addend;
|
||||
Block *BlockToFix = *(GraphSection.blocks().begin());
|
||||
JITTargetAddress FixupAddress = FixupSect.sh_addr + Rel.r_offset;
|
||||
auto FixupAddress = orc::ExecutorAddr(FixupSect.sh_addr) + Rel.r_offset;
|
||||
Edge::OffsetT Offset = FixupAddress - BlockToFix->getAddress();
|
||||
Edge GE(*Kind, Offset, *GraphSymbol, Addend);
|
||||
LLVM_DEBUG({
|
||||
|
|
|
@ -59,8 +59,8 @@ public:
|
|||
// the TLS Info entry's key value will be written by the fixTLVSectionByName
|
||||
// pass, so create mutable content.
|
||||
auto &TLSInfoEntry = G.createMutableContentBlock(
|
||||
getTLSInfoSection(G), G.allocateContent(getTLSInfoEntryContent()), 0, 8,
|
||||
0);
|
||||
getTLSInfoSection(G), G.allocateContent(getTLSInfoEntryContent()),
|
||||
orc::ExecutorAddr(), 8, 0);
|
||||
TLSInfoEntry.addEdge(x86_64::Pointer64, 8, Target, 0);
|
||||
return G.addAnonymousSymbol(TLSInfoEntry, 0, 16, false, false);
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ private:
|
|||
}
|
||||
|
||||
Block *BlockToFix = *(GraphSection.blocks().begin());
|
||||
JITTargetAddress FixupAddress = FixupSection.sh_addr + Rel.r_offset;
|
||||
auto FixupAddress = orc::ExecutorAddr(FixupSection.sh_addr) + Rel.r_offset;
|
||||
Edge::OffsetT Offset = FixupAddress - BlockToFix->getAddress();
|
||||
Edge GE(Kind, Offset, *GraphSymbol, Addend);
|
||||
LLVM_DEBUG({
|
||||
|
@ -322,8 +322,9 @@ private:
|
|||
// If there's no defined symbol then create one.
|
||||
SectionRange SR(*GOTSection);
|
||||
if (SR.empty())
|
||||
GOTSymbol = &G.addAbsoluteSymbol(ELFGOTSymbolName, 0, 0,
|
||||
Linkage::Strong, Scope::Local, true);
|
||||
GOTSymbol =
|
||||
&G.addAbsoluteSymbol(ELFGOTSymbolName, orc::ExecutorAddr(), 0,
|
||||
Linkage::Strong, Scope::Local, true);
|
||||
else
|
||||
GOTSymbol =
|
||||
&G.addDefinedSymbol(*SR.getFirstBlock(), 0, ELFGOTSymbolName, 0,
|
||||
|
|
|
@ -90,8 +90,8 @@ const char *getScopeName(Scope S) {
|
|||
}
|
||||
|
||||
raw_ostream &operator<<(raw_ostream &OS, const Block &B) {
|
||||
return OS << formatv("{0:x16}", B.getAddress()) << " -- "
|
||||
<< formatv("{0:x8}", B.getAddress() + B.getSize()) << ": "
|
||||
return OS << B.getAddress() << " -- " << (B.getAddress() + B.getSize())
|
||||
<< ": "
|
||||
<< "size = " << formatv("{0:x8}", B.getSize()) << ", "
|
||||
<< (B.isZeroFill() ? "zero-fill" : "content")
|
||||
<< ", align = " << B.getAlignment()
|
||||
|
@ -100,9 +100,8 @@ raw_ostream &operator<<(raw_ostream &OS, const Block &B) {
|
|||
}
|
||||
|
||||
raw_ostream &operator<<(raw_ostream &OS, const Symbol &Sym) {
|
||||
OS << formatv("{0:x16}", Sym.getAddress()) << " ("
|
||||
<< (Sym.isDefined() ? "block" : "addressable") << " + "
|
||||
<< formatv("{0:x8}", Sym.getOffset())
|
||||
OS << Sym.getAddress() << " (" << (Sym.isDefined() ? "block" : "addressable")
|
||||
<< " + " << formatv("{0:x8}", Sym.getOffset())
|
||||
<< "): size: " << formatv("{0:x8}", Sym.getSize())
|
||||
<< ", linkage: " << formatv("{0:6}", getLinkageName(Sym.getLinkage()))
|
||||
<< ", scope: " << formatv("{0:8}", getScopeName(Sym.getScope())) << ", "
|
||||
|
@ -113,9 +112,9 @@ raw_ostream &operator<<(raw_ostream &OS, const Symbol &Sym) {
|
|||
|
||||
void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
|
||||
StringRef EdgeKindName) {
|
||||
OS << "edge@" << formatv("{0:x16}", B.getAddress() + E.getOffset()) << ": "
|
||||
<< formatv("{0:x16}", B.getAddress()) << " + "
|
||||
<< formatv("{0:x}", E.getOffset()) << " -- " << EdgeKindName << " -> ";
|
||||
OS << "edge@" << B.getAddress() + E.getOffset() << ": " << B.getAddress()
|
||||
<< " + " << formatv("{0:x}", E.getOffset()) << " -- " << EdgeKindName
|
||||
<< " -> ";
|
||||
|
||||
auto &TargetSym = E.getTarget();
|
||||
if (TargetSym.hasName())
|
||||
|
@ -123,17 +122,16 @@ void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
|
|||
else {
|
||||
auto &TargetBlock = TargetSym.getBlock();
|
||||
auto &TargetSec = TargetBlock.getSection();
|
||||
JITTargetAddress SecAddress = ~JITTargetAddress(0);
|
||||
orc::ExecutorAddr SecAddress(~uint64_t(0));
|
||||
for (auto *B : TargetSec.blocks())
|
||||
if (B->getAddress() < SecAddress)
|
||||
SecAddress = B->getAddress();
|
||||
|
||||
JITTargetAddress SecDelta = TargetSym.getAddress() - SecAddress;
|
||||
OS << formatv("{0:x16}", TargetSym.getAddress()) << " (section "
|
||||
<< TargetSec.getName();
|
||||
orc::ExecutorAddrDiff SecDelta = TargetSym.getAddress() - SecAddress;
|
||||
OS << TargetSym.getAddress() << " (section " << TargetSec.getName();
|
||||
if (SecDelta)
|
||||
OS << " + " << formatv("{0:x}", SecDelta);
|
||||
OS << " / block " << formatv("{0:x16}", TargetBlock.getAddress());
|
||||
OS << " / block " << TargetBlock.getAddress();
|
||||
if (TargetSym.getOffset())
|
||||
OS << " + " << formatv("{0:x}", TargetSym.getOffset());
|
||||
OS << ")";
|
||||
|
@ -265,7 +263,7 @@ void LinkGraph::dump(raw_ostream &OS) {
|
|||
});
|
||||
|
||||
for (auto *B : SortedBlocks) {
|
||||
OS << " block " << formatv("{0:x16}", B->getAddress())
|
||||
OS << " block " << B->getAddress()
|
||||
<< " size = " << formatv("{0:x8}", B->getSize())
|
||||
<< ", align = " << B->getAlignment()
|
||||
<< ", alignment-offset = " << B->getAlignmentOffset();
|
||||
|
@ -290,9 +288,8 @@ void LinkGraph::dump(raw_ostream &OS) {
|
|||
return LHS.getOffset() < RHS.getOffset();
|
||||
});
|
||||
for (auto &E : SortedEdges) {
|
||||
OS << " " << formatv("{0:x16}", B->getFixupAddress(E))
|
||||
<< " (block + " << formatv("{0:x8}", E.getOffset())
|
||||
<< "), addend = ";
|
||||
OS << " " << B->getFixupAddress(E) << " (block + "
|
||||
<< formatv("{0:x8}", E.getOffset()) << "), addend = ";
|
||||
if (E.getAddend() >= 0)
|
||||
OS << formatv("+{0:x8}", E.getAddend());
|
||||
else
|
||||
|
@ -315,16 +312,14 @@ void LinkGraph::dump(raw_ostream &OS) {
|
|||
OS << "Absolute symbols:\n";
|
||||
if (!llvm::empty(absolute_symbols())) {
|
||||
for (auto *Sym : absolute_symbols())
|
||||
OS << " " << format("0x%016" PRIx64, Sym->getAddress()) << ": " << *Sym
|
||||
<< "\n";
|
||||
OS << " " << Sym->getAddress() << ": " << *Sym << "\n";
|
||||
} else
|
||||
OS << " none\n";
|
||||
|
||||
OS << "\nExternal symbols:\n";
|
||||
if (!llvm::empty(external_symbols())) {
|
||||
for (auto *Sym : external_symbols())
|
||||
OS << " " << format("0x%016" PRIx64, Sym->getAddress()) << ": " << *Sym
|
||||
<< "\n";
|
||||
OS << " " << Sym->getAddress() << ": " << *Sym << "\n";
|
||||
} else
|
||||
OS << " none\n";
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ JITLinkContext::LookupMap JITLinkerBase::getExternalSymbolNames() const {
|
|||
// Identify unresolved external symbols.
|
||||
JITLinkContext::LookupMap UnresolvedExternals;
|
||||
for (auto *Sym : G->external_symbols()) {
|
||||
assert(Sym->getAddress() == 0 &&
|
||||
assert(!Sym->getAddress() &&
|
||||
"External has already been assigned an address");
|
||||
assert(Sym->getName() != StringRef() && Sym->getName() != "" &&
|
||||
"Externals must be named");
|
||||
|
@ -209,11 +209,12 @@ void JITLinkerBase::applyLookupResult(AsyncLookupResult Result) {
|
|||
for (auto *Sym : G->external_symbols()) {
|
||||
assert(Sym->getOffset() == 0 &&
|
||||
"External symbol is not at the start of its addressable block");
|
||||
assert(Sym->getAddress() == 0 && "Symbol already resolved");
|
||||
assert(!Sym->getAddress() && "Symbol already resolved");
|
||||
assert(!Sym->isDefined() && "Symbol being resolved is already defined");
|
||||
auto ResultI = Result.find(Sym->getName());
|
||||
if (ResultI != Result.end())
|
||||
Sym->getAddressable().setAddress(ResultI->second.getAddress());
|
||||
Sym->getAddressable().setAddress(
|
||||
orc::ExecutorAddr(ResultI->second.getAddress()));
|
||||
else
|
||||
assert(Sym->getLinkage() == Linkage::Weak &&
|
||||
"Failed to resolve non-weak reference");
|
||||
|
@ -223,7 +224,7 @@ void JITLinkerBase::applyLookupResult(AsyncLookupResult Result) {
|
|||
dbgs() << "Externals after applying lookup result:\n";
|
||||
for (auto *Sym : G->external_symbols())
|
||||
dbgs() << " " << Sym->getName() << ": "
|
||||
<< formatv("{0:x16}", Sym->getAddress()) << "\n";
|
||||
<< formatv("{0:x16}", Sym->getAddress().getValue()) << "\n";
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -66,10 +66,10 @@ JITLinkMemoryManager::InFlightAlloc::~InFlightAlloc() = default;
|
|||
|
||||
static Error runAllocAction(AllocActionCall &C) {
|
||||
using WrapperFnTy = CWrapperFunctionResult (*)(const void *, size_t);
|
||||
auto *Fn = jitTargetAddressToPointer<WrapperFnTy>(C.FnAddr);
|
||||
auto *Fn = C.FnAddr.toPtr<WrapperFnTy>();
|
||||
|
||||
return toError(Fn(jitTargetAddressToPointer<const void *>(C.CtxAddr),
|
||||
static_cast<size_t>(C.CtxSize)));
|
||||
return toError(
|
||||
Fn(C.CtxAddr.toPtr<const void *>(), static_cast<size_t>(C.CtxSize)));
|
||||
}
|
||||
|
||||
BasicLayout::BasicLayout(LinkGraph &G) : G(G) {
|
||||
|
@ -207,7 +207,7 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
|
|||
std::make_unique<LinkGraph>("", Triple(), 0, support::native, nullptr);
|
||||
AllocGroupSmallMap<Block *> ContentBlocks;
|
||||
|
||||
JITTargetAddress NextAddr = 0x100000;
|
||||
orc::ExecutorAddr NextAddr(0x100000);
|
||||
for (auto &KV : Segments) {
|
||||
auto &AG = KV.first;
|
||||
auto &Seg = KV.second;
|
||||
|
@ -220,7 +220,8 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
|
|||
Sec.setMemDeallocPolicy(AG.getMemDeallocPolicy());
|
||||
|
||||
if (Seg.ContentSize != 0) {
|
||||
NextAddr = alignTo(NextAddr, Seg.ContentAlign);
|
||||
NextAddr =
|
||||
orc::ExecutorAddr(alignTo(NextAddr.getValue(), Seg.ContentAlign));
|
||||
auto &B =
|
||||
G->createMutableContentBlock(Sec, G->allocateBuffer(Seg.ContentSize),
|
||||
NextAddr, Seg.ContentAlign.value(), 0);
|
||||
|
@ -426,8 +427,8 @@ void InProcessMemoryManager::allocate(const JITLinkDylib *JD, LinkGraph &G,
|
|||
static_cast<size_t>(SegsSizes->FinalizeSegs)};
|
||||
}
|
||||
|
||||
auto NextStandardSegAddr = pointerToJITTargetAddress(StandardSegsMem.base());
|
||||
auto NextFinalizeSegAddr = pointerToJITTargetAddress(FinalizeSegsMem.base());
|
||||
auto NextStandardSegAddr = orc::ExecutorAddr::fromPtr(StandardSegsMem.base());
|
||||
auto NextFinalizeSegAddr = orc::ExecutorAddr::fromPtr(FinalizeSegsMem.base());
|
||||
|
||||
LLVM_DEBUG({
|
||||
dbgs() << "InProcessMemoryManager allocated:\n";
|
||||
|
@ -454,7 +455,7 @@ void InProcessMemoryManager::allocate(const JITLinkDylib *JD, LinkGraph &G,
|
|||
? NextStandardSegAddr
|
||||
: NextFinalizeSegAddr;
|
||||
|
||||
Seg.WorkingMem = jitTargetAddressToPointer<char *>(SegAddr);
|
||||
Seg.WorkingMem = SegAddr.toPtr<char *>();
|
||||
Seg.Addr = SegAddr;
|
||||
|
||||
SegAddr += alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize);
|
||||
|
@ -478,8 +479,7 @@ void InProcessMemoryManager::deallocate(std::vector<FinalizedAlloc> Allocs,
|
|||
{
|
||||
std::lock_guard<std::mutex> Lock(FinalizedAllocsMutex);
|
||||
for (auto &Alloc : Allocs) {
|
||||
auto *FA =
|
||||
jitTargetAddressToPointer<FinalizedAllocInfo *>(Alloc.release());
|
||||
auto *FA = Alloc.release().toPtr<FinalizedAllocInfo *>();
|
||||
StandardSegmentsList.push_back(std::move(FA->StandardSegments));
|
||||
if (!FA->DeallocActions.empty())
|
||||
DeallocActionsList.push_back(std::move(FA->DeallocActions));
|
||||
|
@ -520,7 +520,7 @@ InProcessMemoryManager::createFinalizedAlloc(
|
|||
auto *FA = FinalizedAllocInfos.Allocate<FinalizedAllocInfo>();
|
||||
new (FA) FinalizedAllocInfo(
|
||||
{std::move(StandardSegments), std::move(DeallocActions)});
|
||||
return FinalizedAlloc(pointerToJITTargetAddress(FA));
|
||||
return FinalizedAlloc(orc::ExecutorAddr::fromPtr(FA));
|
||||
}
|
||||
|
||||
} // end namespace jitlink
|
||||
|
|
|
@ -134,7 +134,7 @@ Error MachOLinkGraphBuilder::createNormalizedSections() {
|
|||
memcpy(&NSec.SegName, Sec64.segname, 16);
|
||||
NSec.SegName[16] = '\0';
|
||||
|
||||
NSec.Address = Sec64.addr;
|
||||
NSec.Address = orc::ExecutorAddr(Sec64.addr);
|
||||
NSec.Size = Sec64.size;
|
||||
NSec.Alignment = 1ULL << Sec64.align;
|
||||
NSec.Flags = Sec64.flags;
|
||||
|
@ -147,7 +147,7 @@ Error MachOLinkGraphBuilder::createNormalizedSections() {
|
|||
memcpy(&NSec.SegName, Sec32.segname, 16);
|
||||
NSec.SegName[16] = '\0';
|
||||
|
||||
NSec.Address = Sec32.addr;
|
||||
NSec.Address = orc::ExecutorAddr(Sec32.addr);
|
||||
NSec.Size = Sec32.size;
|
||||
NSec.Alignment = 1ULL << Sec32.align;
|
||||
NSec.Flags = Sec32.flags;
|
||||
|
@ -287,7 +287,8 @@ Error MachOLinkGraphBuilder::createNormalizedSymbols() {
|
|||
if (!NSec)
|
||||
return NSec.takeError();
|
||||
|
||||
if (Value < NSec->Address || Value > NSec->Address + NSec->Size)
|
||||
if (orc::ExecutorAddr(Value) < NSec->Address ||
|
||||
orc::ExecutorAddr(Value) > NSec->Address + NSec->Size)
|
||||
return make_error<JITLinkError>("Address " + formatv("{0:x}", Value) +
|
||||
" for symbol " + *Name +
|
||||
" does not fall within section");
|
||||
|
@ -311,8 +312,9 @@ Error MachOLinkGraphBuilder::createNormalizedSymbols() {
|
|||
}
|
||||
|
||||
void MachOLinkGraphBuilder::addSectionStartSymAndBlock(
|
||||
unsigned SecIndex, Section &GraphSec, uint64_t Address, const char *Data,
|
||||
uint64_t Size, uint32_t Alignment, bool IsLive) {
|
||||
unsigned SecIndex, Section &GraphSec, orc::ExecutorAddr Address,
|
||||
const char *Data, orc::ExecutorAddrDiff Size, uint32_t Alignment,
|
||||
bool IsLive) {
|
||||
Block &B =
|
||||
Data ? G->createContentBlock(GraphSec, ArrayRef<char>(Data, Size),
|
||||
Address, Alignment, 0)
|
||||
|
@ -346,7 +348,8 @@ Error MachOLinkGraphBuilder::graphifyRegularSymbols() {
|
|||
return make_error<JITLinkError>("Anonymous common symbol at index " +
|
||||
Twine(KV.first));
|
||||
NSym.GraphSymbol = &G->addCommonSymbol(
|
||||
*NSym.Name, NSym.S, getCommonSection(), 0, NSym.Value,
|
||||
*NSym.Name, NSym.S, getCommonSection(), orc::ExecutorAddr(),
|
||||
orc::ExecutorAddrDiff(NSym.Value),
|
||||
1ull << MachO::GET_COMM_ALIGN(NSym.Desc),
|
||||
NSym.Desc & MachO::N_NO_DEAD_STRIP);
|
||||
} else {
|
||||
|
@ -364,8 +367,8 @@ Error MachOLinkGraphBuilder::graphifyRegularSymbols() {
|
|||
return make_error<JITLinkError>("Anonymous absolute symbol at index " +
|
||||
Twine(KV.first));
|
||||
NSym.GraphSymbol = &G->addAbsoluteSymbol(
|
||||
*NSym.Name, NSym.Value, 0, Linkage::Strong, Scope::Default,
|
||||
NSym.Desc & MachO::N_NO_DEAD_STRIP);
|
||||
*NSym.Name, orc::ExecutorAddr(NSym.Value), 0, Linkage::Strong,
|
||||
Scope::Default, NSym.Desc & MachO::N_NO_DEAD_STRIP);
|
||||
break;
|
||||
case MachO::N_SECT:
|
||||
SecIndexToSymbols[NSym.Sect - 1].push_back(&NSym);
|
||||
|
@ -468,13 +471,13 @@ Error MachOLinkGraphBuilder::graphifyRegularSymbols() {
|
|||
|
||||
// If the section is non-empty but there is no symbol covering the start
|
||||
// address then add an anonymous one.
|
||||
if (SecNSymStack.back()->Value != NSec.Address) {
|
||||
auto AnonBlockSize = SecNSymStack.back()->Value - NSec.Address;
|
||||
if (orc::ExecutorAddr(SecNSymStack.back()->Value) != NSec.Address) {
|
||||
auto AnonBlockSize =
|
||||
orc::ExecutorAddr(SecNSymStack.back()->Value) - NSec.Address;
|
||||
LLVM_DEBUG({
|
||||
dbgs() << " Section start not covered by symbol. "
|
||||
<< "Creating anonymous block to cover [ "
|
||||
<< formatv("{0:x16}", NSec.Address) << " -- "
|
||||
<< formatv("{0:x16}", NSec.Address + AnonBlockSize) << " ]\n";
|
||||
<< "Creating anonymous block to cover [ " << NSec.Address
|
||||
<< " -- " << (NSec.Address + AnonBlockSize) << " ]\n";
|
||||
});
|
||||
addSectionStartSymAndBlock(SecIndex, *NSec.GraphSection, NSec.Address,
|
||||
NSec.Data, AnonBlockSize, NSec.Alignment,
|
||||
|
@ -496,12 +499,12 @@ Error MachOLinkGraphBuilder::graphifyRegularSymbols() {
|
|||
}
|
||||
|
||||
// BlockNSyms now contains the block symbols in reverse canonical order.
|
||||
JITTargetAddress BlockStart = BlockSyms.front()->Value;
|
||||
JITTargetAddress BlockEnd = SecNSymStack.empty()
|
||||
? NSec.Address + NSec.Size
|
||||
: SecNSymStack.back()->Value;
|
||||
JITTargetAddress BlockOffset = BlockStart - NSec.Address;
|
||||
JITTargetAddress BlockSize = BlockEnd - BlockStart;
|
||||
auto BlockStart = orc::ExecutorAddr(BlockSyms.front()->Value);
|
||||
orc::ExecutorAddr BlockEnd =
|
||||
SecNSymStack.empty() ? NSec.Address + NSec.Size
|
||||
: orc::ExecutorAddr(SecNSymStack.back()->Value);
|
||||
orc::ExecutorAddrDiff BlockOffset = BlockStart - NSec.Address;
|
||||
orc::ExecutorAddrDiff BlockSize = BlockEnd - BlockStart;
|
||||
|
||||
LLVM_DEBUG({
|
||||
dbgs() << " Creating block for " << formatv("{0:x16}", BlockStart)
|
||||
|
@ -521,8 +524,8 @@ Error MachOLinkGraphBuilder::graphifyRegularSymbols() {
|
|||
BlockStart, NSec.Alignment,
|
||||
BlockStart % NSec.Alignment);
|
||||
|
||||
Optional<JITTargetAddress> LastCanonicalAddr;
|
||||
JITTargetAddress SymEnd = BlockEnd;
|
||||
Optional<orc::ExecutorAddr> LastCanonicalAddr;
|
||||
auto SymEnd = BlockEnd;
|
||||
while (!BlockSyms.empty()) {
|
||||
auto &NSym = *BlockSyms.back();
|
||||
BlockSyms.pop_back();
|
||||
|
@ -530,9 +533,9 @@ Error MachOLinkGraphBuilder::graphifyRegularSymbols() {
|
|||
bool SymLive =
|
||||
(NSym.Desc & MachO::N_NO_DEAD_STRIP) || SectionIsNoDeadStrip;
|
||||
|
||||
auto &Sym = createStandardGraphSymbol(NSym, B, SymEnd - NSym.Value,
|
||||
SectionIsText, SymLive,
|
||||
LastCanonicalAddr != NSym.Value);
|
||||
auto &Sym = createStandardGraphSymbol(
|
||||
NSym, B, SymEnd - orc::ExecutorAddr(NSym.Value), SectionIsText,
|
||||
SymLive, LastCanonicalAddr != orc::ExecutorAddr(NSym.Value));
|
||||
|
||||
if (LastCanonicalAddr != Sym.getAddress()) {
|
||||
if (LastCanonicalAddr)
|
||||
|
@ -568,11 +571,12 @@ Symbol &MachOLinkGraphBuilder::createStandardGraphSymbol(NormalizedSymbol &NSym,
|
|||
dbgs() << "\n";
|
||||
});
|
||||
|
||||
auto &Sym = NSym.Name ? G->addDefinedSymbol(B, NSym.Value - B.getAddress(),
|
||||
*NSym.Name, Size, NSym.L, NSym.S,
|
||||
IsText, IsNoDeadStrip)
|
||||
: G->addAnonymousSymbol(B, NSym.Value - B.getAddress(),
|
||||
Size, IsText, IsNoDeadStrip);
|
||||
auto SymOffset = orc::ExecutorAddr(NSym.Value) - B.getAddress();
|
||||
auto &Sym =
|
||||
NSym.Name
|
||||
? G->addDefinedSymbol(B, SymOffset, *NSym.Name, Size, NSym.L, NSym.S,
|
||||
IsText, IsNoDeadStrip)
|
||||
: G->addAnonymousSymbol(B, SymOffset, Size, IsText, IsNoDeadStrip);
|
||||
NSym.GraphSymbol = &Sym;
|
||||
|
||||
if (IsCanonical)
|
||||
|
@ -635,12 +639,12 @@ Error MachOLinkGraphBuilder::graphifyCStringSection(
|
|||
|
||||
bool SectionIsNoDeadStrip = NSec.Flags & MachO::S_ATTR_NO_DEAD_STRIP;
|
||||
bool SectionIsText = NSec.Flags & MachO::S_ATTR_PURE_INSTRUCTIONS;
|
||||
JITTargetAddress BlockStart = 0;
|
||||
orc::ExecutorAddrDiff BlockStart = 0;
|
||||
|
||||
// Scan section for null characters.
|
||||
for (size_t I = 0; I != NSec.Size; ++I)
|
||||
if (NSec.Data[I] == '\0') {
|
||||
JITTargetAddress BlockEnd = I + 1;
|
||||
orc::ExecutorAddrDiff BlockEnd = I + 1;
|
||||
size_t BlockSize = BlockEnd - BlockStart;
|
||||
// Create a block for this null terminated string.
|
||||
auto &B = G->createContentBlock(*NSec.GraphSection,
|
||||
|
@ -654,7 +658,8 @@ Error MachOLinkGraphBuilder::graphifyCStringSection(
|
|||
});
|
||||
|
||||
// If there's no symbol at the start of this block then create one.
|
||||
if (NSyms.empty() || NSyms.back()->Value != B.getAddress()) {
|
||||
if (NSyms.empty() ||
|
||||
orc::ExecutorAddr(NSyms.back()->Value) != B.getAddress()) {
|
||||
auto &S = G->addAnonymousSymbol(B, 0, BlockSize, false, false);
|
||||
setCanonicalSymbol(NSec, S);
|
||||
LLVM_DEBUG({
|
||||
|
@ -666,18 +671,19 @@ Error MachOLinkGraphBuilder::graphifyCStringSection(
|
|||
}
|
||||
|
||||
// Process any remaining symbols that point into this block.
|
||||
JITTargetAddress LastCanonicalAddr = B.getAddress() + BlockEnd;
|
||||
while (!NSyms.empty() &&
|
||||
NSyms.back()->Value < (B.getAddress() + BlockSize)) {
|
||||
auto LastCanonicalAddr = B.getAddress() + BlockEnd;
|
||||
while (!NSyms.empty() && orc::ExecutorAddr(NSyms.back()->Value) <
|
||||
B.getAddress() + BlockSize) {
|
||||
auto &NSym = *NSyms.back();
|
||||
size_t SymSize = (B.getAddress() + BlockSize) - NSyms.back()->Value;
|
||||
size_t SymSize = (B.getAddress() + BlockSize) -
|
||||
orc::ExecutorAddr(NSyms.back()->Value);
|
||||
bool SymLive =
|
||||
(NSym.Desc & MachO::N_NO_DEAD_STRIP) || SectionIsNoDeadStrip;
|
||||
|
||||
bool IsCanonical = false;
|
||||
if (LastCanonicalAddr != NSym.Value) {
|
||||
if (LastCanonicalAddr != orc::ExecutorAddr(NSym.Value)) {
|
||||
IsCanonical = true;
|
||||
LastCanonicalAddr = NSym.Value;
|
||||
LastCanonicalAddr = orc::ExecutorAddr(NSym.Value);
|
||||
}
|
||||
|
||||
createStandardGraphSymbol(NSym, B, SymSize, SectionIsText, SymLive,
|
||||
|
|
|
@ -71,13 +71,13 @@ protected:
|
|||
public:
|
||||
char SectName[17];
|
||||
char SegName[17];
|
||||
uint64_t Address = 0;
|
||||
orc::ExecutorAddr Address;
|
||||
uint64_t Size = 0;
|
||||
uint64_t Alignment = 0;
|
||||
uint32_t Flags = 0;
|
||||
const char *Data = nullptr;
|
||||
Section *GraphSection = nullptr;
|
||||
std::map<JITTargetAddress, Symbol *> CanonicalSymbols;
|
||||
std::map<orc::ExecutorAddr, Symbol *> CanonicalSymbols;
|
||||
};
|
||||
|
||||
using SectionParserFunction = std::function<Error(NormalizedSection &S)>;
|
||||
|
@ -137,7 +137,7 @@ protected:
|
|||
/// Returns the symbol with the highest address not greater than the search
|
||||
/// address, or null if no such symbol exists.
|
||||
Symbol *getSymbolByAddress(NormalizedSection &NSec,
|
||||
JITTargetAddress Address) {
|
||||
orc::ExecutorAddr Address) {
|
||||
auto I = NSec.CanonicalSymbols.upper_bound(Address);
|
||||
if (I == NSec.CanonicalSymbols.begin())
|
||||
return nullptr;
|
||||
|
@ -147,7 +147,7 @@ protected:
|
|||
/// Returns the symbol with the highest address not greater than the search
|
||||
/// address, or an error if no such symbol exists.
|
||||
Expected<Symbol &> findSymbolByAddress(NormalizedSection &NSec,
|
||||
JITTargetAddress Address) {
|
||||
orc::ExecutorAddr Address) {
|
||||
auto *Sym = getSymbolByAddress(NSec, Address);
|
||||
if (Sym)
|
||||
if (Address <= Sym->getAddress() + Sym->getSize())
|
||||
|
@ -193,9 +193,9 @@ private:
|
|||
|
||||
Section &getCommonSection();
|
||||
void addSectionStartSymAndBlock(unsigned SecIndex, Section &GraphSec,
|
||||
uint64_t Address, const char *Data,
|
||||
uint64_t Size, uint32_t Alignment,
|
||||
bool IsLive);
|
||||
orc::ExecutorAddr Address, const char *Data,
|
||||
orc::ExecutorAddrDiff Size,
|
||||
uint32_t Alignment, bool IsLive);
|
||||
|
||||
Error createNormalizedSections();
|
||||
Error createNormalizedSymbols();
|
||||
|
|
|
@ -109,7 +109,7 @@ private:
|
|||
Expected<PairRelocInfo>
|
||||
parsePairRelocation(Block &BlockToFix, Edge::Kind SubtractorKind,
|
||||
const MachO::relocation_info &SubRI,
|
||||
JITTargetAddress FixupAddress, const char *FixupContent,
|
||||
orc::ExecutorAddr FixupAddress, const char *FixupContent,
|
||||
object::relocation_iterator &UnsignedRelItr,
|
||||
object::relocation_iterator &RelEnd) {
|
||||
using namespace support;
|
||||
|
@ -162,7 +162,7 @@ private:
|
|||
return ToSymbolSec.takeError();
|
||||
ToSymbol = getSymbolByAddress(*ToSymbolSec, ToSymbolSec->Address);
|
||||
assert(ToSymbol && "No symbol for section");
|
||||
FixupValue -= ToSymbol->getAddress();
|
||||
FixupValue -= ToSymbol->getAddress().getValue();
|
||||
}
|
||||
|
||||
MachOARM64RelocationKind DeltaKind;
|
||||
|
@ -195,7 +195,7 @@ private:
|
|||
|
||||
for (auto &S : Obj.sections()) {
|
||||
|
||||
JITTargetAddress SectionAddress = S.getAddress();
|
||||
orc::ExecutorAddr SectionAddress(S.getAddress());
|
||||
|
||||
// Skip relocations virtual sections.
|
||||
if (S.isVirtual()) {
|
||||
|
@ -234,7 +234,8 @@ private:
|
|||
return Kind.takeError();
|
||||
|
||||
// Find the address of the value to fix up.
|
||||
JITTargetAddress FixupAddress = SectionAddress + (uint32_t)RI.r_address;
|
||||
orc::ExecutorAddr FixupAddress =
|
||||
SectionAddress + (uint32_t)RI.r_address;
|
||||
LLVM_DEBUG({
|
||||
dbgs() << " " << NSec->SectName << " + "
|
||||
<< formatv("{0:x8}", RI.r_address) << ":\n";
|
||||
|
@ -249,7 +250,7 @@ private:
|
|||
BlockToFix = &SymbolToFixOrErr->getBlock();
|
||||
}
|
||||
|
||||
if (FixupAddress + static_cast<JITTargetAddress>(1ULL << RI.r_length) >
|
||||
if (FixupAddress + orc::ExecutorAddrDiff(1ULL << RI.r_length) >
|
||||
BlockToFix->getAddress() + BlockToFix->getContent().size())
|
||||
return make_error<JITLinkError>(
|
||||
"Relocation content extends past end of fixup block");
|
||||
|
@ -290,7 +291,7 @@ private:
|
|||
});
|
||||
|
||||
// Find the address of the value to fix up.
|
||||
JITTargetAddress PairedFixupAddress =
|
||||
orc::ExecutorAddr PairedFixupAddress =
|
||||
SectionAddress + (uint32_t)RI.r_address;
|
||||
if (PairedFixupAddress != FixupAddress)
|
||||
return make_error<JITLinkError>("Paired relocation points at "
|
||||
|
@ -324,7 +325,7 @@ private:
|
|||
Addend = *(const ulittle64_t *)FixupContent;
|
||||
break;
|
||||
case Pointer64Anon: {
|
||||
JITTargetAddress TargetAddress = *(const ulittle64_t *)FixupContent;
|
||||
orc::ExecutorAddr TargetAddress(*(const ulittle64_t *)FixupContent);
|
||||
auto TargetNSec = findSectionByIndex(RI.r_symbolnum - 1);
|
||||
if (!TargetNSec)
|
||||
return TargetNSec.takeError();
|
||||
|
@ -435,7 +436,7 @@ public:
|
|||
|
||||
Symbol &createGOTEntry(Symbol &Target) {
|
||||
auto &GOTEntryBlock = G.createContentBlock(
|
||||
getGOTSection(), getGOTEntryBlockContent(), 0, 8, 0);
|
||||
getGOTSection(), getGOTEntryBlockContent(), orc::ExecutorAddr(), 8, 0);
|
||||
GOTEntryBlock.addEdge(Pointer64, 0, Target, 0);
|
||||
return G.addAnonymousSymbol(GOTEntryBlock, 0, 8, false, false);
|
||||
}
|
||||
|
@ -457,8 +458,8 @@ public:
|
|||
}
|
||||
|
||||
Symbol &createPLTStub(Symbol &Target) {
|
||||
auto &StubContentBlock =
|
||||
G.createContentBlock(getStubsSection(), getStubBlockContent(), 0, 1, 0);
|
||||
auto &StubContentBlock = G.createContentBlock(
|
||||
getStubsSection(), getStubBlockContent(), orc::ExecutorAddr(), 1, 0);
|
||||
// Re-use GOT entries for stub targets.
|
||||
auto &GOTEntrySymbol = getGOTEntry(Target);
|
||||
StubContentBlock.addEdge(LDRLiteral19, 0, GOTEntrySymbol, 0);
|
||||
|
@ -545,11 +546,12 @@ private:
|
|||
|
||||
char *BlockWorkingMem = B.getAlreadyMutableContent().data();
|
||||
char *FixupPtr = BlockWorkingMem + E.getOffset();
|
||||
JITTargetAddress FixupAddress = B.getAddress() + E.getOffset();
|
||||
orc::ExecutorAddr FixupAddress = B.getAddress() + E.getOffset();
|
||||
|
||||
switch (E.getKind()) {
|
||||
case Branch26: {
|
||||
assert((FixupAddress & 0x3) == 0 && "Branch-inst is not 32-bit aligned");
|
||||
assert((FixupAddress.getValue() & 0x3) == 0 &&
|
||||
"Branch-inst is not 32-bit aligned");
|
||||
|
||||
int64_t Value = E.getTarget().getAddress() - FixupAddress + E.getAddend();
|
||||
|
||||
|
@ -569,7 +571,7 @@ private:
|
|||
break;
|
||||
}
|
||||
case Pointer32: {
|
||||
uint64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
uint64_t Value = E.getTarget().getAddress().getValue() + E.getAddend();
|
||||
if (Value > std::numeric_limits<uint32_t>::max())
|
||||
return makeTargetOutOfRangeError(G, B, E);
|
||||
*(ulittle32_t *)FixupPtr = Value;
|
||||
|
@ -577,7 +579,7 @@ private:
|
|||
}
|
||||
case Pointer64:
|
||||
case Pointer64Anon: {
|
||||
uint64_t Value = E.getTarget().getAddress() + E.getAddend();
|
||||
uint64_t Value = E.getTarget().getAddress().getValue() + E.getAddend();
|
||||
*(ulittle64_t *)FixupPtr = Value;
|
||||
break;
|
||||
}
|
||||
|
@ -587,9 +589,10 @@ private:
|
|||
assert((E.getKind() != GOTPage21 || E.getAddend() == 0) &&
|
||||
"GOTPAGE21 with non-zero addend");
|
||||
uint64_t TargetPage =
|
||||
(E.getTarget().getAddress() + E.getAddend()) &
|
||||
~static_cast<uint64_t>(4096 - 1);
|
||||
uint64_t PCPage = FixupAddress & ~static_cast<uint64_t>(4096 - 1);
|
||||
(E.getTarget().getAddress().getValue() + E.getAddend()) &
|
||||
~static_cast<uint64_t>(4096 - 1);
|
||||
uint64_t PCPage =
|
||||
FixupAddress.getValue() & ~static_cast<uint64_t>(4096 - 1);
|
||||
|
||||
int64_t PageDelta = TargetPage - PCPage;
|
||||
if (PageDelta < -(1 << 30) || PageDelta > ((1 << 30) - 1))
|
||||
|
@ -606,7 +609,7 @@ private:
|
|||
}
|
||||
case PageOffset12: {
|
||||
uint64_t TargetOffset =
|
||||
(E.getTarget().getAddress() + E.getAddend()) & 0xfff;
|
||||
(E.getTarget().getAddress() + E.getAddend()).getValue() & 0xfff;
|
||||
|
||||
uint32_t RawInstr = *(ulittle32_t *)FixupPtr;
|
||||
unsigned ImmShift = getPageOffset12Shift(RawInstr);
|
||||
|
@ -627,7 +630,7 @@ private:
|
|||
assert((RawInstr & 0xfffffc00) == 0xf9400000 &&
|
||||
"RawInstr isn't a 64-bit LDR immediate");
|
||||
|
||||
uint32_t TargetOffset = E.getTarget().getAddress() & 0xfff;
|
||||
uint32_t TargetOffset = E.getTarget().getAddress().getValue() & 0xfff;
|
||||
assert((TargetOffset & 0x7) == 0 && "GOT entry is not 8-byte aligned");
|
||||
uint32_t EncodedImm = (TargetOffset >> 3) << 10;
|
||||
uint32_t FixedInstr = RawInstr | EncodedImm;
|
||||
|
@ -635,7 +638,8 @@ private:
|
|||
break;
|
||||
}
|
||||
case LDRLiteral19: {
|
||||
assert((FixupAddress & 0x3) == 0 && "LDR is not 32-bit aligned");
|
||||
assert((FixupAddress.getValue() & 0x3) == 0 &&
|
||||
"LDR is not 32-bit aligned");
|
||||
assert(E.getAddend() == 0 && "LDRLiteral19 with non-zero addend");
|
||||
uint32_t RawInstr = *(ulittle32_t *)FixupPtr;
|
||||
assert(RawInstr == 0x58000010 && "RawInstr isn't a 64-bit LDR literal");
|
||||
|
|
|
@ -119,7 +119,7 @@ private:
|
|||
// returns the edge kind and addend to be used.
|
||||
Expected<PairRelocInfo> parsePairRelocation(
|
||||
Block &BlockToFix, MachONormalizedRelocationType SubtractorKind,
|
||||
const MachO::relocation_info &SubRI, JITTargetAddress FixupAddress,
|
||||
const MachO::relocation_info &SubRI, orc::ExecutorAddr FixupAddress,
|
||||
const char *FixupContent, object::relocation_iterator &UnsignedRelItr,
|
||||
object::relocation_iterator &RelEnd) {
|
||||
using namespace support;
|
||||
|
@ -172,7 +172,7 @@ private:
|
|||
return ToSymbolSec.takeError();
|
||||
ToSymbol = getSymbolByAddress(*ToSymbolSec, ToSymbolSec->Address);
|
||||
assert(ToSymbol && "No symbol for section");
|
||||
FixupValue -= ToSymbol->getAddress();
|
||||
FixupValue -= ToSymbol->getAddress().getValue();
|
||||
}
|
||||
|
||||
Edge::Kind DeltaKind;
|
||||
|
@ -206,7 +206,7 @@ private:
|
|||
|
||||
for (auto &S : Obj.sections()) {
|
||||
|
||||
JITTargetAddress SectionAddress = S.getAddress();
|
||||
orc::ExecutorAddr SectionAddress(S.getAddress());
|
||||
|
||||
// Skip relocations virtual sections.
|
||||
if (S.isVirtual()) {
|
||||
|
@ -241,7 +241,7 @@ private:
|
|||
MachO::relocation_info RI = getRelocationInfo(RelItr);
|
||||
|
||||
// Find the address of the value to fix up.
|
||||
JITTargetAddress FixupAddress = SectionAddress + (uint32_t)RI.r_address;
|
||||
auto FixupAddress = SectionAddress + (uint32_t)RI.r_address;
|
||||
|
||||
LLVM_DEBUG({
|
||||
dbgs() << " " << NSec->SectName << " + "
|
||||
|
@ -257,7 +257,7 @@ private:
|
|||
BlockToFix = &SymbolToFixOrErr->getBlock();
|
||||
}
|
||||
|
||||
if (FixupAddress + static_cast<JITTargetAddress>(1ULL << RI.r_length) >
|
||||
if (FixupAddress + orc::ExecutorAddrDiff(1ULL << RI.r_length) >
|
||||
BlockToFix->getAddress() + BlockToFix->getContent().size())
|
||||
return make_error<JITLinkError>(
|
||||
"Relocation extends past end of fixup block");
|
||||
|
@ -343,7 +343,7 @@ private:
|
|||
Kind = x86_64::Pointer64;
|
||||
break;
|
||||
case MachOPointer64Anon: {
|
||||
JITTargetAddress TargetAddress = *(const ulittle64_t *)FixupContent;
|
||||
orc::ExecutorAddr TargetAddress(*(const ulittle64_t *)FixupContent);
|
||||
auto TargetNSec = findSectionByIndex(RI.r_symbolnum - 1);
|
||||
if (!TargetNSec)
|
||||
return TargetNSec.takeError();
|
||||
|
@ -367,8 +367,8 @@ private:
|
|||
Kind = x86_64::Delta32;
|
||||
break;
|
||||
case MachOPCRel32Anon: {
|
||||
JITTargetAddress TargetAddress =
|
||||
FixupAddress + 4 + *(const little32_t *)FixupContent;
|
||||
orc::ExecutorAddr TargetAddress(FixupAddress + 4 +
|
||||
*(const little32_t *)FixupContent);
|
||||
auto TargetNSec = findSectionByIndex(RI.r_symbolnum - 1);
|
||||
if (!TargetNSec)
|
||||
return TargetNSec.takeError();
|
||||
|
@ -384,10 +384,10 @@ private:
|
|||
case MachOPCRel32Minus1Anon:
|
||||
case MachOPCRel32Minus2Anon:
|
||||
case MachOPCRel32Minus4Anon: {
|
||||
JITTargetAddress Delta =
|
||||
4 + static_cast<JITTargetAddress>(
|
||||
orc::ExecutorAddrDiff Delta =
|
||||
4 + orc::ExecutorAddrDiff(
|
||||
1ULL << (*MachORelocKind - MachOPCRel32Minus1Anon));
|
||||
JITTargetAddress TargetAddress =
|
||||
orc::ExecutorAddr TargetAddress =
|
||||
FixupAddress + Delta + *(const little32_t *)FixupContent;
|
||||
auto TargetNSec = findSectionByIndex(RI.r_symbolnum - 1);
|
||||
if (!TargetNSec)
|
||||
|
|
|
@ -47,16 +47,16 @@ public:
|
|||
if (impl().isGOTEdgeToFix(E)) {
|
||||
LLVM_DEBUG({
|
||||
dbgs() << " Fixing " << G.getEdgeKindName(E.getKind())
|
||||
<< " edge at " << formatv("{0:x}", B->getFixupAddress(E))
|
||||
<< " (" << formatv("{0:x}", B->getAddress()) << " + "
|
||||
<< " edge at " << B->getFixupAddress(E) << " ("
|
||||
<< B->getAddress() << " + "
|
||||
<< formatv("{0:x}", E.getOffset()) << ")\n";
|
||||
});
|
||||
impl().fixGOTEdge(E, getGOTEntry(E.getTarget()));
|
||||
} else if (impl().isExternalBranchEdge(E)) {
|
||||
LLVM_DEBUG({
|
||||
dbgs() << " Fixing " << G.getEdgeKindName(E.getKind())
|
||||
<< " edge at " << formatv("{0:x}", B->getFixupAddress(E))
|
||||
<< " (" << formatv("{0:x}", B->getAddress()) << " + "
|
||||
<< " edge at " << B->getFixupAddress(E) << " ("
|
||||
<< B->getAddress() << " + "
|
||||
<< formatv("{0:x}", E.getOffset()) << ")\n";
|
||||
});
|
||||
impl().fixPLTEdge(E, getPLTStub(E.getTarget()));
|
||||
|
|
|
@ -95,10 +95,10 @@ Error optimizeGOTAndStubAccesses(LinkGraph &G) {
|
|||
assert(GOTEntryBlock.edges_size() == 1 &&
|
||||
"GOT entry should only have one outgoing edge");
|
||||
auto &GOTTarget = GOTEntryBlock.edges().begin()->getTarget();
|
||||
JITTargetAddress TargetAddr = GOTTarget.getAddress();
|
||||
JITTargetAddress EdgeAddr = B->getFixupAddress(E);
|
||||
orc::ExecutorAddr TargetAddr = GOTTarget.getAddress();
|
||||
orc::ExecutorAddr EdgeAddr = B->getFixupAddress(E);
|
||||
int64_t Displacement = TargetAddr - EdgeAddr + 4;
|
||||
bool TargetInRangeForImmU32 = isInRangeForImmU32(TargetAddr);
|
||||
bool TargetInRangeForImmU32 = isInRangeForImmU32(TargetAddr.getValue());
|
||||
bool DisplacementInRangeForImmS32 = isInRangeForImmS32(Displacement);
|
||||
|
||||
// If both of the Target and displacement is out of range, then
|
||||
|
@ -165,8 +165,8 @@ Error optimizeGOTAndStubAccesses(LinkGraph &G) {
|
|||
"GOT block should only have one outgoing edge");
|
||||
|
||||
auto &GOTTarget = GOTBlock.edges().begin()->getTarget();
|
||||
JITTargetAddress EdgeAddr = B->getAddress() + E.getOffset();
|
||||
JITTargetAddress TargetAddr = GOTTarget.getAddress();
|
||||
orc::ExecutorAddr EdgeAddr = B->getAddress() + E.getOffset();
|
||||
orc::ExecutorAddr TargetAddr = GOTTarget.getAddress();
|
||||
|
||||
int64_t Displacement = TargetAddr - EdgeAddr + 4;
|
||||
if (isInRangeForImmS32(Displacement)) {
|
||||
|
|
|
@ -67,9 +67,9 @@ private:
|
|||
template <typename ELFT>
|
||||
void ELFDebugObjectSection<ELFT>::setTargetMemoryRange(SectionRange Range) {
|
||||
// Only patch load-addresses for executable and data sections.
|
||||
if (isTextOrDataSection()) {
|
||||
Header->sh_addr = static_cast<typename ELFT::uint>(Range.getStart());
|
||||
}
|
||||
if (isTextOrDataSection())
|
||||
Header->sh_addr =
|
||||
static_cast<typename ELFT::uint>(Range.getStart().getValue());
|
||||
}
|
||||
|
||||
template <typename ELFT>
|
||||
|
|
|
@ -129,8 +129,8 @@ public:
|
|||
Section *Sec = nullptr;
|
||||
StringRef SegName;
|
||||
StringRef SecName;
|
||||
JITTargetAddress Alignment = 0;
|
||||
JITTargetAddress StartAddr = 0;
|
||||
uint64_t Alignment = 0;
|
||||
orc::ExecutorAddr StartAddr;
|
||||
uint64_t Size = 0;
|
||||
};
|
||||
|
||||
|
@ -153,7 +153,8 @@ public:
|
|||
return Error::success();
|
||||
}
|
||||
DebugSecInfos.push_back({&Sec, Sec.getName().substr(0, SepPos),
|
||||
Sec.getName().substr(SepPos + 1), 0, 0});
|
||||
Sec.getName().substr(SepPos + 1), 0,
|
||||
orc::ExecutorAddr(), 0});
|
||||
} else {
|
||||
NonDebugSections.push_back(&Sec);
|
||||
|
||||
|
@ -182,11 +183,11 @@ public:
|
|||
size_t ContainerBlockSize =
|
||||
sizeof(typename MachOTraits::Header) + SegmentLCSize;
|
||||
auto ContainerBlockContent = G.allocateBuffer(ContainerBlockSize);
|
||||
MachOContainerBlock =
|
||||
&G.createMutableContentBlock(SDOSec, ContainerBlockContent, 0, 8, 0);
|
||||
MachOContainerBlock = &G.createMutableContentBlock(
|
||||
SDOSec, ContainerBlockContent, orc::ExecutorAddr(), 8, 0);
|
||||
|
||||
// Copy debug section blocks and symbols.
|
||||
JITTargetAddress NextBlockAddr = MachOContainerBlock->getSize();
|
||||
orc::ExecutorAddr NextBlockAddr(MachOContainerBlock->getSize());
|
||||
for (auto &SI : DebugSecInfos) {
|
||||
assert(!llvm::empty(SI.Sec->blocks()) && "Empty debug info section?");
|
||||
|
||||
|
@ -219,7 +220,8 @@ public:
|
|||
G.mergeSections(SDOSec, *SI.Sec);
|
||||
SI.Sec = nullptr;
|
||||
}
|
||||
size_t DebugSectionsSize = NextBlockAddr - MachOContainerBlock->getSize();
|
||||
size_t DebugSectionsSize =
|
||||
NextBlockAddr - orc::ExecutorAddr(MachOContainerBlock->getSize());
|
||||
|
||||
// Write MachO header and debug section load commands.
|
||||
MachOStructWriter Writer(MachOContainerBlock->getAlreadyMutableContent());
|
||||
|
@ -266,9 +268,9 @@ public:
|
|||
memset(&Sec, 0, sizeof(Sec));
|
||||
memcpy(Sec.sectname, SI.SecName.data(), SI.SecName.size());
|
||||
memcpy(Sec.segname, SI.SegName.data(), SI.SegName.size());
|
||||
Sec.addr = SI.StartAddr;
|
||||
Sec.addr = SI.StartAddr.getValue();
|
||||
Sec.size = SI.Size;
|
||||
Sec.offset = SI.StartAddr;
|
||||
Sec.offset = SI.StartAddr.getValue();
|
||||
Sec.align = SI.Alignment;
|
||||
Sec.reloff = 0;
|
||||
Sec.nreloc = 0;
|
||||
|
@ -336,7 +338,7 @@ public:
|
|||
memset(&SecCmd, 0, sizeof(SecCmd));
|
||||
memcpy(SecCmd.sectname, SecName.data(), SecName.size());
|
||||
memcpy(SecCmd.segname, SegName.data(), SegName.size());
|
||||
SecCmd.addr = R.getStart();
|
||||
SecCmd.addr = R.getStart().getValue();
|
||||
SecCmd.size = R.getSize();
|
||||
SecCmd.offset = 0;
|
||||
SecCmd.align = R.getFirstBlock()->getAlignment();
|
||||
|
@ -348,7 +350,7 @@ public:
|
|||
|
||||
SectionRange R(MachOContainerBlock->getSection());
|
||||
G.allocActions().push_back(
|
||||
{{RegisterActionAddr.getValue(), R.getStart(), R.getSize()}, {}});
|
||||
{{RegisterActionAddr, R.getStart(), R.getSize()}, {}});
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,8 @@ public:
|
|||
auto &DSOHandleSection =
|
||||
G->createSection(".data.__dso_handle", jitlink::MemProt::Read);
|
||||
auto &DSOHandleBlock = G->createContentBlock(
|
||||
DSOHandleSection, getDSOHandleContent(PointerSize), 0, 8, 0);
|
||||
DSOHandleSection, getDSOHandleContent(PointerSize), orc::ExecutorAddr(),
|
||||
8, 0);
|
||||
auto &DSOHandleSymbol = G->addDefinedSymbol(
|
||||
DSOHandleBlock, 0, *R->getInitializerSymbol(), DSOHandleBlock.getSize(),
|
||||
jitlink::Linkage::Strong, jitlink::Scope::Default, false, true);
|
||||
|
@ -375,7 +376,7 @@ void ELFNixPlatform::rt_getDeinitializers(
|
|||
|
||||
{
|
||||
std::lock_guard<std::mutex> Lock(PlatformMutex);
|
||||
auto I = HandleAddrToJITDylib.find(Handle.getValue());
|
||||
auto I = HandleAddrToJITDylib.find(Handle);
|
||||
if (I != HandleAddrToJITDylib.end())
|
||||
JD = I->second;
|
||||
}
|
||||
|
@ -406,7 +407,7 @@ void ELFNixPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
|
|||
|
||||
{
|
||||
std::lock_guard<std::mutex> Lock(PlatformMutex);
|
||||
auto I = HandleAddrToJITDylib.find(Handle.getValue());
|
||||
auto I = HandleAddrToJITDylib.find(Handle);
|
||||
if (I != HandleAddrToJITDylib.end())
|
||||
JD = I->second;
|
||||
}
|
||||
|
@ -630,12 +631,11 @@ void ELFNixPlatform::ELFNixPlatformPlugin::addDSOHandleSupportPasses(
|
|||
assert(I != G.defined_symbols().end() && "Missing DSO handle symbol");
|
||||
{
|
||||
std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
|
||||
JITTargetAddress HandleAddr = (*I)->getAddress();
|
||||
auto HandleAddr = (*I)->getAddress();
|
||||
MP.HandleAddrToJITDylib[HandleAddr] = &JD;
|
||||
assert(!MP.InitSeqs.count(&JD) && "InitSeq entry for JD already exists");
|
||||
MP.InitSeqs.insert(std::make_pair(
|
||||
&JD,
|
||||
ELFNixJITDylibInitializers(JD.getName(), ExecutorAddr(HandleAddr))));
|
||||
&JD, ELFNixJITDylibInitializers(JD.getName(), HandleAddr)));
|
||||
}
|
||||
return Error::success();
|
||||
});
|
||||
|
|
|
@ -56,17 +56,17 @@ EPCEHFrameRegistrar::Create(ExecutionSession &ES) {
|
|||
ExecutorAddr(DeregisterEHFrameWrapperFnAddr));
|
||||
}
|
||||
|
||||
Error EPCEHFrameRegistrar::registerEHFrames(JITTargetAddress EHFrameSectionAddr,
|
||||
Error EPCEHFrameRegistrar::registerEHFrames(ExecutorAddr EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) {
|
||||
return ES.callSPSWrapper<void(SPSExecutorAddr, uint64_t)>(
|
||||
RegisterEHFrameWrapperFnAddr, ExecutorAddr(EHFrameSectionAddr),
|
||||
RegisterEHFrameWrapperFnAddr, EHFrameSectionAddr,
|
||||
static_cast<uint64_t>(EHFrameSectionSize));
|
||||
}
|
||||
|
||||
Error EPCEHFrameRegistrar::deregisterEHFrames(
|
||||
JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
|
||||
Error EPCEHFrameRegistrar::deregisterEHFrames(ExecutorAddr EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) {
|
||||
return ES.callSPSWrapper<void(SPSExecutorAddr, uint64_t)>(
|
||||
DeregisterEHFrameWrapperFnAddr, ExecutorAddr(EHFrameSectionAddr),
|
||||
DeregisterEHFrameWrapperFnAddr, EHFrameSectionAddr,
|
||||
static_cast<uint64_t>(EHFrameSectionSize));
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ public:
|
|||
} else if (FinalizeErr)
|
||||
OnFinalize(std::move(FinalizeErr));
|
||||
else
|
||||
OnFinalize(FinalizedAlloc(AllocAddr.getValue()));
|
||||
OnFinalize(FinalizedAlloc(AllocAddr));
|
||||
},
|
||||
Parent.SAs.Allocator, std::move(FR));
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ void EPCGenericJITLinkMemoryManager::completeAllocation(
|
|||
const auto &AG = KV.first;
|
||||
auto &Seg = KV.second;
|
||||
|
||||
Seg.Addr = NextSegAddr.getValue();
|
||||
Seg.Addr = NextSegAddr;
|
||||
KV.second.WorkingMem = BL.getGraph().allocateBuffer(Seg.ContentSize).data();
|
||||
NextSegAddr += ExecutorAddrDiff(
|
||||
alignTo(Seg.ContentSize + Seg.ZeroFillSize, EPC.getPageSize()));
|
||||
|
|
|
@ -119,10 +119,12 @@ Error EPCTrampolinePool::grow() {
|
|||
unsigned NumTrampolines = TrampolinesPerPage;
|
||||
|
||||
auto SegInfo = Alloc->getSegInfo(MemProt::Read | MemProt::Exec);
|
||||
EPCIU.getABISupport().writeTrampolines(
|
||||
SegInfo.WorkingMem.data(), SegInfo.Addr, ResolverAddress, NumTrampolines);
|
||||
EPCIU.getABISupport().writeTrampolines(SegInfo.WorkingMem.data(),
|
||||
SegInfo.Addr.getValue(),
|
||||
ResolverAddress, NumTrampolines);
|
||||
for (unsigned I = 0; I < NumTrampolines; ++I)
|
||||
AvailableTrampolines.push_back(SegInfo.Addr + (I * TrampolineSize));
|
||||
AvailableTrampolines.push_back(SegInfo.Addr.getValue() +
|
||||
(I * TrampolineSize));
|
||||
|
||||
auto FA = Alloc->finalize();
|
||||
if (!FA)
|
||||
|
@ -300,15 +302,15 @@ EPCIndirectionUtils::writeResolverBlock(JITTargetAddress ReentryFnAddr,
|
|||
return Alloc.takeError();
|
||||
|
||||
auto SegInfo = Alloc->getSegInfo(MemProt::Read | MemProt::Exec);
|
||||
ABI->writeResolverCode(SegInfo.WorkingMem.data(), SegInfo.Addr, ReentryFnAddr,
|
||||
ReentryCtxAddr);
|
||||
ABI->writeResolverCode(SegInfo.WorkingMem.data(), SegInfo.Addr.getValue(),
|
||||
ReentryFnAddr, ReentryCtxAddr);
|
||||
|
||||
auto FA = Alloc->finalize();
|
||||
if (!FA)
|
||||
return FA.takeError();
|
||||
|
||||
ResolverBlock = std::move(*FA);
|
||||
return SegInfo.Addr;
|
||||
return SegInfo.Addr.getValue();
|
||||
}
|
||||
|
||||
std::unique_ptr<IndirectStubsManager>
|
||||
|
@ -369,8 +371,9 @@ EPCIndirectionUtils::getIndirectStubs(unsigned NumStubs) {
|
|||
auto StubSeg = Alloc->getSegInfo(StubProt);
|
||||
auto PtrSeg = Alloc->getSegInfo(PtrProt);
|
||||
|
||||
ABI->writeIndirectStubsBlock(StubSeg.WorkingMem.data(), StubSeg.Addr,
|
||||
PtrSeg.Addr, NumStubsToAllocate);
|
||||
ABI->writeIndirectStubsBlock(StubSeg.WorkingMem.data(),
|
||||
StubSeg.Addr.getValue(),
|
||||
PtrSeg.Addr.getValue(), NumStubsToAllocate);
|
||||
|
||||
auto FA = Alloc->finalize();
|
||||
if (!FA)
|
||||
|
@ -381,8 +384,8 @@ EPCIndirectionUtils::getIndirectStubs(unsigned NumStubs) {
|
|||
auto StubExecutorAddr = StubSeg.Addr;
|
||||
auto PtrExecutorAddr = PtrSeg.Addr;
|
||||
for (unsigned I = 0; I != NumStubsToAllocate; ++I) {
|
||||
AvailableIndirectStubs.push_back(
|
||||
IndirectStubInfo(StubExecutorAddr, PtrExecutorAddr));
|
||||
AvailableIndirectStubs.push_back(IndirectStubInfo(
|
||||
StubExecutorAddr.getValue(), PtrExecutorAddr.getValue()));
|
||||
StubExecutorAddr += ABI->getStubSize();
|
||||
PtrExecutorAddr += ABI->getPointerSize();
|
||||
}
|
||||
|
|
|
@ -410,7 +410,7 @@ Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym,
|
|||
while (I < Content.size()) {
|
||||
MCInst Instr;
|
||||
uint64_t InstrSize = 0;
|
||||
uint64_t InstrStart = SymAddress + I;
|
||||
uint64_t InstrStart = SymAddress.getValue() + I;
|
||||
auto DecodeStatus = Disassembler.getInstruction(
|
||||
Instr, InstrSize, Content.drop_front(I), InstrStart, CommentStream);
|
||||
if (DecodeStatus != MCDisassembler::Success) {
|
||||
|
@ -426,7 +426,7 @@ Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym,
|
|||
// Check for a PC-relative address equal to the symbol itself.
|
||||
auto PCRelAddr =
|
||||
MIA.evaluateMemoryOperandAddress(Instr, &STI, InstrStart, InstrSize);
|
||||
if (!PCRelAddr.hasValue() || PCRelAddr.getValue() != SymAddress)
|
||||
if (!PCRelAddr || *PCRelAddr != SymAddress.getValue())
|
||||
continue;
|
||||
|
||||
auto RelocOffInInstr =
|
||||
|
@ -438,8 +438,8 @@ Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym,
|
|||
continue;
|
||||
}
|
||||
|
||||
auto RelocOffInBlock =
|
||||
InstrStart + *RelocOffInInstr - SymAddress + Sym.getOffset();
|
||||
auto RelocOffInBlock = orc::ExecutorAddr(InstrStart) + *RelocOffInInstr -
|
||||
SymAddress + Sym.getOffset();
|
||||
if (ExistingRelocations.contains(RelocOffInBlock))
|
||||
continue;
|
||||
|
||||
|
|
|
@ -106,7 +106,8 @@ private:
|
|||
auto HeaderContent = G.allocateString(
|
||||
StringRef(reinterpret_cast<const char *>(&Hdr), sizeof(Hdr)));
|
||||
|
||||
return G.createContentBlock(HeaderSection, HeaderContent, 0, 8, 0);
|
||||
return G.createContentBlock(HeaderSection, HeaderContent,
|
||||
orc::ExecutorAddr(), 8, 0);
|
||||
}
|
||||
|
||||
static MaterializationUnit::Interface
|
||||
|
@ -439,7 +440,7 @@ void MachOPlatform::rt_getDeinitializers(SendDeinitializerSequenceFn SendResult,
|
|||
|
||||
{
|
||||
std::lock_guard<std::mutex> Lock(PlatformMutex);
|
||||
auto I = HeaderAddrToJITDylib.find(Handle.getValue());
|
||||
auto I = HeaderAddrToJITDylib.find(Handle);
|
||||
if (I != HeaderAddrToJITDylib.end())
|
||||
JD = I->second;
|
||||
}
|
||||
|
@ -469,7 +470,7 @@ void MachOPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
|
|||
|
||||
{
|
||||
std::lock_guard<std::mutex> Lock(PlatformMutex);
|
||||
auto I = HeaderAddrToJITDylib.find(Handle.getValue());
|
||||
auto I = HeaderAddrToJITDylib.find(Handle);
|
||||
if (I != HeaderAddrToJITDylib.end())
|
||||
JD = I->second;
|
||||
}
|
||||
|
@ -661,11 +662,11 @@ Error MachOPlatform::MachOPlatformPlugin::associateJITDylibHeaderSymbol(
|
|||
|
||||
auto &JD = MR.getTargetJITDylib();
|
||||
std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
|
||||
JITTargetAddress HeaderAddr = (*I)->getAddress();
|
||||
auto HeaderAddr = (*I)->getAddress();
|
||||
MP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
|
||||
assert(!MP.InitSeqs.count(&JD) && "InitSeq entry for JD already exists");
|
||||
MP.InitSeqs.insert(std::make_pair(
|
||||
&JD, MachOJITDylibInitializers(JD.getName(), ExecutorAddr(HeaderAddr))));
|
||||
MP.InitSeqs.insert(
|
||||
std::make_pair(&JD, MachOJITDylibInitializers(JD.getName(), HeaderAddr)));
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
|
@ -792,7 +793,7 @@ Error MachOPlatform::MachOPlatformPlugin::registerInitSections(
|
|||
|
||||
if (auto *ObjCImageInfoSec = G.findSectionByName(ObjCImageInfoSectionName)) {
|
||||
if (auto Addr = jitlink::SectionRange(*ObjCImageInfoSec).getStart())
|
||||
ObjCImageInfoAddr.setValue(Addr);
|
||||
ObjCImageInfoAddr = Addr;
|
||||
}
|
||||
|
||||
for (auto InitSectionName : InitSectionNames)
|
||||
|
@ -879,11 +880,10 @@ Error MachOPlatform::MachOPlatformPlugin::registerEHAndTLVSections(
|
|||
if (auto *EHFrameSection = G.findSectionByName(EHFrameSectionName)) {
|
||||
jitlink::SectionRange R(*EHFrameSection);
|
||||
if (!R.empty())
|
||||
G.allocActions().push_back(
|
||||
{{MP.orc_rt_macho_register_ehframe_section.getValue(), R.getStart(),
|
||||
R.getSize()},
|
||||
{MP.orc_rt_macho_deregister_ehframe_section.getValue(), R.getStart(),
|
||||
R.getSize()}});
|
||||
G.allocActions().push_back({{MP.orc_rt_macho_register_ehframe_section,
|
||||
R.getStart(), R.getSize()},
|
||||
{MP.orc_rt_macho_deregister_ehframe_section,
|
||||
R.getStart(), R.getSize()}});
|
||||
}
|
||||
|
||||
// Get a pointer to the thread data section if there is one. It will be used
|
||||
|
@ -913,10 +913,10 @@ Error MachOPlatform::MachOPlatformPlugin::registerEHAndTLVSections(
|
|||
inconvertibleErrorCode());
|
||||
|
||||
G.allocActions().push_back(
|
||||
{{MP.orc_rt_macho_register_thread_data_section.getValue(),
|
||||
R.getStart(), R.getSize()},
|
||||
{MP.orc_rt_macho_deregister_thread_data_section.getValue(),
|
||||
R.getStart(), R.getSize()}});
|
||||
{{MP.orc_rt_macho_register_thread_data_section, R.getStart(),
|
||||
R.getSize()},
|
||||
{MP.orc_rt_macho_deregister_thread_data_section, R.getStart(),
|
||||
R.getSize()}});
|
||||
}
|
||||
}
|
||||
return Error::success();
|
||||
|
@ -963,10 +963,8 @@ Error MachOPlatform::MachOPlatformPlugin::registerEHSectionsPhase1(
|
|||
// Otherwise, add allocation actions to the graph to register eh-frames for
|
||||
// this object.
|
||||
G.allocActions().push_back(
|
||||
{{orc_rt_macho_register_ehframe_section.getValue(), R.getStart(),
|
||||
R.getSize()},
|
||||
{orc_rt_macho_deregister_ehframe_section.getValue(), R.getStart(),
|
||||
R.getSize()}});
|
||||
{{orc_rt_macho_register_ehframe_section, R.getStart(), R.getSize()},
|
||||
{orc_rt_macho_deregister_ehframe_section, R.getStart(), R.getSize()}});
|
||||
|
||||
return Error::success();
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ public:
|
|||
Flags |= JITSymbolFlags::Exported;
|
||||
|
||||
InternedResult[InternedName] =
|
||||
JITEvaluatedSymbol(Sym->getAddress(), Flags);
|
||||
JITEvaluatedSymbol(Sym->getAddress().getValue(), Flags);
|
||||
if (AutoClaim && !MR->getSymbols().count(InternedName)) {
|
||||
assert(!ExtraSymbolsToClaim.count(InternedName) &&
|
||||
"Duplicate symbol to claim?");
|
||||
|
@ -235,7 +235,7 @@ public:
|
|||
if (Sym->getLinkage() == Linkage::Weak)
|
||||
Flags |= JITSymbolFlags::Weak;
|
||||
InternedResult[InternedName] =
|
||||
JITEvaluatedSymbol(Sym->getAddress(), Flags);
|
||||
JITEvaluatedSymbol(Sym->getAddress().getValue(), Flags);
|
||||
if (AutoClaim && !MR->getSymbols().count(InternedName)) {
|
||||
assert(!ExtraSymbolsToClaim.count(InternedName) &&
|
||||
"Duplicate symbol to claim?");
|
||||
|
@ -743,7 +743,7 @@ void EHFrameRegistrationPlugin::modifyPassConfig(
|
|||
PassConfiguration &PassConfig) {
|
||||
|
||||
PassConfig.PostFixupPasses.push_back(createEHFrameRecorderPass(
|
||||
G.getTargetTriple(), [this, &MR](JITTargetAddress Addr, size_t Size) {
|
||||
G.getTargetTriple(), [this, &MR](ExecutorAddr Addr, size_t Size) {
|
||||
if (Addr) {
|
||||
std::lock_guard<std::mutex> Lock(EHFramePluginMutex);
|
||||
assert(!InProcessLinks.count(&MR) &&
|
||||
|
|
|
@ -120,8 +120,8 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) {
|
|||
// then add it to the GOT entry info table.
|
||||
if (Sym->getSize() != 0) {
|
||||
if (auto TS = getELFGOTTarget(G, Sym->getBlock()))
|
||||
FileInfo.GOTEntryInfos[TS->getName()] = {Sym->getSymbolContent(),
|
||||
Sym->getAddress()};
|
||||
FileInfo.GOTEntryInfos[TS->getName()] = {
|
||||
Sym->getSymbolContent(), Sym->getAddress().getValue()};
|
||||
else
|
||||
return TS.takeError();
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) {
|
|||
|
||||
if (auto TS = getELFStubTarget(G, Sym->getBlock()))
|
||||
FileInfo.StubInfos[TS->getName()] = {Sym->getSymbolContent(),
|
||||
Sym->getAddress()};
|
||||
Sym->getAddress().getValue()};
|
||||
else
|
||||
return TS.takeError();
|
||||
SectionContainsContent = true;
|
||||
|
@ -141,18 +141,19 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) {
|
|||
|
||||
if (Sym->hasName()) {
|
||||
if (Sym->isSymbolZeroFill()) {
|
||||
S.SymbolInfos[Sym->getName()] = {Sym->getSize(), Sym->getAddress()};
|
||||
S.SymbolInfos[Sym->getName()] = {Sym->getSize(),
|
||||
Sym->getAddress().getValue()};
|
||||
SectionContainsZeroFill = true;
|
||||
} else {
|
||||
S.SymbolInfos[Sym->getName()] = {Sym->getSymbolContent(),
|
||||
Sym->getAddress()};
|
||||
Sym->getAddress().getValue()};
|
||||
SectionContainsContent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JITTargetAddress SecAddr = FirstSym->getAddress();
|
||||
uint64_t SecSize =
|
||||
auto SecAddr = FirstSym->getAddress();
|
||||
auto SecSize =
|
||||
(LastSym->getBlock().getAddress() + LastSym->getBlock().getSize()) -
|
||||
SecAddr;
|
||||
|
||||
|
@ -161,11 +162,11 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) {
|
|||
"supported yet",
|
||||
inconvertibleErrorCode());
|
||||
if (SectionContainsZeroFill)
|
||||
FileInfo.SectionInfos[Sec.getName()] = {SecSize, SecAddr};
|
||||
FileInfo.SectionInfos[Sec.getName()] = {SecSize, SecAddr.getValue()};
|
||||
else
|
||||
FileInfo.SectionInfos[Sec.getName()] = {
|
||||
ArrayRef<char>(FirstSym->getBlock().getContent().data(), SecSize),
|
||||
SecAddr};
|
||||
SecAddr.getValue()};
|
||||
}
|
||||
|
||||
return Error::success();
|
||||
|
|
|
@ -118,8 +118,8 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) {
|
|||
inconvertibleErrorCode());
|
||||
|
||||
if (auto TS = getMachOGOTTarget(G, Sym->getBlock()))
|
||||
FileInfo.GOTEntryInfos[TS->getName()] = {Sym->getSymbolContent(),
|
||||
Sym->getAddress()};
|
||||
FileInfo.GOTEntryInfos[TS->getName()] = {
|
||||
Sym->getSymbolContent(), Sym->getAddress().getValue()};
|
||||
else
|
||||
return TS.takeError();
|
||||
SectionContainsContent = true;
|
||||
|
@ -130,24 +130,25 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) {
|
|||
|
||||
if (auto TS = getMachOStubTarget(G, Sym->getBlock()))
|
||||
FileInfo.StubInfos[TS->getName()] = {Sym->getSymbolContent(),
|
||||
Sym->getAddress()};
|
||||
Sym->getAddress().getValue()};
|
||||
else
|
||||
return TS.takeError();
|
||||
SectionContainsContent = true;
|
||||
} else if (Sym->hasName()) {
|
||||
if (Sym->isSymbolZeroFill()) {
|
||||
S.SymbolInfos[Sym->getName()] = {Sym->getSize(), Sym->getAddress()};
|
||||
S.SymbolInfos[Sym->getName()] = {Sym->getSize(),
|
||||
Sym->getAddress().getValue()};
|
||||
SectionContainsZeroFill = true;
|
||||
} else {
|
||||
S.SymbolInfos[Sym->getName()] = {Sym->getSymbolContent(),
|
||||
Sym->getAddress()};
|
||||
Sym->getAddress().getValue()};
|
||||
SectionContainsContent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JITTargetAddress SecAddr = FirstSym->getAddress();
|
||||
uint64_t SecSize =
|
||||
auto SecAddr = FirstSym->getAddress();
|
||||
auto SecSize =
|
||||
(LastSym->getBlock().getAddress() + LastSym->getBlock().getSize()) -
|
||||
SecAddr;
|
||||
|
||||
|
@ -156,11 +157,11 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) {
|
|||
"supported yet",
|
||||
inconvertibleErrorCode());
|
||||
if (SectionContainsZeroFill)
|
||||
FileInfo.SectionInfos[Sec.getName()] = {SecSize, SecAddr};
|
||||
FileInfo.SectionInfos[Sec.getName()] = {SecSize, SecAddr.getValue()};
|
||||
else
|
||||
FileInfo.SectionInfos[Sec.getName()] = {
|
||||
ArrayRef<char>(FirstSym->getBlock().getContent().data(), SecSize),
|
||||
SecAddr};
|
||||
SecAddr.getValue()};
|
||||
}
|
||||
|
||||
return Error::success();
|
||||
|
|
|
@ -327,7 +327,7 @@ static uint64_t computeTotalBlockSizes(LinkGraph &G) {
|
|||
}
|
||||
|
||||
static void dumpSectionContents(raw_ostream &OS, LinkGraph &G) {
|
||||
constexpr JITTargetAddress DumpWidth = 16;
|
||||
constexpr orc::ExecutorAddrDiff DumpWidth = 16;
|
||||
static_assert(isPowerOf2_64(DumpWidth), "DumpWidth must be a power of two");
|
||||
|
||||
// Put sections in address order.
|
||||
|
@ -360,12 +360,13 @@ static void dumpSectionContents(raw_ostream &OS, LinkGraph &G) {
|
|||
return LHS->getAddress() < RHS->getAddress();
|
||||
});
|
||||
|
||||
JITTargetAddress NextAddr = Syms.front()->getAddress() & ~(DumpWidth - 1);
|
||||
orc::ExecutorAddr NextAddr(Syms.front()->getAddress().getValue() &
|
||||
~(DumpWidth - 1));
|
||||
for (auto *Sym : Syms) {
|
||||
bool IsZeroFill = Sym->getBlock().isZeroFill();
|
||||
JITTargetAddress SymStart = Sym->getAddress();
|
||||
JITTargetAddress SymSize = Sym->getSize();
|
||||
JITTargetAddress SymEnd = SymStart + SymSize;
|
||||
auto SymStart = Sym->getAddress();
|
||||
auto SymSize = Sym->getSize();
|
||||
auto SymEnd = SymStart + SymSize;
|
||||
const uint8_t *SymData = IsZeroFill ? nullptr
|
||||
: reinterpret_cast<const uint8_t *>(
|
||||
Sym->getSymbolContent().data());
|
||||
|
@ -433,8 +434,8 @@ public:
|
|||
assert(BL.graphAllocActions().empty() &&
|
||||
"Support function calls not supported yet");
|
||||
|
||||
OnFinalized(FinalizedAlloc(
|
||||
pointerToJITTargetAddress(new FinalizedAllocInfo())));
|
||||
OnFinalized(
|
||||
FinalizedAlloc(ExecutorAddr::fromPtr(new FinalizedAllocInfo())));
|
||||
}
|
||||
|
||||
void abandon(OnAbandonedFunction OnAbandoned) override {
|
||||
|
@ -500,8 +501,8 @@ public:
|
|||
sys::MemoryBlock FinalizeSegs(AllocBase + SegsSizes->StandardSegs,
|
||||
SegsSizes->FinalizeSegs);
|
||||
|
||||
auto NextStandardSegAddr = pointerToJITTargetAddress(StandardSegs.base());
|
||||
auto NextFinalizeSegAddr = pointerToJITTargetAddress(FinalizeSegs.base());
|
||||
auto NextStandardSegAddr = ExecutorAddr::fromPtr(StandardSegs.base());
|
||||
auto NextFinalizeSegAddr = ExecutorAddr::fromPtr(FinalizeSegs.base());
|
||||
|
||||
LLVM_DEBUG({
|
||||
dbgs() << "JITLinkSlabAllocator allocated:\n";
|
||||
|
@ -532,7 +533,7 @@ public:
|
|||
dbgs() << " " << Group << " -> " << formatv("{0:x16}", SegAddr)
|
||||
<< "\n";
|
||||
});
|
||||
Seg.WorkingMem = jitTargetAddressToPointer<char *>(SegAddr);
|
||||
Seg.WorkingMem = SegAddr.toPtr<char *>();
|
||||
Seg.Addr = SegAddr + NextSlabDelta;
|
||||
|
||||
SegAddr += alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize);
|
||||
|
@ -559,7 +560,7 @@ public:
|
|||
Error Err = Error::success();
|
||||
for (auto &FA : FinalizedAllocs) {
|
||||
std::unique_ptr<FinalizedAllocInfo> FAI(
|
||||
jitTargetAddressToPointer<FinalizedAllocInfo *>(FA.release()));
|
||||
FA.release().toPtr<FinalizedAllocInfo *>());
|
||||
|
||||
// FIXME: Run dealloc actions.
|
||||
|
||||
|
@ -613,8 +614,8 @@ private:
|
|||
// Calculate the target address delta to link as-if slab were at
|
||||
// SlabAddress.
|
||||
if (SlabAddress != ~0ULL)
|
||||
NextSlabDelta =
|
||||
SlabAddress - pointerToJITTargetAddress(SlabRemaining.base());
|
||||
NextSlabDelta = ExecutorAddr(SlabAddress) -
|
||||
ExecutorAddr::fromPtr(SlabRemaining.base());
|
||||
}
|
||||
|
||||
Error freeBlock(sys::MemoryBlock MB) {
|
||||
|
|
|
@ -76,15 +76,16 @@ TEST(LinkGraphTest, AddressAccess) {
|
|||
getGenericEdgeKindName);
|
||||
|
||||
auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write);
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, 0x1000, 8, 0);
|
||||
orc::ExecutorAddr B1Addr(0x1000);
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0);
|
||||
auto &S1 = G.addDefinedSymbol(B1, 4, "S1", 4, Linkage::Strong, Scope::Default,
|
||||
false, false);
|
||||
B1.addEdge(Edge::FirstRelocation, 8, S1, 0);
|
||||
auto &E1 = *B1.edges().begin();
|
||||
|
||||
EXPECT_EQ(B1.getAddress(), 0x1000U) << "Incorrect block address";
|
||||
EXPECT_EQ(S1.getAddress(), 0x1004U) << "Incorrect symbol address";
|
||||
EXPECT_EQ(B1.getFixupAddress(E1), 0x1008U) << "Incorrect fixup address";
|
||||
EXPECT_EQ(B1.getAddress(), B1Addr) << "Incorrect block address";
|
||||
EXPECT_EQ(S1.getAddress(), B1Addr + 4) << "Incorrect symbol address";
|
||||
EXPECT_EQ(B1.getFixupAddress(E1), B1Addr + 8) << "Incorrect fixup address";
|
||||
}
|
||||
|
||||
TEST(LinkGraphTest, BlockAndSymbolIteration) {
|
||||
|
@ -92,16 +93,20 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) {
|
|||
LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
|
||||
getGenericEdgeKindName);
|
||||
auto &Sec1 = G.createSection("__data.1", MemProt::Read | MemProt::Write);
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, 0x1000, 8, 0);
|
||||
auto &B2 = G.createContentBlock(Sec1, BlockContent, 0x2000, 8, 0);
|
||||
orc::ExecutorAddr B1Addr(0x1000);
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0);
|
||||
orc::ExecutorAddr B2Addr(0x1000);
|
||||
auto &B2 = G.createContentBlock(Sec1, BlockContent, B2Addr, 8, 0);
|
||||
auto &S1 = G.addDefinedSymbol(B1, 0, "S1", 4, Linkage::Strong, Scope::Default,
|
||||
false, false);
|
||||
auto &S2 = G.addDefinedSymbol(B2, 4, "S2", 4, Linkage::Strong, Scope::Default,
|
||||
false, false);
|
||||
|
||||
auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write);
|
||||
auto &B3 = G.createContentBlock(Sec2, BlockContent, 0x3000, 8, 0);
|
||||
auto &B4 = G.createContentBlock(Sec2, BlockContent, 0x4000, 8, 0);
|
||||
orc::ExecutorAddr B3Addr(0x3000);
|
||||
auto &B3 = G.createContentBlock(Sec2, BlockContent, B3Addr, 8, 0);
|
||||
orc::ExecutorAddr B4Addr(0x4000);
|
||||
auto &B4 = G.createContentBlock(Sec2, BlockContent, B4Addr, 8, 0);
|
||||
auto &S3 = G.addDefinedSymbol(B3, 0, "S3", 4, Linkage::Strong, Scope::Default,
|
||||
false, false);
|
||||
auto &S4 = G.addDefinedSymbol(B4, 4, "S4", 4, Linkage::Strong, Scope::Default,
|
||||
|
@ -141,7 +146,8 @@ TEST(LinkGraphTest, ContentAccessAndUpdate) {
|
|||
auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
|
||||
|
||||
// Create an initial block.
|
||||
auto &B = G.createContentBlock(Sec, BlockContent, 0x1000, 8, 0);
|
||||
orc::ExecutorAddr BAddr(0x1000);
|
||||
auto &B = G.createContentBlock(Sec, BlockContent, BAddr, 8, 0);
|
||||
|
||||
EXPECT_FALSE(B.isContentMutable()) << "Content unexpectedly mutable";
|
||||
EXPECT_EQ(B.getContent().data(), BlockContent.data())
|
||||
|
@ -196,7 +202,8 @@ TEST(LinkGraphTest, ContentAccessAndUpdate) {
|
|||
<< "Unexpected block content size";
|
||||
|
||||
// Create an initially mutable block.
|
||||
auto &B2 = G.createMutableContentBlock(Sec, MutableContent, 0x10000, 8, 0);
|
||||
auto &B2 = G.createMutableContentBlock(Sec, MutableContent,
|
||||
orc::ExecutorAddr(0x10000), 8, 0);
|
||||
|
||||
EXPECT_TRUE(B2.isContentMutable()) << "Expected B2 content to be mutable";
|
||||
}
|
||||
|
@ -208,7 +215,8 @@ TEST(LinkGraphTest, MakeExternal) {
|
|||
auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
|
||||
|
||||
// Create an initial block.
|
||||
auto &B1 = G.createContentBlock(Sec, BlockContent, 0x1000, 8, 0);
|
||||
auto &B1 =
|
||||
G.createContentBlock(Sec, BlockContent, orc::ExecutorAddr(0x1000), 8, 0);
|
||||
|
||||
// Add a symbol to the block.
|
||||
auto &S1 = G.addDefinedSymbol(B1, 0, "S1", 4, Linkage::Strong, Scope::Default,
|
||||
|
@ -218,7 +226,8 @@ TEST(LinkGraphTest, MakeExternal) {
|
|||
EXPECT_FALSE(S1.isExternal()) << "Symbol should not be external";
|
||||
EXPECT_FALSE(S1.isAbsolute()) << "Symbol should not be absolute";
|
||||
EXPECT_TRUE(&S1.getBlock()) << "Symbol should have a non-null block";
|
||||
EXPECT_EQ(S1.getAddress(), 0x1000U) << "Unexpected symbol address";
|
||||
EXPECT_EQ(S1.getAddress(), orc::ExecutorAddr(0x1000))
|
||||
<< "Unexpected symbol address";
|
||||
|
||||
EXPECT_EQ(
|
||||
std::distance(G.defined_symbols().begin(), G.defined_symbols().end()), 1U)
|
||||
|
@ -235,7 +244,8 @@ TEST(LinkGraphTest, MakeExternal) {
|
|||
EXPECT_FALSE(S1.isDefined()) << "Symbol should not be defined";
|
||||
EXPECT_TRUE(S1.isExternal()) << "Symbol should be external";
|
||||
EXPECT_FALSE(S1.isAbsolute()) << "Symbol should not be absolute";
|
||||
EXPECT_EQ(S1.getAddress(), 0U) << "Unexpected symbol address";
|
||||
EXPECT_EQ(S1.getAddress(), orc::ExecutorAddr())
|
||||
<< "Unexpected symbol address";
|
||||
|
||||
EXPECT_EQ(
|
||||
std::distance(G.defined_symbols().begin(), G.defined_symbols().end()), 0U)
|
||||
|
@ -253,7 +263,8 @@ TEST(LinkGraphTest, MakeDefined) {
|
|||
auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
|
||||
|
||||
// Create an initial block.
|
||||
auto &B1 = G.createContentBlock(Sec, BlockContent, 0x1000, 8, 0);
|
||||
orc::ExecutorAddr B1Addr(0x1000);
|
||||
auto &B1 = G.createContentBlock(Sec, BlockContent, B1Addr, 8, 0);
|
||||
|
||||
// Add an external symbol.
|
||||
auto &S1 = G.addExternalSymbol("S1", 4, Linkage::Strong);
|
||||
|
@ -261,7 +272,8 @@ TEST(LinkGraphTest, MakeDefined) {
|
|||
EXPECT_FALSE(S1.isDefined()) << "Symbol should not be defined";
|
||||
EXPECT_TRUE(S1.isExternal()) << "Symbol should be external";
|
||||
EXPECT_FALSE(S1.isAbsolute()) << "Symbol should not be absolute";
|
||||
EXPECT_EQ(S1.getAddress(), 0U) << "Unexpected symbol address";
|
||||
EXPECT_EQ(S1.getAddress(), orc::ExecutorAddr())
|
||||
<< "Unexpected symbol address";
|
||||
|
||||
EXPECT_EQ(
|
||||
std::distance(G.defined_symbols().begin(), G.defined_symbols().end()), 0U)
|
||||
|
@ -279,7 +291,8 @@ TEST(LinkGraphTest, MakeDefined) {
|
|||
EXPECT_FALSE(S1.isExternal()) << "Symbol should not be external";
|
||||
EXPECT_FALSE(S1.isAbsolute()) << "Symbol should not be absolute";
|
||||
EXPECT_TRUE(&S1.getBlock()) << "Symbol should have a non-null block";
|
||||
EXPECT_EQ(S1.getAddress(), 0x1000U) << "Unexpected symbol address";
|
||||
EXPECT_EQ(S1.getAddress(), orc::ExecutorAddr(0x1000U))
|
||||
<< "Unexpected symbol address";
|
||||
|
||||
EXPECT_EQ(
|
||||
std::distance(G.defined_symbols().begin(), G.defined_symbols().end()), 1U)
|
||||
|
@ -296,10 +309,13 @@ TEST(LinkGraphTest, TransferDefinedSymbol) {
|
|||
getGenericEdgeKindName);
|
||||
auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
|
||||
|
||||
// Create an initial block.
|
||||
auto &B1 = G.createContentBlock(Sec, BlockContent, 0x1000, 8, 0);
|
||||
auto &B2 = G.createContentBlock(Sec, BlockContent, 0x2000, 8, 0);
|
||||
auto &B3 = G.createContentBlock(Sec, BlockContent.slice(0, 32), 0x3000, 8, 0);
|
||||
// Create initial blocks.
|
||||
orc::ExecutorAddr B1Addr(0x1000);
|
||||
auto &B1 = G.createContentBlock(Sec, BlockContent, B1Addr, 8, 0);
|
||||
orc::ExecutorAddr B2Addr(0x2000);
|
||||
auto &B2 = G.createContentBlock(Sec, BlockContent, B2Addr, 8, 0);
|
||||
orc::ExecutorAddr B3Addr(0x3000);
|
||||
auto &B3 = G.createContentBlock(Sec, BlockContent.slice(0, 32), B3Addr, 8, 0);
|
||||
|
||||
// Add a symbol.
|
||||
auto &S1 = G.addDefinedSymbol(B1, 0, "S1", B1.getSize(), Linkage::Strong,
|
||||
|
@ -329,8 +345,10 @@ TEST(LinkGraphTest, TransferDefinedSymbolAcrossSections) {
|
|||
auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write);
|
||||
|
||||
// Create blocks in each section.
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, 0x1000, 8, 0);
|
||||
auto &B2 = G.createContentBlock(Sec2, BlockContent, 0x2000, 8, 0);
|
||||
orc::ExecutorAddr B1Addr(0x1000);
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0);
|
||||
orc::ExecutorAddr B2Addr(0x2000);
|
||||
auto &B2 = G.createContentBlock(Sec2, BlockContent, B2Addr, 8, 0);
|
||||
|
||||
// Add a symbol to section 1.
|
||||
auto &S1 = G.addDefinedSymbol(B1, 0, "S1", B1.getSize(), Linkage::Strong,
|
||||
|
@ -359,8 +377,10 @@ TEST(LinkGraphTest, TransferBlock) {
|
|||
auto &Sec2 = G.createSection("__data.2", MemProt::Read | MemProt::Write);
|
||||
|
||||
// Create an initial block.
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, 0x1000, 8, 0);
|
||||
auto &B2 = G.createContentBlock(Sec1, BlockContent, 0x2000, 8, 0);
|
||||
orc::ExecutorAddr B1Addr(0x1000);
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0);
|
||||
orc::ExecutorAddr B2Addr(0x2000);
|
||||
auto &B2 = G.createContentBlock(Sec1, BlockContent, B2Addr, 8, 0);
|
||||
|
||||
// Add some symbols on B1...
|
||||
G.addDefinedSymbol(B1, 0, "S1", B1.getSize(), Linkage::Strong, Scope::Default,
|
||||
|
@ -404,9 +424,12 @@ TEST(LinkGraphTest, MergeSections) {
|
|||
auto &Sec3 = G.createSection("__data.3", MemProt::Read | MemProt::Write);
|
||||
|
||||
// Create an initial block.
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, 0x1000, 8, 0);
|
||||
auto &B2 = G.createContentBlock(Sec2, BlockContent, 0x2000, 8, 0);
|
||||
auto &B3 = G.createContentBlock(Sec3, BlockContent, 0x3000, 8, 0);
|
||||
orc::ExecutorAddr B1Addr(0x1000);
|
||||
auto &B1 = G.createContentBlock(Sec1, BlockContent, B1Addr, 8, 0);
|
||||
orc::ExecutorAddr B2Addr(0x2000);
|
||||
auto &B2 = G.createContentBlock(Sec2, BlockContent, B2Addr, 8, 0);
|
||||
orc::ExecutorAddr B3Addr(0x3000);
|
||||
auto &B3 = G.createContentBlock(Sec3, BlockContent, B3Addr, 8, 0);
|
||||
|
||||
// Add a symbols for each block.
|
||||
G.addDefinedSymbol(B1, 0, "S1", B1.getSize(), Linkage::Strong, Scope::Default,
|
||||
|
@ -482,7 +505,8 @@ TEST(LinkGraphTest, SplitBlock) {
|
|||
auto &Sec = G.createSection("__data", MemProt::Read | MemProt::Write);
|
||||
|
||||
// Create the block to split.
|
||||
auto &B1 = G.createContentBlock(Sec, BlockContent, 0x1000, 8, 0);
|
||||
orc::ExecutorAddr B1Addr(0x1000);
|
||||
auto &B1 = G.createContentBlock(Sec, BlockContent, B1Addr, 8, 0);
|
||||
|
||||
// Add some symbols to the block.
|
||||
auto &S1 = G.addDefinedSymbol(B1, 0, "S1", 4, Linkage::Strong, Scope::Default,
|
||||
|
@ -499,7 +523,8 @@ TEST(LinkGraphTest, SplitBlock) {
|
|||
|
||||
// Add an extra block, EB, and target symbols, and use these to add edges
|
||||
// from B1 to EB.
|
||||
auto &EB = G.createContentBlock(Sec, BlockContent, 0x2000, 8, 0);
|
||||
orc::ExecutorAddr EBAddr(0x2000);
|
||||
auto &EB = G.createContentBlock(Sec, BlockContent, EBAddr, 8, 0);
|
||||
auto &ES1 = G.addDefinedSymbol(EB, 0, "TS1", 4, Linkage::Strong,
|
||||
Scope::Default, false, false);
|
||||
auto &ES2 = G.addDefinedSymbol(EB, 4, "TS2", 4, Linkage::Strong,
|
||||
|
@ -519,10 +544,10 @@ TEST(LinkGraphTest, SplitBlock) {
|
|||
auto &B2 = G.splitBlock(B1, 8);
|
||||
|
||||
// Check that the block addresses and content matches what we would expect.
|
||||
EXPECT_EQ(B1.getAddress(), 0x1008U);
|
||||
EXPECT_EQ(B1.getAddress(), B1Addr + 8);
|
||||
EXPECT_EQ(B1.getContent(), BlockContent.slice(8));
|
||||
|
||||
EXPECT_EQ(B2.getAddress(), 0x1000U);
|
||||
EXPECT_EQ(B2.getAddress(), B1Addr);
|
||||
EXPECT_EQ(B2.getContent(), BlockContent.slice(0, 8));
|
||||
|
||||
// Check that symbols in B1 were transferred as expected:
|
||||
|
|
|
@ -44,7 +44,8 @@ TEST_F(ObjectLinkingLayerTest, AddLinkGraph) {
|
|||
support::little, x86_64::getEdgeKindName);
|
||||
|
||||
auto &Sec1 = G->createSection("__data", MemProt::Read | MemProt::Write);
|
||||
auto &B1 = G->createContentBlock(Sec1, BlockContent, 0x1000, 8, 0);
|
||||
auto &B1 = G->createContentBlock(Sec1, BlockContent,
|
||||
orc::ExecutorAddr(0x1000), 8, 0);
|
||||
G->addDefinedSymbol(B1, 4, "_X", 4, Linkage::Strong, Scope::Default, false,
|
||||
false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue