llvm-mirror/tools
Lang Hames 900dc7edc7 [ORC] Add generic initializer/deinitializer support.
Initializers and deinitializers are used to implement C++ static constructors
and destructors, runtime registration for some languages (e.g. with the
Objective-C runtime for Objective-C/C++ code) and other tasks that would
typically be performed when a shared-object/dylib is loaded or unloaded by a
statically compiled program.

MCJIT and ORC have historically provided limited support for discovering and
running initializers/deinitializers by scanning the llvm.global_ctors and
llvm.global_dtors variables and recording the functions to be run. This approach
suffers from several drawbacks: (1) It only works for IR inputs, not for object
files (including cached JIT'd objects). (2) It only works for initializers
described by llvm.global_ctors and llvm.global_dtors, however not all
initializers are described in this way (Objective-C, for example, describes
initializers via specially named metadata sections). (3) To make the
initializer/deinitializer functions described by llvm.global_ctors and
llvm.global_dtors searchable they must be promoted to extern linkage, polluting
the JIT symbol table (extra care must be taken to ensure this promotion does
not result in symbol name clashes).

This patch introduces several interdependent changes to ORCv2 to support the
construction of new initialization schemes, and includes an implementation of a
backwards-compatible llvm.global_ctor/llvm.global_dtor scanning scheme, and a
MachO specific scheme that handles Objective-C runtime registration (if the
Objective-C runtime is available) enabling execution of LLVM IR compiled from
Objective-C and Swift.

The major changes included in this patch are:

(1) The MaterializationUnit and MaterializationResponsibility classes are
extended to describe an optional "initializer" symbol for the module (see the
getInitializerSymbol method on each class). The presence or absence of this
symbol indicates whether the module contains any initializers or
deinitializers. The initializer symbol otherwise behaves like any other:
searching for it triggers materialization.

(2) A new Platform interface is introduced in llvm/ExecutionEngine/Orc/Core.h
which provides the following callback interface:

  - Error setupJITDylib(JITDylib &JD): Can be used to install standard symbols
    in JITDylibs upon creation. E.g. __dso_handle.

  - Error notifyAdding(JITDylib &JD, const MaterializationUnit &MU): Generally
    used to record initializer symbols.

  - Error notifyRemoving(JITDylib &JD, VModuleKey K): Used to notify a platform
    that a module is being removed.

  Platform implementations can use these callbacks to track outstanding
initializers and implement a platform-specific approach for executing them. For
example, the MachOPlatform installs a plugin in the JIT linker to scan for both
__mod_inits sections (for C++ static constructors) and ObjC metadata sections.
If discovered, these are processed in the usual platform order: Objective-C
registration is carried out first, then static initializers are executed,
ensuring that calls to Objective-C from static initializers will be safe.

This patch updates LLJIT to use the new scheme for initialization. Two
LLJIT::PlatformSupport classes are implemented: A GenericIR platform and a MachO
platform. The GenericIR platform implements a modified version of the previous
llvm.global-ctor scraping scheme to provide support for Windows and
Linux. LLJIT's MachO platform uses the MachOPlatform class to provide MachO
specific initialization as described above.

Reviewers: sgraenitz, dblaikie

Subscribers: mgorny, hiraditya, mgrang, ributzka, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74300
2020-02-19 13:59:32 -08:00
..
bugpoint Revert "Remove redundant "std::move"s in return statements" 2020-02-10 07:07:40 -08:00
bugpoint-passes Reverted the remainings of c1c9819ef91aab51b5a23fb3027adac5a2f551cc 2020-02-11 16:20:06 -08:00
dsymutil [dsymutil] Explicitly link against libatomic when necessary 2020-02-17 22:28:18 +00:00
gold [Support] On Windows, ensure hardware_concurrency() extends to all CPU sockets and all NUMA groups 2020-02-14 10:24:22 -05:00
llc [Remarks] Extend the RemarkStreamer to support other emitters 2020-02-04 17:16:02 -08:00
lli [ORC] Add generic initializer/deinitializer support. 2020-02-19 13:59:32 -08:00
llvm-ar [llvm-ar] Simplify Windows comparePaths NFCI 2020-02-14 11:20:17 +00:00
llvm-as
llvm-as-fuzzer
llvm-bcanalyzer Revert "Remove redundant "std::move"s in return statements" 2020-02-10 07:07:40 -08:00
llvm-c-test Move the sysroot attribute from DIModule to DICompileUnit 2020-01-17 12:55:40 -08:00
llvm-cat
llvm-cfi-verify Revert "Remove redundant "std::move"s in return statements" 2020-02-10 07:07:40 -08:00
llvm-config Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-cov [Support] On Windows, ensure hardware_concurrency() extends to all CPU sockets and all NUMA groups 2020-02-14 10:24:22 -05:00
llvm-cvtres
llvm-cxxdump
llvm-cxxfilt Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-cxxmap
llvm-diff
llvm-dis
llvm-dwarfdump [llvm-dwarfdump][Stats] Fix the License header 2020-02-10 08:01:56 +01:00
llvm-dwp [DebugInfo]: Added support for DWARFv5 Info section header parsing in llvm-dwp utility. 2020-02-19 10:33:39 +05:30
llvm-elfabi Revert "Remove redundant "std::move"s in return statements" 2020-02-10 07:07:40 -08:00
llvm-exegesis Recommit: "[llvm-exegesis] Improve error reporting in Assembler.cpp" 2020-02-19 14:40:28 +01:00
llvm-extract [llvm-extract] Add -keep-const-init commandline option 2020-02-03 14:30:28 +09:00
llvm-go Reinstate llvm-go to test the go bindings. 2020-02-13 17:24:55 -08:00
llvm-ifs Revert "Remove redundant "std::move"s in return statements" 2020-02-10 07:07:40 -08:00
llvm-isel-fuzzer
llvm-itanium-demangle-fuzzer
llvm-jitlink [ORC] Add generic initializer/deinitializer support. 2020-02-19 13:59:32 -08:00
llvm-jitlistener
llvm-link Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-lipo Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-lto Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-lto2 Improve comments after 8404aeb56a73ab24f9b295111de3b37a37f0b841. 2020-02-18 14:25:21 -05:00
llvm-mc [AsmPrinter][MCStreamer] De-capitalize EmitInstruction and EmitCFI* 2020-02-13 22:08:55 -08:00
llvm-mc-assemble-fuzzer Remove AllTargetsAsmPrinters 2020-01-17 19:04:06 -05:00
llvm-mc-disassemble-fuzzer Remove AllTargetsAsmPrinters 2020-01-17 19:04:06 -05:00
llvm-mca [MC] De-capitalize another set of MCStreamer::Emit* functions 2020-02-14 19:26:52 -08:00
llvm-microsoft-demangle-fuzzer
llvm-ml [ms] [llvm-ml] Add a draft MASM parser 2020-02-16 12:30:46 -05:00
llvm-modextract
llvm-mt
llvm-nm Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-objcopy [llvm-objcopy][WebAssembly] Add dump/add/remove-section support 2020-02-11 15:17:18 -08:00
llvm-objdump [llvm-objdump] Print file format in lowercase to match GNU output. 2020-02-12 08:17:01 -08:00
llvm-opt-fuzzer
llvm-opt-report Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-pdbutil Use std::foo_t rather than std::foo in LLVM. 2020-02-11 15:12:51 -08:00
llvm-profdata [Support] On Windows, ensure hardware_concurrency() extends to all CPU sockets and all NUMA groups 2020-02-14 10:24:22 -05:00
llvm-rc Revert "Remove redundant "std::move"s in return statements" 2020-02-10 07:07:40 -08:00
llvm-readobj [llvm-readobj] - Report a warning when an unexpected DT_SYMENT tag value is met. 2020-02-18 14:36:17 +03:00
llvm-reduce Revert "[llvm-reduce] add ReduceAttribute delta pass" 2020-02-05 14:15:11 -05:00
llvm-rtdyld Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-shlib
llvm-size [llvm-size] print a blank line between archieve members when using sysv format 2020-01-03 14:05:55 +08:00
llvm-special-case-list-fuzzer
llvm-split
llvm-stress
llvm-strings
llvm-symbolizer [llvm-symbolizer]Fix printing of malformed address values not passed via stdin 2020-01-08 18:37:41 +08:00
llvm-undname Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
llvm-xray Use std::foo_t rather than std::foo in LLVM. 2020-02-11 15:12:51 -08:00
llvm-yaml-numeric-parser-fuzzer
lto
msbuild
obj2yaml [obj2yaml] - Fix a -Wsign-compare warning gived by GCC 9.2 2020-02-15 18:35:57 +03:00
opt [Coroutines][5/6] Add coroutine passes to pipeline 2020-02-19 00:57:14 -05:00
opt-viewer [opt viewer] Python compat - decode/encode string 2020-01-29 14:49:24 -08:00
remarks-shlib
sancov [llvm] Replace SmallStr.str().str() with std::string conversion operator. 2020-01-29 21:16:46 -08:00
sanstats
verify-uselistorder
vfabi-demangle-fuzzer [llvm][VectorUtils] Tweak VFShape for scalable vector functions. 2020-01-30 05:53:56 +00:00
xcode-toolchain
yaml2obj [yaml2obj] Add -D k=v to preprocess the input YAML 2020-02-07 09:35:00 -08:00
CMakeLists.txt Continue removing llgo. 2020-02-10 10:33:58 -08:00
LLVMBuild.txt