Skip to content

Commit 148c69d

Browse files
authored
[llvm] annotate interfaces in llvm/ExecutionEngine for DLL export (#140809)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/ExecutionEngine` library. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The following manual adjustments were also applied after running IDS on Linux: - Add `LLVM_ABI_FRIEND` to friend member functions declared with `LLVM_ABI` - Add `LLVM_ABI` to a subset of private class methods and fields that require export - Add `LLVM_ABI` to a small number of symbols that require export but are not declared in headers - Add `LLVM_ABI` to a number of `extern "C"` methods that IDS missed because they're implicitly exported ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
1 parent a903271 commit 148c69d

File tree

101 files changed

+872
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+872
-721
lines changed

llvm/include/llvm/ExecutionEngine/ExecutionEngine.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Object/Binary.h"
2626
#include "llvm/Support/CBindingWrapping.h"
2727
#include "llvm/Support/CodeGen.h"
28+
#include "llvm/Support/Compiler.h"
2829
#include "llvm/Support/ErrorHandling.h"
2930
#include "llvm/Support/Mutex.h"
3031
#include "llvm/Target/TargetMachine.h"
@@ -88,15 +89,15 @@ class ExecutionEngineState {
8889
/// Erase an entry from the mapping table.
8990
///
9091
/// \returns The address that \p ToUnmap was mapped to.
91-
uint64_t RemoveMapping(StringRef Name);
92+
LLVM_ABI uint64_t RemoveMapping(StringRef Name);
9293
};
9394

9495
using FunctionCreator = std::function<void *(const std::string &)>;
9596

9697
/// Abstract interface for implementation execution of LLVM modules,
9798
/// designed to support both interpreter and just-in-time (JIT) compiler
9899
/// implementations.
99-
class ExecutionEngine {
100+
class LLVM_ABI ExecutionEngine {
100101
/// The state object holding the global address mapping, which must be
101102
/// accessed synchronously.
102103
//
@@ -550,13 +551,13 @@ class EngineBuilder {
550551

551552
public:
552553
/// Default constructor for EngineBuilder.
553-
EngineBuilder();
554+
LLVM_ABI EngineBuilder();
554555

555556
/// Constructor for EngineBuilder.
556-
EngineBuilder(std::unique_ptr<Module> M);
557+
LLVM_ABI EngineBuilder(std::unique_ptr<Module> M);
557558

558559
// Out-of-line since we don't have the def'n of RTDyldMemoryManager here.
559-
~EngineBuilder();
560+
LLVM_ABI ~EngineBuilder();
560561

561562
/// setEngineKind - Controls whether the user wants the interpreter, the JIT,
562563
/// or whichever engine works. This option defaults to EngineKind::Either.
@@ -571,12 +572,14 @@ class EngineBuilder {
571572
/// to create anything other than MCJIT will cause a runtime error. If create()
572573
/// is called and is successful, the created engine takes ownership of the
573574
/// memory manager. This option defaults to NULL.
574-
EngineBuilder &setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
575+
LLVM_ABI EngineBuilder &
576+
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
575577

576-
EngineBuilder&
578+
LLVM_ABI EngineBuilder &
577579
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
578580

579-
EngineBuilder &setSymbolResolver(std::unique_ptr<LegacyJITSymbolResolver> SR);
581+
LLVM_ABI EngineBuilder &
582+
setSymbolResolver(std::unique_ptr<LegacyJITSymbolResolver> SR);
580583

581584
/// setErrorStr - Set the error string to write to on error. This option
582585
/// defaults to NULL.
@@ -645,20 +648,19 @@ class EngineBuilder {
645648
this->EmulatedTLS = EmulatedTLS;
646649
}
647650

648-
TargetMachine *selectTarget();
651+
LLVM_ABI TargetMachine *selectTarget();
649652

650653
/// selectTarget - Pick a target either via -march or by guessing the native
651654
/// arch. Add any CPU features specified via -mcpu or -mattr.
652-
TargetMachine *selectTarget(const Triple &TargetTriple,
653-
StringRef MArch,
654-
StringRef MCPU,
655-
const SmallVectorImpl<std::string>& MAttrs);
655+
LLVM_ABI TargetMachine *
656+
selectTarget(const Triple &TargetTriple, StringRef MArch, StringRef MCPU,
657+
const SmallVectorImpl<std::string> &MAttrs);
656658

657659
ExecutionEngine *create() {
658660
return create(selectTarget());
659661
}
660662

661-
ExecutionEngine *create(TargetMachine *TM);
663+
LLVM_ABI ExecutionEngine *create(TargetMachine *TM);
662664
};
663665

664666
// Create wrappers for C Binding types (see CBindingWrapping.h).

llvm/include/llvm/ExecutionEngine/Interpreter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#define LLVM_EXECUTIONENGINE_INTERPRETER_H
1616

1717
#include "llvm/ExecutionEngine/ExecutionEngine.h"
18+
#include "llvm/Support/Compiler.h"
1819

19-
extern "C" void LLVMLinkInInterpreter();
20+
extern "C" LLVM_ABI void LLVMLinkInInterpreter();
2021

2122
namespace {
2223
struct ForceInterpreterLinking {

llvm/include/llvm/ExecutionEngine/JITEventListener.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ExecutionEngine/RuntimeDyld.h"
2020
#include "llvm/IR/DebugLoc.h"
2121
#include "llvm/Support/CBindingWrapping.h"
22+
#include "llvm/Support/Compiler.h"
2223
#include <cstdint>
2324

2425
namespace llvm {
@@ -37,7 +38,7 @@ class ObjectFile;
3738
/// profilers and debuggers that need to know where functions have been emitted.
3839
///
3940
/// The default implementation of each method does nothing.
40-
class JITEventListener {
41+
class LLVM_ABI JITEventListener {
4142
public:
4243
using ObjectKey = uint64_t;
4344

llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
1717
#include "llvm/ExecutionEngine/JITSymbol.h"
18+
#include "llvm/Support/Compiler.h"
1819
#include "llvm/Support/Error.h"
1920
#include "llvm/TargetParser/Triple.h"
2021

@@ -36,7 +37,7 @@ class EHFrameCFIBlockInspector {
3637
/// second to PC-begin, third (if present) to LSDA.
3738
///
3839
/// It is illegal to call this function on a block with four or more edges.
39-
static EHFrameCFIBlockInspector FromEdgeScan(Block &B);
40+
LLVM_ABI static EHFrameCFIBlockInspector FromEdgeScan(Block &B);
4041

4142
/// Returns true if this frame is an FDE, false for a CIE.
4243
bool isFDE() const { return CIEEdge != nullptr; }
@@ -85,7 +86,7 @@ class EHFrameCFIBlockInspector {
8586

8687
/// Returns a pointer to the DWARF eh-frame section if the graph contains a
8788
/// non-empty one, otherwise returns null.
88-
Section *getEHFrameSection(LinkGraph &G);
89+
LLVM_ABI Section *getEHFrameSection(LinkGraph &G);
8990

9091
} // end namespace jitlink
9192
} // end namespace llvm

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/Support/Allocator.h"
2828
#include "llvm/Support/BinaryStreamReader.h"
2929
#include "llvm/Support/BinaryStreamWriter.h"
30+
#include "llvm/Support/Compiler.h"
3031
#include "llvm/Support/Endian.h"
3132
#include "llvm/Support/Error.h"
3233
#include "llvm/Support/FormatVariadic.h"
@@ -49,7 +50,7 @@ class Section;
4950

5051
/// Base class for errors originating in JIT linker, e.g. missing relocation
5152
/// support.
52-
class JITLinkError : public ErrorInfo<JITLinkError> {
53+
class LLVM_ABI JITLinkError : public ErrorInfo<JITLinkError> {
5354
public:
5455
static char ID;
5556

@@ -105,7 +106,7 @@ class Edge {
105106

106107
/// Returns the string name of the given generic edge kind, or "unknown"
107108
/// otherwise. Useful for debugging.
108-
const char *getGenericEdgeKindName(Edge::Kind K);
109+
LLVM_ABI const char *getGenericEdgeKindName(Edge::Kind K);
109110

110111
/// Base class for Addressable entities (externals, absolutes, blocks).
111112
class Addressable {
@@ -389,7 +390,7 @@ inline orc::ExecutorAddr alignToBlock(orc::ExecutorAddr Addr, const Block &B) {
389390
// Returns true if the given blocks contains exactly one valid c-string.
390391
// Zero-fill blocks of size 1 count as valid empty strings. Content blocks
391392
// must end with a zero, and contain no zeros before the end.
392-
bool isCStringBlock(Block &B);
393+
LLVM_ABI bool isCStringBlock(Block &B);
393394

394395
/// Describes symbol linkage. This can be used to resolve definition clashes.
395396
enum class Linkage : uint8_t {
@@ -401,7 +402,7 @@ enum class Linkage : uint8_t {
401402
using TargetFlagsType = uint8_t;
402403

403404
/// For errors and debugging output.
404-
const char *getLinkageName(Linkage L);
405+
LLVM_ABI const char *getLinkageName(Linkage L);
405406

406407
/// Defines the scope in which this symbol should be visible:
407408
/// Default -- Visible in the public interface of the linkage unit.
@@ -412,9 +413,9 @@ const char *getLinkageName(Linkage L);
412413
enum class Scope : uint8_t { Default, Hidden, SideEffectsOnly, Local };
413414

414415
/// For debugging output.
415-
const char *getScopeName(Scope S);
416+
LLVM_ABI const char *getScopeName(Scope S);
416417

417-
raw_ostream &operator<<(raw_ostream &OS, const Block &B);
418+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const Block &B);
418419

419420
/// Symbol representation.
420421
///
@@ -708,10 +709,10 @@ class Symbol {
708709
size_t Size = 0;
709710
};
710711

711-
raw_ostream &operator<<(raw_ostream &OS, const Symbol &A);
712+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const Symbol &A);
712713

713-
void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
714-
StringRef EdgeKindName);
714+
LLVM_ABI void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
715+
StringRef EdgeKindName);
715716

716717
/// Represents an object file section.
717718
class Section {
@@ -731,7 +732,7 @@ class Section {
731732
using block_iterator = BlockSet::iterator;
732733
using const_block_iterator = BlockSet::const_iterator;
733734

734-
~Section();
735+
LLVM_ABI ~Section();
735736

736737
// Sections are not movable or copyable.
737738
Section(const Section &) = delete;
@@ -1039,7 +1040,7 @@ class LinkGraph {
10391040
LinkGraph &operator=(const LinkGraph &) = delete;
10401041
LinkGraph(LinkGraph &&) = delete;
10411042
LinkGraph &operator=(LinkGraph &&) = delete;
1042-
~LinkGraph();
1043+
LLVM_ABI ~LinkGraph();
10431044

10441045
/// Returns the name of this graph (usually the name of the original
10451046
/// underlying MemoryBuffer).
@@ -1658,11 +1659,11 @@ class LinkGraph {
16581659
orc::shared::AllocActions &allocActions() { return AAs; }
16591660

16601661
/// Dump the graph.
1661-
void dump(raw_ostream &OS);
1662+
LLVM_ABI void dump(raw_ostream &OS);
16621663

16631664
private:
1664-
std::vector<Block *> splitBlockImpl(std::vector<Block *> Blocks,
1665-
SplitBlockCache *Cache);
1665+
LLVM_ABI std::vector<Block *> splitBlockImpl(std::vector<Block *> Blocks,
1666+
SplitBlockCache *Cache);
16661667

16671668
// Put the BumpPtrAllocator first so that we don't free any of the underlying
16681669
// memory until the Symbol/Addressable destructors have been run.
@@ -1894,15 +1895,15 @@ struct PassConfiguration {
18941895
/// the two types once we have an OrcSupport library.
18951896
enum class SymbolLookupFlags { RequiredSymbol, WeaklyReferencedSymbol };
18961897

1897-
raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupFlags &LF);
1898+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupFlags &LF);
18981899

18991900
/// A map of symbol names to resolved addresses.
19001901
using AsyncLookupResult =
19011902
DenseMap<orc::SymbolStringPtr, orc::ExecutorSymbolDef>;
19021903

19031904
/// A function object to call with a resolved symbol map (See AsyncLookupResult)
19041905
/// or an error if resolution failed.
1905-
class JITLinkAsyncLookupContinuation {
1906+
class LLVM_ABI JITLinkAsyncLookupContinuation {
19061907
public:
19071908
virtual ~JITLinkAsyncLookupContinuation() = default;
19081909
virtual void run(Expected<AsyncLookupResult> LR) = 0;
@@ -1929,7 +1930,7 @@ createLookupContinuation(Continuation Cont) {
19291930
}
19301931

19311932
/// Holds context for a single jitLink invocation.
1932-
class JITLinkContext {
1933+
class LLVM_ABI JITLinkContext {
19331934
public:
19341935
using LookupMap = DenseMap<orc::SymbolStringPtr, SymbolLookupFlags>;
19351936

@@ -1995,14 +1996,14 @@ class JITLinkContext {
19951996

19961997
/// Marks all symbols in a graph live. This can be used as a default,
19971998
/// conservative mark-live implementation.
1998-
Error markAllSymbolsLive(LinkGraph &G);
1999+
LLVM_ABI Error markAllSymbolsLive(LinkGraph &G);
19992000

20002001
/// Create an out of range error for the given edge in the given block.
2001-
Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
2002-
const Edge &E);
2002+
LLVM_ABI Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
2003+
const Edge &E);
20032004

2004-
Error makeAlignmentError(llvm::orc::ExecutorAddr Loc, uint64_t Value, int N,
2005-
const Edge &E);
2005+
LLVM_ABI Error makeAlignmentError(llvm::orc::ExecutorAddr Loc, uint64_t Value,
2006+
int N, const Edge &E);
20062007

20072008
/// Creates a new pointer block in the given section and returns an
20082009
/// Anonymous symbol pointing to it.
@@ -2016,7 +2017,7 @@ using AnonymousPointerCreator =
20162017
Symbol *InitialTarget, uint64_t InitialAddend)>;
20172018

20182019
/// Get target-specific AnonymousPointerCreator
2019-
AnonymousPointerCreator getAnonymousPointerCreator(const Triple &TT);
2020+
LLVM_ABI AnonymousPointerCreator getAnonymousPointerCreator(const Triple &TT);
20202021

20212022
/// Create a jump stub that jumps via the pointer at the given symbol and
20222023
/// an anonymous symbol pointing to it. Return the anonymous symbol.
@@ -2026,7 +2027,7 @@ using PointerJumpStubCreator = unique_function<Symbol &(
20262027
LinkGraph &G, Section &StubSection, Symbol &PointerSymbol)>;
20272028

20282029
/// Get target-specific PointerJumpStubCreator
2029-
PointerJumpStubCreator getPointerJumpStubCreator(const Triple &TT);
2030+
LLVM_ABI PointerJumpStubCreator getPointerJumpStubCreator(const Triple &TT);
20302031

20312032
/// Base case for edge-visitors where the visitor-list is empty.
20322033
inline void visitEdge(LinkGraph &G, Block *B, Edge &E) {}
@@ -2063,17 +2064,18 @@ void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs) {
20632064
/// Note: The graph does not take ownership of the underlying buffer, nor copy
20642065
/// its contents. The caller is responsible for ensuring that the object buffer
20652066
/// outlives the graph.
2066-
Expected<std::unique_ptr<LinkGraph>>
2067+
LLVM_ABI Expected<std::unique_ptr<LinkGraph>>
20672068
createLinkGraphFromObject(MemoryBufferRef ObjectBuffer,
20682069
std::shared_ptr<orc::SymbolStringPool> SSP);
20692070

20702071
/// Create a \c LinkGraph defining the given absolute symbols.
2071-
std::unique_ptr<LinkGraph>
2072+
LLVM_ABI std::unique_ptr<LinkGraph>
20722073
absoluteSymbolsLinkGraph(Triple TT, std::shared_ptr<orc::SymbolStringPool> SSP,
20732074
orc::SymbolMap Symbols);
20742075

20752076
/// Link the given graph.
2076-
void link(std::unique_ptr<LinkGraph> G, std::unique_ptr<JITLinkContext> Ctx);
2077+
LLVM_ABI void link(std::unique_ptr<LinkGraph> G,
2078+
std::unique_ptr<JITLinkContext> Ctx);
20772079

20782080
} // end namespace jitlink
20792081
} // end namespace llvm

0 commit comments

Comments
 (0)