Skip to content

Commit

Permalink
[JITLink][MachO][x86-64] Introduce generic x86-64 support.
Browse files Browse the repository at this point in the history
This patch introduces generic x86-64 edge kinds, and refactors the MachO/x86-64
backend to use these edge kinds. This simplifies the implementation of the
MachO/x86-64 backend and makes it possible to write generic x86-64 passes and
utilities.

The new edge kinds are different from the original set used in the MachO/x86-64
backend. Several edge kinds that were not meaningfully distinguished in that
backend (e.g. the PCRelMinusN edges) have been merged into single edge kinds in
the new scheme (these edge kinds can be reintroduced later if we find a use for
them). At the same time, new edge kinds have been introduced to convey extra
information about the state of the graph. E.g. The Request*AndTransformTo**
edges represent GOT/TLVP relocations prior to synthesis of the GOT/TLVP
entries, and the 'Relaxable' suffix distinguishes edges that are candidates for
optimization from edges which should be left as-is (e.g. to enable runtime
redirection).

ELF/x86-64 will be refactored to use these generic edges at some point in the
future, and I anticipate a similar refactor to create a generic arm64 support
header too.

Differential Revision: https://reviews.llvm.org/D98305
  • Loading branch information
lhames committed Mar 15, 2021
1 parent bcf95cb commit ecf6466
Show file tree
Hide file tree
Showing 17 changed files with 619 additions and 352 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/ExecutionEngine/JITLink/ELF_x86_64.h
Expand Up @@ -57,7 +57,7 @@ void link_ELF_x86_64(std::unique_ptr<LinkGraph> G,
std::unique_ptr<JITLinkContext> Ctx);

/// Return the string name of the given ELF x86-64 edge kind.
StringRef getELFX86RelocationKindName(Edge::Kind R);
const char *getELFX86RelocationKindName(Edge::Kind R);
} // end namespace jitlink
} // end namespace llvm

Expand Down
22 changes: 13 additions & 9 deletions llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
Expand Up @@ -792,10 +792,13 @@ class LinkGraph {
Section::const_block_iterator, const Block *,
getSectionConstBlocks>;

using GetEdgeKindNameFunction = const char *(*)(Edge::Kind);

LinkGraph(std::string Name, const Triple &TT, unsigned PointerSize,
support::endianness Endianness)
support::endianness Endianness,
GetEdgeKindNameFunction GetEdgeKindName)
: Name(std::move(Name)), TT(TT), PointerSize(PointerSize),
Endianness(Endianness) {}
Endianness(Endianness), GetEdgeKindName(std::move(GetEdgeKindName)) {}

/// Returns the name of this graph (usually the name of the original
/// underlying MemoryBuffer).
Expand All @@ -810,6 +813,8 @@ class LinkGraph {
/// Returns the endianness of content in this graph.
support::endianness getEndianness() const { return Endianness; }

const char *getEdgeKindName(Edge::Kind K) const { return GetEdgeKindName(K); }

/// Allocate a copy of the given string using the LinkGraph's allocator.
/// This can be useful when renaming symbols or adding new content to the
/// graph.
Expand Down Expand Up @@ -1055,13 +1060,7 @@ class LinkGraph {
}

/// Dump the graph.
///
/// If supplied, the EdgeKindToName function will be used to name edge
/// kinds in the debug output. Otherwise raw edge kind numbers will be
/// displayed.
void dump(raw_ostream &OS,
std::function<StringRef(Edge::Kind)> EdegKindToName =
std::function<StringRef(Edge::Kind)>());
void dump(raw_ostream &OS);

private:
// Put the BumpPtrAllocator first so that we don't free any of the underlying
Expand All @@ -1072,6 +1071,7 @@ class LinkGraph {
Triple TT;
unsigned PointerSize;
support::endianness Endianness;
GetEdgeKindNameFunction GetEdgeKindName = nullptr;
SectionList Sections;
ExternalSymbolSet ExternalSymbols;
ExternalSymbolSet AbsoluteSymbols;
Expand Down Expand Up @@ -1387,6 +1387,10 @@ class JITLinkContext {
/// conservative mark-live implementation.
Error markAllSymbolsLive(LinkGraph &G);

/// Create an out of range error for the given edge in the given block.
Error makeTargetOutOfRangeError(const Block &B, const Edge &E,
const char *(*getEdgeKindName)(Edge::Kind));

/// Create a LinkGraph from the given object buffer.
///
/// Note: The graph does not take ownership of the underlying buffer, nor copy
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ExecutionEngine/JITLink/MachO_arm64.h
Expand Up @@ -61,7 +61,7 @@ void link_MachO_arm64(std::unique_ptr<LinkGraph> G,
std::unique_ptr<JITLinkContext> Ctx);

/// Return the string name of the given MachO arm64 edge kind.
StringRef getMachOARM64RelocationKindName(Edge::Kind R);
const char *getMachOARM64RelocationKindName(Edge::Kind R);

} // end namespace jitlink
} // end namespace llvm
Expand Down
30 changes: 0 additions & 30 deletions llvm/include/llvm/ExecutionEngine/JITLink/MachO_x86_64.h
Expand Up @@ -18,33 +18,6 @@
namespace llvm {
namespace jitlink {

namespace MachO_x86_64_Edges {

enum MachOX86RelocationKind : Edge::Kind {
Branch32 = Edge::FirstRelocation,
Branch32ToStub,
Pointer32,
Pointer64,
Pointer64Anon,
PCRel32,
PCRel32Minus1,
PCRel32Minus2,
PCRel32Minus4,
PCRel32Anon,
PCRel32Minus1Anon,
PCRel32Minus2Anon,
PCRel32Minus4Anon,
PCRel32GOTLoad,
PCRel32GOT,
PCRel32TLV,
Delta32,
Delta64,
NegDelta32,
NegDelta64,
};

} // namespace MachO_x86_64_Edges

/// Create a LinkGraph from a MachO/x86-64 relocatable object.
///
/// Note: The graph does not take ownership of the underlying buffer, nor copy
Expand All @@ -65,9 +38,6 @@ createLinkGraphFromMachOObject_x86_64(MemoryBufferRef ObjectBuffer);
void link_MachO_x86_64(std::unique_ptr<LinkGraph> G,
std::unique_ptr<JITLinkContext> Ctx);

/// Return the string name of the given MachO x86-64 edge kind.
StringRef getMachOX86RelocationKindName(Edge::Kind R);

} // end namespace jitlink
} // end namespace llvm

Expand Down

0 comments on commit ecf6466

Please sign in to comment.