Commit Graph

129 Commits

Author SHA1 Message Date
Javier Lopez-Gomez
1cca2f0f7e Restore symbol lookup in child interpreters
Prior to the upgrade to LLVM13, child interpreters used to also lookup symbols
in their parent.
This commit introduces a `DefinitionGenerator` that allows for symbol lookup
across different `IncrementalJIT` instances, which restores the old behavior.

This change fixes the following tests:
- CodeUnloading/AtExit.C
- MultipleInterpreters/MultipleInterpreters.C

Fixes #12455.
2023-05-31 21:29:03 +02:00
Sergey Linev
0525bca060 Use nullptr in cling
Avoid warnings when -Wzero-as-null-pointer-constant is specified
2023-01-30 08:29:07 +01:00
Axel Naumann
4b2e5f8e2c Reuse existing weak symbols, also from JIT:
With the upgrade to llvm-13, the JIT lost the ability to re-use existing weak
symbols that the JIT had already emitted, instead only looking at dlsym. This
causes a significant increase in JITted symbols, and thus a significant slow-down
of cling / its JIT.

This restores the old behavior, with an identical set of symbols that jet jitted.
2023-01-17 16:59:06 +01:00
Axel Naumann
da247bd77a Re-enable CodeGen-OptLevel after llvm13 upgrade:
With the upgrade, BackendPasses was modifying a TargetMachine that was
not used by SimpleCompiler.

Change that by
- using a SimpleCompiler that uses IncrementalJIT::TM;
- moving the TM creation to IncrementalJIT, and giving access to it

This reduces the runtime of https://github.com/root-project/root/issues/11927
to
- before llvm upgrade: 2.69s
- llvm13, without this commit: ???
- llvm13, with this commit: 2.89s
i.e, a slow-down of 7% (that is likely caused by the different emission
mechanism of Orc-v2; to be confirmed...)
2022-12-21 17:14:02 +01:00
Axel Naumann
3675713fee Remove unused data members, parameters, includes.
(cherry picked from commit 872d7c14d8c8e2883ed20a0b6c66a4bbafa4237d)
2022-12-09 08:44:20 +01:00
Axel Naumann
d8c5c2a206 Pass libCling handle at construction time, resolve from it:
OrcV2 uses specific DyLibs to resolve symbols from, we need a dedicated
resolver for libCling because its symbols cannot be found from the
process.

Remove now unused "ExposeHiddenSharedLibrarySymbols".
2022-12-09 08:44:20 +01:00
Jonas Hahnfeld
927f761b8b TCling: Re-implement autoload via MaterializationUnits
Replace the existing LazyFunctionCreator interface by a function
to add DefinitionGenerators to be passed via the chain Interpreter
-> IncrementalExecutor -> IncrementalJIT.
Implement a DefinitionGenerator in TCling(Callbacks) to define
MaterializationUnits for autoloading symbols. This also allows to
remove the double DynamicLibrarySearchGenerator now that the created
AutoloadLibraryMUs inject the addresses into the JIT after loading
the required library.
2022-12-09 08:44:19 +01:00
Axel Naumann
619f5e83a2 Silence Orc missing symbols message:
IncrementalExecutor has its own, showing what is requesting the
symbols, which is more useful than the diagnostic of Orc. OTOH
Orc might emit more errors than just missing symbols, and if
there are multiple missing symbols, IncrementalExecutor only
shows the first.

So enable `Verbose` also for IncrementalJIT, showing the original
missing symbols as diagnosed by Orc.

This fixes roottest_cling_other_checkMissingSymbolExitCode which
fails due to the extra diagnostic error line.
2022-12-09 08:44:19 +01:00
Vassil Vassilev
ed72130ee6 Fix the special case for Windows. FIXE: Try remove ifdef 2022-12-09 08:44:19 +01:00
Vassil Vassilev
b4b96a6d85 The JIT now is more consistent on OSX with the linker-level mangling
OSX (due to legacy to disambigate between asm and C symbols) implements an extra
linker-level mangling which adds another `_` in the name. However, that is only
in the on-disk representation and needs to be dropped upon calling dlsym.

