Commit Graph

117 Commits

Author SHA1 Message Date
Guilherme Amadio
b0940d1ba7 Re-enable support for profiling/debugging interpreted/JITted code
This feature, originally added in commit 22b1606f, was reverted to
make the LLVM upgrade to version 13 easier. This commit adds back
all functionality as it was just before the LLVM upgrade.
2022-12-15 10:29:03 +01:00
Jonas Hahnfeld
eb2b4bd693 Revert "Add support for profiling/debugging interpreted/JITted code"
This reverts commit 22b1606f5fd842590f04724d789de5b29495efc6 until it
is re-implemented on top of the changes for upgrading to LLVM 13.
2022-12-09 08:44:15 +01:00
Guilherme Amadio
bbc1089732 Add support for profiling/debugging interpreted/JITted code
This commit builds on previous work for getting GDB support for JITted
and interpreted code working in cling. It adds a JIT event listener as
well to create perf map files to allow profiling of interpreted/JITted
code with cling.

The functionality provided is disabled by default. The interface to
enable it has been chosen to be via environment variables to allow both
interpreted code in the prompt as well as linked code to be able to
optionally enable debugging/profiling. Using ld.so as example, where
LD_DEBUG and LD_PROFILE exist, we chose CLING_DEBUG and CLING_PROFILE
to enable these features. For the moment, setting these variables to
anything enables the feature. Later on, if support for oprofile is
added, for example, it may be better to enable specific JIT event
listeners depending on the value of the variables, for example with
CLING_PROFILE=perf or CLING_PROFILE=oprofile, respectively.
2022-06-07 21:59:05 +02:00
Vassil Vassilev
d78d1a03fe Fix building ROOT with external llvm.
Fixes #8141.
2021-08-17 10:29:05 +02:00
Axel Naumann
10180ae79f On Win, do not always-append to cling-compiledata.h.in:
Before, cling-compiledata.h caused
```
interpreter\cling\lib\Interpreter\cling-compiledata.h(6,1): warning C4005: 'CLING_UCRT_VERSION': macro redefinition
  interpreter\cling\lib\Interpreter\cling-compiledata.h(3): message : see previous definition of 'CLING_UCRT_VERSION'
```
due to it containing
```

      #define CLING_INCLUDE_PATHS ""
      #define CLING_UCRT_VERSION  ""
      #define CLING_INCLUDE_PATHS ""
      #define CLING_UCRT_VERSION  "10.0.19041.0"
```
2021-08-10 12:29:07 +02:00
Vassil Vassilev
a89bbcbb04 Do not bind cling's sysroot to a particular version of osx sdk.
The CMAKE_OSX_SYSROOT exports the exact version of the sdk which we build
against. However, this means that binary releases become sensitive to minor sdk
upgrades (eg. MacOSX11.1.sdk -> MacOSX11.2.sdk). Our infrastructure is
relatively resilient to such changes.

This patch introduces a workaround to address this issue -- it uses the fact
that the current sdk's parent directory has a symlink MacOSX.sdk which points
to the current sdk.

This should resolve root-project/root#7021.
2021-03-21 21:59:03 +01:00
Vassil Vassilev
cad5c25c17 Implement -Dbuiltin_cling=Off
Cling needs to be built and installed as part of llvm/clang and
then we need to specify paths as we do for builtin_clang=Off.
2021-02-25 20:44:18 +01:00
Axel Naumann
a28b92c121 clingInterpreter needs -ldl for DynamicLibraryManagerSymbol. 2020-08-19 18:44:09 +02:00
Axel Naumann
02737be6d5 Enable colored diagnostics also for Ninja, also for GCC:
Ninja buffers compiler output, and compilers then think they should
not use colored output (because no terminal). Force it on them.
The same was already implemented for clang, a few lines above.

