Skip to content

Commit

Permalink
[cling] Handle the case if the plugin is passed as a shared object.
Browse files Browse the repository at this point in the history
When cling is embedded and the plugins are linked statically we can rely
on the initialization of the Preprocessor to register the pragmas.

Currently, due to the current implementation deficiency we cannot rely
on the same mechanism when loading the plugins as shared objects.

This patch fixes the failing cling test.
vgvassilev committed Nov 19, 2018

Verified

This commit was signed with the committer’s verified signature.
fiji-flo Florian Dieminger
1 parent 9451eec commit 3e1aa3a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion interpreter/cling/lib/Interpreter/IncrementalParser.cpp
Original file line number Diff line number Diff line change
@@ -193,12 +193,25 @@ static void HandlePlugins(CompilerInstance& CI,
// plugins if cling is in a single shared library which is dlopen-ed with
// RTLD_LOCAL. In that situation plugins can still find the cling, clang and
// llvm symbols opened with local visibility.
if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end()) {
for (const std::string& Path : CI.getFrontendOpts().Plugins) {
std::string Err;
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Err))
CI.getDiagnostics().Report(clang::diag::err_fe_unable_to_load_plugin)
<< Path << Err;
}
// If we are not statically linked, we should register the pragmas ourselves
// because the dlopen happens after creating the clang::Preprocessor which
// calls RegisterBuiltinPragmas.
// FIXME: This can be avoided by refactoring our routine and moving it to
// the CIFactory. This requires an abstraction which allows us to
// conditionally create MultiplexingConsumers.

// Copied from Lex/Pragma.cpp
// Pragmas added by plugins
for (PragmaHandlerRegistry::iterator it = PragmaHandlerRegistry::begin(),
ie = PragmaHandlerRegistry::end(); it != ie; ++it)
CI.getPreprocessor().AddPragmaHandler(it->instantiate().release());
}

for (auto it = clang::FrontendPluginRegistry::begin(),

0 comments on commit 3e1aa3a

Please sign in to comment.