OrcV2 gives us a handle to the symbol with starts with `__` allowing us to
invert the logic of the symbol search where we drop the `__` for dlsym.
2022-12-09 08:44:19 +01:00
Vassil Vassilev
3ea6cd0e18 Re-teach getAddressOfGlobal to tell if something came from the JIT.
This patch also inverts the parameter from ExcludeHostSymbols to
IncludeHostSymbols to improve readability.

As written in one of the FIXMEs this is a temporary solution which allows us to
go further with the llvm-13 upgrade. We can rework the getAddress* functionality
to reuse more the ORCV2 infrastructure and more importantly to use that
infrastructure in the recommended way.
2022-12-09 08:44:18 +01:00
Vassil Vassilev
8115be39be Rename addSymbol to match what it does and remove redundant params. 2022-12-09 08:44:18 +01:00
Vassil Vassilev
6c35a3a41e The OrcV2 now can iterate over the globals and run the static init for us. 2022-12-09 08:44:18 +01:00
Vassil Vassilev
c8ffc972b7 Implement a solution to the JIT-owned llvm::Modules.
When removing code, we need to recover Clang's CodeGen and this happens by
iterating over the clang::Decls and the llvm::Module for a given Transaction in
the TransactionUnloader.

The problem is that now OrcV2 takes the ownership of the llvm::Module from the
Transaction for itself and then it can notify us when the module was compiled on
demand. Unfortuantely, there is no good way to guarantee that the same module
will be attached to the same transaction. This approach allows the
TransactionUnloader::unloadModule logic to recover CodeGen.

In a longer term, when we switch to partial translation units from clang-repl
we might be able to recover CodeGen without needing to know details about the
generated llvm::Module.
2022-12-09 08:44:18 +01:00
Stefan Gränitz
ace63db064 Rework the cling JIT to use the ORCv2 interface.
The ORCv1 JIT was deprecated and removed in llvm13. The ORCv2 provides several
benefits such as parallel compilation.
2022-12-09 08:44:17 +01:00
Vassil Vassilev
96fccb8e76 Do not alter the llvm::Module when running the static inits.
This change was from MCJIT times and now is not needed anymore. Moreover, the
orcv2 jit infrastructure considers the llvm::Module immutable after it takes
control of it via emitModule. This change will allow us to migrate easier to
orcv2.
2022-02-18 10:14:08 +01:00
Axel Naumann
11d203f55d Do not emit existing weak symbols:
Instead of suppressing the emission of weak symbols that have an existing
in-process definition, remove the definition of the weak symbol from the
module. This prevents relocation "surprises" as seen e.g. on Apple M1, where
weak symbol definitions are expected to be found within the module, and
relocations are thus expected to be local. By removing the definition, the
symbol becomes a reference (declaration) and relocation will work as for any
non-local symbol.

Thus also reduces the amount of duplicate work, as in-process weak symbols
will now be suppressed early.
2021-10-14 15:14:05 +02:00
Mattias Ellert
35259e725a Actually request the use of the large code model for ppc64/ppc64le
Instead of erroring out with an assert.
2021-05-26 10:44:02 +02:00
Vassil Vassilev
561e905b24 Use the dyld to show more meaningful message when a symbol is missing.
The dynamic library manager's dyld can search a symbol in the library path.
This patch uses that functionality to aid the 'unresolved while linking'
diagnostics.

Now we get:

cling -L lib/

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ extern int gErrorIgnoreLevel;
[cling]$ gErrorIgnoreLevel
IncrementalExecutor::executeFunction: symbol 'gErrorIgnoreLevel' unresolved while linking [cling interface function]!
Symbol found in '/.../lib/libCore.so'; did you mean to load it with .L /.../lib/libCore.so ?
[cling]$
2021-05-08 20:59:07 +02:00
Vassil Vassilev
74f74a7d0b Remove the include to IncrementalExecutor.
This exposed a set of missing includes and constructors to destroy the
backend passes.
2021-05-08 20:59:07 +02:00
Jonas Hahnfeld
b38192f29f Disable GlobalISel on AArch64 (#7419)
In tests on an Apple M1 after the upgrade to LLVM 9, this new
instruction selection framework emits branches / calls that expect
all code to be reachable in +/- 128 MB. This cannot be guaranteed
during JIT, which generates code into allocated pages on the heap
and could span the entire address space of the process.
2021-03-09 21:29:04 +01:00
Vassil Vassilev
deafa47202 Remove unused parameters. Fixes -Wunused-parameter. 2021-02-25 20:44:18 +01:00
Vassil Vassilev
b4daff130e LLVM_ON_WIN32 was dropped.
See llvm-mirror/llvm@4833be0
2021-02-25 20:44:18 +01:00
Vassil Vassilev
fa7c45b1ca Orc JIT now takes the ownership of the llvm::Module.
The old JIT infrastructure assumed shared ownership of the llvm::Module
implemented via shared_ptr. This guaranteed each client can have a uniform
view of the llvm::Module. The new infrastructure claims ownership of the object
and even more transfer ownership when the llvm::Module travels through different
layers of the JIT. The claimed advantage is better thread safety.

The new logic defines away an important property which cling has been built
around, that is the shared symbol object ownership.

This patch makes the cling::Transaction the owner of the llvm::Module. The
ownership is transfered when we want the JIT to 'emit' the module. Fortunately,
there is a JIT callback which can transfer back the ownership to the transaction.

This preserves some consistency, however, makes some operations unsafe. For
example, we cannot rely on Transaction::getModule when the module is being
handed to the JIT.

This patch tries to adapt to the new infrastructure by reducing the dependency
on the transaction's llvm::Module in favor of relying more on the information
available in the execution engine (eg. at_exit handling).
2021-02-25 20:44:17 +01:00
Vassil Vassilev
08d52941b2 Delegate the TargetMachine initialization to JITTargetMachineBuilder.
This fixes the uninitialized CodeModel and also is able to detect which is
the best setup for running a JIT.
2021-02-25 20:44:17 +01:00
Vassil Vassilev
ca290d04a0 Try moving cling to the new orc jit api. 2021-02-25 20:44:17 +01:00
Vassil Vassilev
8c77337f72 The default JIT settings are assumed by default now.
See llvm-mirror/llvm@9aafb85.
2021-02-25 20:44:16 +01:00
Vassil Vassilev
89a9b377da Remove redundant include. 2021-02-25 20:44:16 +01:00
Vassil Vassilev
bd0b61528c Allow the atexit functions to be called on their own.
In environments where cling's teardown should be controlled more carefully,
the atexit function handlers should allow to be called separately. This is
useful when a handler depends on alive interpreter and cannot be executed while
the interpreter is half shut down.

This patch should enable TCling's proper shutdown and relax some of the pain
in shutting down ROOT in general.
2019-12-23 19:14:14 +01:00
Vassil Vassilev
2a88ca8943 Constify. 2019-03-16 14:29:29 +01:00
Vassil Vassilev
0b9abc1e14 Force flush cout after execution
The user might use utilities which print on cout and expects the output
to be shown immediately.

This patch automatically flushes std::cout after each execution of a wrapper.
2019-03-16 14:29:29 +01:00
Yuka Takahashi
2849a2ab73 Support autoloading of dynamic symbols and callback from IncrementalExecutor
This patch contains two functionality:
1. Autoloading of dynamic symbols for system headers
   There is three kind of symbols in shared object file, which is 1
   normal symbols, 2 dynamic symbols, and 3 hidden visibility symbols.
   Linker doesn't care about 3, but should take care (of course) 1 and
   2. For system headers, often symbols are defined in .dynsym section
   which means they are 2 dynamic symbols. This patch adds support of
   autoloading those symbols. We fallback to resolving dynamic symbols
   from system headers only if we couldn't resolve from normal symbol
   table, as the initialization of header search is expensive (iterating
   through all system headers)
2. Register callback from IncrementalExecutor
   Previously, LazyFunctionCreatorAutoload was getting callback only
   from DynamicLibraryManager::loadLibrary. This was enough for fixing
   tests, but is insufficient to handle "symbol <something> unresolved
   while linking function" errors as those errors are emitted from
   IncrementalExecutor. Adding a callback from IncrementalExecutor
   enables us to unresolved symbols.

It fixes these kind of errors:
`IncrementalExecutor::executeFunction: symbol '_ZN7TCanvasC1EPKcS1_iiii' unresolved while linking function '_GLOBAL__sub_I_cling_module_8'!`
2018-12-13 10:29:32 +01:00
Bertrand Bellenot
e128adbcca Fix cling on Windows (there is no Emulated TLS on Windows) 2018-03-13 18:44:11 +01:00
Raphael Isemann
62eac4d1d2 Fix formatting of the TLS commit 2017-11-07 03:57:48 +01:00
Raphael Isemann
89c6351e3a Fix thread local storage in the cling JIT
TLS is currently not suppored in the JIT on some platforms.

However, it's possible to enable emulated TLS support in LLVM
which means that we now support TLS across many architectures.
The performance downsides of this are the overhead of accessing
the variable due to the additional indirection by the emulation.

However, this overhead is minimal and shouldn't affect most
programs. It also can be easily worked around from the user side.
This can be donefFor example by wrapping TLS variables into a single
TLS struct variable that then contains the other variables. Or just
minimizing referencing the TLS variable and use a normal copy of
the variable instead and write it back later.

Patch created with a lot of help from Lang Hames and Pavel Labath!
2017-11-07 03:57:48 +01:00
Vassil Vassilev
dfc0e8a2d4 shared_ptr-ize the llvm::Module*.
This is in prepare for the upcoming llvm upgrade. The future orc jit compile
layer needs a std::shared_ptr<llvm::Module>. The current design passes a
llvm::Module* around and any conversions to a shared_ptr cause the
destruction of the llvm::Module which is a long-lived object in cling.
2017-10-05 17:59:08 +02:00
Axel Naumann
15a4056c56 Whitespace. 2017-08-31 08:44:16 +02:00
Axel Naumann
8cfa532b72 Interpreter callback is created after Interpreter ctor. 2017-08-31 08:44:15 +02:00
Axel Naumann
4f41d10b0c Inform callback upon invoking functions / static init. 2017-08-31 08:44:15 +02:00
Philippe Canal
6c368913e7 clang-format suggestion 2017-08-24 17:03:58 +02:00
Frederich Munch
38c4b902cf Fix registration of other atexit functions during an atexit handler. Recursive registration of atexit handlers is legal and should be handled, not ignored. 2017-08-24 17:03:58 +02:00
Frederich Munch
5c41b2957c Hide members of CXAAtExitElement and make it a callable object. Update iteration to use llvm::reverse and C++11 range based for loop. 2017-08-24 17:03:58 +02:00
Frederich Munch
baa1cba4d3 Store unresolved symbols in an unordered_set; have no need for ordering. 2017-08-24 17:03:58 +02:00
Frederich Munch
95c67cb818 Cleanup cruft from CreateHostTargetMachine. 2017-06-20 11:44:13 +02:00
Vassil Vassilev
a1bd767b6b Adapt to interface changes due to upgrade to r302975. 2017-06-08 10:29:13 +02:00
Axel Naumann
875a597aff Move target init early. 2017-05-10 08:29:53 +02:00
Axel Naumann
053223229e Enable all available targets, for instance for the cuda backend. 2017-05-08 14:59:05 +02:00
Bertrand Bellenot
09369c4fd6 Remove the Windows ELF formatting from IncrementalExecutor, since it is now in CIFactory 2017-03-02 11:59:59 +01:00
Frederich Munch
b6afe909f3 Use utils::FunctionToVoidPtr for casting unresolvedSymbol. 2017-02-02 10:14:15 +01:00
Frederich Munch
e4c24a133a Move IncrementalExecutor::CreateHostTargetMachine into IncrementalExecutor.cpp. 2017-01-25 12:14:06 +01:00