And let cling survive: it's parsing compiler output, and the ANSI
color escapes confuse the regexes.
2020-05-25 22:29:09 +02:00
Alexander Penev
bdd03109ba Improve symbol resolution.
This patch consolidates the symbol resolution facilities throughout TCling into
a new singleton class Dyld part of the cling's DynamicLibraryManager.

The new dyld is responsible for:
  * Symlink resolution -- it implements a memory efficient representation of
    the full path to shared objects allowing search at constant time O(1). This
    also fixes issues when resolving symbols from OSX where the system libraries
    contain multiple levels of symlinks.
  * Bloom filter optimization -- it uses a stohastic data structure which gives
    a definitive answer if a symbol is not in the set. The implementation checks
    the .gnu.hash section in ELF which is the GNU implementation of a bloom
    filter and uses it. If the symbol is not in the bloom filter, the
    implementation builds its own and uses it. The measured performance of the
    bloom filter is 30% speed up for 2mb more memory. The custom bloom filter on
    top of the .gnu.hash filter gives 1-2% better performance.
    The advantage for the custom bloom filter is that it works on all
    implementations which do not support .gnu.hash (windows and osx). It is also
    customizable if we want to further reduce the false positive rates
    (currently at p=2%).
  * Hash table optimization -- we build a hash table which contains all symbols
    for a given library. This allows us to avoid the fallback symbol iteration
    if multiple symbols from the same library are requested. The hash table
    optimization targets to optimize the case where the bloom filter tells us
    the symbol is *maybe* in the library.

Patch by Alexander Penev and me!
2020-05-06 22:14:06 +02:00
Philippe Canal
6e2db073b7 Compile Interpreter.cpp with exception on. Fix script with exception with ROOT Mutex on.
Compiling Interpreter.cpp allows RunFunction and friends to be actually seen during stack unwind after an
exception has been thrown, directly or indirectly, by interpreter code.  This allows for the RAII objects to be
properly tear down.

In particular, without this patch, EnterUserCodeRAII was not tear down and thus the callbacks were not executed.
Consequently the "Restore the ROOT global Mutex" callback was not executed leaving the Mutex in an invalid state.

In case of ART application, in most cases, they customize the ROOT error handler to throw an exception.  This
resulted (without this fix) in crash when import a GDML file with an error in it.

In practice what we have is:

    call to TGeo Import
       which calls the interpreter for some of its functionality
          which calls gdml code
            which reports an error
               which leads the error handler to thrown an exception.
       ... some of the stack are properly unwound ... some are not (because they were not compiled with exception support on)  ....
       ... so the ROOT Mutex goes into an incorrect state ...
       ... unwinding continues
       ... unwinding reached a frame that Unlock the mutex
         Mutex notices it is an incorrect state.
            so it reports the Error
               the Error handler throw an exception .......

and because this exception is being thrown during the unwind, it is fatal.
2020-01-30 08:59:10 +01:00
Chris Burr
500f426c2f Fix building clingutils tetss with builtin_clang=OFF for conda 2020-01-24 15:44:19 +01:00
Simeon Ehrig
96366346c0 Added DeviceKernelInliner ASTTransformer
This ASTTransformer adds an inline attribute to any CUDA __device__ kernel
that does not have the attribute. Inlining solves a problem caused by
incremental compilation of PTX code. In a normal compiler, all definitions
of __global__ and __device__ kernels are in the same translation unit. In
the incremental compiler, each kernel has its own translation unit. In case
a __global__ kernel uses a __device__ function, this design caused an error.
Instead of generating the PTX code of the __device__ kernel in the same file
as the __global__ kernel, there is only an external declaration of the
__device__ function. However, normal PTX code does not support an external
declaration of functions.

The transformer only works if the target device is nvptx.
2019-11-07 19:29:15 +01:00
Javier Lopez-Gomez
1f3b05bd64 DefinitionShadower: modifications suggested in the PR 2019-09-27 14:59:05 +02:00
Javier Lopez-Gomez
d02353c10b Added new ASTTransformer: DefinitionShadowing. Includes minor changes required to DeclExtractor.
This adds Cling support for function/type/var redefinitions, e.g.
```
int i = 0;
float i = 1.0f;
```
2019-09-27 14:59:04 +02:00
Axel Naumann
5446ed5a48 Allow /clang-7" -cc1 to ge found. 2019-09-10 16:29:09 +02:00
Guilherme Amadio
0d3fb9dbf4 Simplify query for include directories
- Use only sed instead of awk and grep
- Use regex independent of locale settings
2019-08-14 14:59:45 +02:00
Vassil Vassilev
084e96df4c Add a dependency on clangSema to clingInterpreter.
We use the target clingInterpreter in a few places as a
general dependency rule making sure the cling infrastructure is
already built.

In some cases, such as clad, the highly parallel builds trigger
build of clad before clangSema, clangBasic and clangAST are built.

This patch ensures the right dependencies are in order.
2018-10-26 09:44:19 +02:00
Axel Naumann
c23abbc88b Force the OSX SDK to be the one at build time:
Fixes builds with command line tools and macos 10.14.
2018-09-26 20:29:22 +02:00
Simeon Ehrig
6652d1a7c9 Add CUDA device compiler, which allows to generate CUDA PTX Code on runtime.
The class IncrementalCUDADeviceCompiler use external tools to generate PTX and cuda fatbin files. It runs the tools clang and fatbinary via llvm::sys::ExecuteAndWait. The class also handle to include new code in existing code. The steps of the compiler pipeline are:
- clang: CUDA C++ + previous PCH -> PCH
- clang: PCH -> PTX
- fatbinary: PTX -> fatbin

There is no selection of code. Every input of the cling will pass to the  IncrementalCUDADeviceCompiler.
2018-06-25 08:29:07 +02:00
Oksana Shadura
f8b6afcbb0 Fixing linking of Clang libraries for Cling and rootcling_stage1 in case of builtin_clang=OFF 2018-05-02 11:29:42 +02:00
Vassil Vassilev
a53b0325db Complete the list of used libraries.
Fixes -Dbuiltin_clang=Off -Dclingtest=On builds.
2018-04-19 14:29:07 +02:00
Vassil Vassilev
5367e13c15 Restore removed dependency.
For in-tree builds we need Options.inc to be tablegen-ed before
building clingInterpreter library.
2018-04-01 20:44:18 +02:00
Vassil Vassilev
6c74a386ba Enable ROOT to be built with prebuilt clang and llvm.
To do so one needs to pass -Dbuiltin_llvm=Off -Dbuiltin_clang=Off and the
PATH should contain the path to llvm-config.

Note this is not enabling ROOT to work with vanilla clang!

This patch allows ROOT to be built against a prebuilt clang and llvm from
https://root.cern.ch/git/{llvm.git,clang.git}. It allows to reduce ROOT's
build times (in cases when cmake decides to rebuild the in-tree llvm for
no good reason). It moves the common denominator of different ROOT builds
in one place to save space. It also allows easy switch between LLVM in
debug and release mode.

To build the external clang and llvm exactly in the same way as the
in-tree builds use:

CMAKE_FLAGS="\
            -DLLVM_ENABLE_WARNINGS=OFF                   \
            -DLLVM_INCLUDE_TESTS=OFF                     \
            -DCLANG_INCLUDE_TESTS=OFF                    \
            -DLLVM_INCLUDE_EXAMPLES=OFF                  \
            -DCLANG_BUILD_TOOLS=OFF                      \
            -DCLANG_TOOL_ARCMT_TEST_BUILD=OFF            \
            -DCLANG_TOOL_CLANG_CHECK_BUILD=OFF           \
            -DCLANG_TOOL_CLANG_FORMAT_BUILD=OFF          \
            -DCLANG_TOOL_CLANG_FORMAT_VS_BUILD=OFF       \
            -DCLANG_TOOL_CLANG_FUZZER_BUILD=OFF          \
            -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=OFF     \
            -DCLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD=OFF \
            -DCLANG_TOOL_CLANG_RENAME_BUILD=OFF          \
            -DCLANG_TOOL_C_ARCMT_TEST_BUILD=OFF          \
            -DCLANG_TOOL_C_INDEX_TEST_BUILD=OFF          \
            -DCLANG_TOOL_DIAGTOOL_BUILD=OFF              \
            -DCLANG_TOOL_LIBCLANG_BUILD=OFF              \
            -DCLANG_TOOL_SCAN_BUILD_BUILD=OFF            \
            -DCLANG_TOOL_SCAN_VIEW_BUILD=OFF             \
            -DLLVM_BUILD_TOOLS=OFF                       \
            -DLLVM_TOOL_LLVM_AR_BUILD=OFF                \
            -DCLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD=OFF \
            -DLLVM_FORCE_USE_OLD_TOOLCHAIN=ON            \
            -DCLANG_ENABLE_STATIC_ANALYZER=OFF           \
            -DCLANG_ENABLE_ARCMT=OFF                     \
            -DCLANG_ENABLE_FORMAT=OFF                    \
            -DLLVM_TARGETS_TO_BUILD=host                 \
            -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF         \
            -DLLVM_ENABLE_ABI_BREAKING_CHECKS=OFF        \
            -DCMAKE_INSTALL_PREFIX=..                    \
            -DCMAKE_BUILD_TYPE=Debug"

cmake "$CMAKE_FLAGS"   ../../../sources/root-llvm/
2018-03-28 19:29:10 +02:00
Simeon Ehrig
83e3eafc44 fix CMakeFiles to allow cling build with shared libraries 2018-03-22 15:59:06 +01:00
Raphael Isemann
3c745639bb Always generate a ROOT modulemap and install it.
To use C++ modules during runtime we need to generate a modulemap
and install it alongside the ROOT headers. However, right now
we need to turn on cxxmodules to generate a modulemap, which would
force experiments to fulfill all the depndencies that cxxmodules
brings with it (that is, a modern clang that can build ROOT with C++
modules).

This patch untangles the modulemap generation from the cxxmodules
option, so that we always generate a modulemap even when cxxmodules
is turned off. We now also install the modulemap alongside
the ROOT headers.

No functional change for normal ROOT expected here, as the modulemap
will just be ignored without having runtime C++ modules enabled.
2017-06-29 20:51:50 +02:00
Axel Naumann
053223229e Enable all available targets, for instance for the cuda backend. 2017-05-08 14:59:05 +02:00
Raphael Isemann
449c26d5f4 Fixed that we corrupt CLING_CXX_PATH
This will fix the issue that cling will try to invoke "OFF " to find headers.

Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
2017-03-10 16:14:04 +01:00
Raphael Isemann
5f6bbb88e1 Fix ROOT nighly builds failing to configure with CMake
Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
2017-03-06 16:44:48 +01:00
Vassil Vassilev
28380b9f54 Add a fixme. 2017-02-03 14:24:58 +01:00
Vassil Vassilev
1f0cf5c847 Mount a stl modulemap for non libcxx implementations. 2017-02-03 14:24:58 +01:00
Frederich Munch
14437862ef Handle -E flag to dump preprocessor definitions. 2017-02-01 13:14:11 +01:00
Frederich Munch
592e61ba1e Feature to generate precompiled headers. 2017-02-01 13:14:11 +01:00
Frederich Munch
f846990f8d Windows: Fix InterpreterException not being caught and terminating. 2016-12-20 12:59:08 +01:00
Frederich Munch
4d41bd315f Make InterpreterException::diagnose virtual and return a boolean. Refactor inheritance chain for InterpreterException. 2016-12-20 12:59:08 +01:00
Bertrand Bellenot
aa5b7fe2ce Do not force non-unicode. 2016-11-30 10:14:12 +01:00
Axel Naumann
2e7ac15af4 Add missing optimizer libs. 2016-11-15 16:44:32 +01:00
Axel Naumann
87585f78e0 Move -ldl to Utils, now that PlatformXYZ git moved. 2016-11-08 08:44:16 +01:00
Axel Naumann
6cdabe2aa1 Provide directory (and not dir+name) in _path, for $PATH comparison. 2016-11-01 18:23:45 +01:00
Axel Naumann
a3ed23c7ec Revert "Missing realpath on compiler directory; should fix CMS."
This was a red herring.
This reverts commit b33080d18d605ef33013fabc59314729fd48d295.
2016-11-01 18:23:45 +01:00
Axel Naumann
4793a14f07 Missing realpath on compiler directory; should fix CMS.
(cherry picked from commit 812c8b6dab03b66b9b17d0c180f6da15a8810cd0)
2016-11-01 18:23:45 +01:00
Roman Zulak
182954b87f Windows: Match UCRT Version from build environment if possible.
Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
2016-10-18 17:53:22 +02:00
Vassil Vassilev
98c827ebdc Do not resolve the REALPATH too early.
In some ccache setups we have the compiler soft link to ccache.

Eg. /usr/local/bin/g++ -> /usr/local/bin/ccache. If we resolve the link too
early we will take the wrong branch assuming the compiler was set as
CMAKE_CXX_COMPILER="ccache g++" and try to get the second token of the command.
2016-10-18 15:55:55 +02:00
Vassil Vassilev
ae18e8eca6 Allow correct automatic relocatability of cling and ROOT.
Patch by Roman Zulak <machtyrtle@gmail.com>!

Patch tested and requested by Chris Green (ROOT-8379).
2016-10-18 15:55:55 +02:00
Pere Mato
bd5d32f9e5 Fix for ROOT-8392 - CMake missing dependency 2016-10-12 12:59:44 +02:00
Roman Zulak
87fb1cc7f1 CMake: Fix --gcc-toolchain flag not being propagated both at compile and runtime.
This was broken in b8b4bec (ROOT: 965fb30) when support for ccache and distcc was added,
and affected cling being compiled with clang.

Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
2016-08-23 09:14:26 +02:00
Frederich Munch
2142853de6 Don't call clang::ApplyHeaderSearchOptions from Interpreter::AddIncludePaths.
Instead call it at the end of cling::createCI (that should probably change too).

clang::ApplyHeaderSearchOptions is a very heavy-weight function that does a lot
of work to determine and add system headers. More importantly it can also wind
up invalidating clangs internal cache making inclusion of files later impossible.

By using the lighter HeaderSearchOptions::AddSearchPath we not only avoid redoing
a lot of work that has been done, but can adjust the method in clang to avoid
cache invalidation so that calling Interpreter::AddIncludePath will actually
make the files in that path accessible to clang.

Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
2016-08-18 15:44:18 +02:00
Frederich Munch
ea25014f1f Add -DCLING_INCLUDE_PATHS to CMake.
This allows a user to prepend to CLING_INCLUDE_PATHS any additional include paths
they want to add on startup.

Refactor common path splitting code into Utils/Paths

Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
2016-08-18 15:44:18 +02:00
Frederich Munch
b8b4becaf6 Try to make C++ header path determination a bit more robust.
Generate C++ include paths at compile time, fallback to absolute path of compiler cling was built with, and finally relative/PATH invocation.

Previously if cling was built with wrapper to a compiler like ccache, then there was a
good chance the wrapper would be invoked to find C++ headers, meaning it would fail unless the user also had said wrapper.

This commit also:
  Changes LLVM_CXX macro to CLING_CXX_PATH.
  Fixes cling-compiledata.h not being updated after changes to
    cling-compiledata.h.in have occurred.

Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
2016-08-18 15:44:17 +02:00
Bertrand Bellenot
0d24d146df Fix weird compilation errors on Windows (to be reviewed) 2016-07-21 11:44:27 +02:00