Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library autoloader #308

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

alexander-penev
Copy link
Collaborator

No description provided.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 12. Check the log or trigger a new build to see more.

lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 82.75862% with 15 lines in your changes missing coverage. Please review.

Project coverage is 74.30%. Comparing base (e0fa91e) to head (6cfe873).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #308      +/-   ##
==========================================
+ Coverage   72.22%   74.30%   +2.07%     
==========================================
  Files           8        8              
  Lines        2963     3043      +80     
==========================================
+ Hits         2140     2261     +121     
+ Misses        823      782      -41     
Files Coverage Δ
include/clang/Interpreter/CppInterOp.h 96.00% <ø> (ø)
lib/Interpreter/DynamicLibraryManagerSymbol.cpp 74.56% <ø> (+6.91%) ⬆️
lib/Interpreter/DynamicLibraryManager.cpp 77.77% <60.00%> (+5.40%) ⬆️
lib/Interpreter/CppInterOp.cpp 78.79% <84.14%> (+0.26%) ⬆️

... and 2 files with indirect coverage changes

Files Coverage Δ
include/clang/Interpreter/CppInterOp.h 96.00% <ø> (ø)
lib/Interpreter/DynamicLibraryManagerSymbol.cpp 74.56% <ø> (+6.91%) ⬆️
lib/Interpreter/DynamicLibraryManager.cpp 77.77% <60.00%> (+5.40%) ⬆️
lib/Interpreter/CppInterOp.cpp 78.79% <84.14%> (+0.26%) ⬆️

... and 2 files with indirect coverage changes

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/DynamicLibraryManager.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 14. Check the log or trigger a new build to see more.

lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
unittests/CppInterOp/DynamicLibraryManagerTest.cpp Outdated Show resolved Hide resolved
unittests/CppInterOp/DynamicLibraryManagerTest.cpp Outdated Show resolved Hide resolved
include/clang/Interpreter/CppInterOp.h Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/DynamicLibraryManagerSymbol.cpp Outdated Show resolved Hide resolved
unittests/CppInterOp/CMakeLists.txt Show resolved Hide resolved
unittests/CppInterOp/DynamicLibraryManagerTest.cpp Outdated Show resolved Hide resolved
unittests/CppInterOp/TestSharedLib1/CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

unittests/CppInterOp/DynamicLibraryManagerTest.cpp Outdated Show resolved Hide resolved
unittests/CppInterOp/DynamicLibraryManagerTest.cpp Outdated Show resolved Hide resolved
unittests/CppInterOp/DynamicLibraryManagerTest.cpp Outdated Show resolved Hide resolved
unittests/CppInterOp/DynamicLibraryManagerTest.cpp Outdated Show resolved Hide resolved
unittests/CppInterOp/TestSharedLib3/TestSharedLib3.h Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 18. Check the log or trigger a new build to see more.

lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Outdated Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
@lhames
Copy link

lhames commented Aug 2, 2024

A couple of quick thoughts for future upstreaming: we'd want to make this compatible with out-of-process execution, and it'd be great if we could re-use parts of it for MachO auto-linking.

We should consider whether SimpleExecutorDylibManager can be extended to handle all this.

@vgvassilev
Copy link
Contributor

A couple of quick thoughts for future upstreaming: we'd want to make this compatible with out-of-process execution, and it'd be great if we could re-use parts of it for MachO auto-linking.

Thanks for the feedback, @lhames. That makes sense.

We should consider whether SimpleExecutorDylibManager can be extended to handle all this.

I was not aware such a thing existed. @SahilPatidar perhaps that's interesting in terms of your project, too.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
lib/Interpreter/CppInterOp.cpp Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

}

void setEnabled(bool enabled) {
Enabled = enabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'isEnabled' can be made const [readability-make-member-function-const]

Suggested change
Enabled = enabled;
bool isEnabled() const {

}

void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
if (!sAutoSG || !sAutoSG->isEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'getName' should be marked [[nodiscard]] [modernize-use-nodiscard]

Suggested change
if (!sAutoSG || !sAutoSG->isEnabled()) {
[[nodiscard]] StringRef getName() const override {

@vgvassilev
Copy link
Contributor

@aaronj0, do you have a clue why cppyy fails?

@aaronj0
Copy link
Collaborator

aaronj0 commented Sep 20, 2024

@aaronj0, do you have a clue why cppyy fails?

cppyy does not fail, InterOp does not build on any of the jobs. This comes back to the point that CppInterOp is only built on the jobs tagged with "cppyy" not the first stage that only builds llvm.

On a preliminary look, it seems like on llvm19 we get:

error: no matching function for call to ‘llvm::orc::MaterializationResponsibility::notifyEmitted()’
 3470 |           llvm::cantFail(R->notifyEmitted());

and on 18 and 17, these "undefined reference to typeinfo for llvm::orc::DefinitionGenerator"

They also fail in some of the emscripten builds but I am more interested in the fact that they pass on llvm 17 and 18 with clang-repl on all platforms

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 21. Check the log or trigger a new build to see more.

class AutoLoadLibrarySearchGenerator : public llvm::orc::DefinitionGenerator {
bool Enabled = false;
public:
bool isEnabled() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'isEnabled' can be made const [readability-make-member-function-const]

Suggested change
bool isEnabled() {
bool isEnabled() const {

AutoloadLibraryMU(std::string Library, const llvm::orc::SymbolNameVector &Symbols)
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), lib(std::move(Library)), syms(Symbols) {}

StringRef getName() const override {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'getName' should be marked [[nodiscard]] [modernize-use-nodiscard]

Suggested change
StringRef getName() const override {
[[nodiscard]] StringRef getName() const override {

}

void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
if (!sAutoSG || !sAutoSG->isEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'sAutoSG' [clang-diagnostic-error]

        if (!sAutoSG || !sAutoSG->isEnabled()) {
                         ^

}

void materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
if (!sAutoSG || !sAutoSG->isEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'sAutoSG' [clang-diagnostic-error]

        if (!sAutoSG || !sAutoSG->isEnabled()) {
             ^

}

if (!loadedSymbols.empty()) {
llvm::cantFail(R->notifyResolved(loadedSymbols));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "llvm::cantFail" is directly included [misc-include-cleaner]

          llvm::cantFail(R->notifyResolved(loadedSymbols));
                ^

auto& I = getInterp();
auto *DLM = I.getDynamicLibraryManager();

std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::unordered_map" is directly included [misc-include-cleaner]

lib/Interpreter/CppInterOp.cpp:26:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <unordered_map>
+ #if CLANG_VERSION_MAJOR >= 19

}

for (auto &&KV : found) {
auto MU = std::make_unique<AutoloadLibraryMU>(KV.first, std::move(KV.second));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::make_unique" is directly included [misc-include-cleaner]

	auto MU = std::make_unique<AutoloadLibraryMU>(KV.first, std::move(KV.second));
                ^

llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib().get();
#endif // CLANG_VERSION_MAJOR

if (!sAutoSG) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'sAutoSG' [clang-diagnostic-error]

    if (!sAutoSG) {
         ^

#endif // CLANG_VERSION_MAJOR

if (!sAutoSG) {
sAutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'sAutoSG' [clang-diagnostic-error]

      sAutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
      ^

if (!sAutoSG) {
sAutoSG = &DyLib.addGenerator(std::make_unique<AutoLoadLibrarySearchGenerator>());
}
sAutoSG->setEnabled(autoload);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'sAutoSG' [clang-diagnostic-error]

    sAutoSG->setEnabled(autoload);
    ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 11. Check the log or trigger a new build to see more.


bool GetLibrariesAutoload() {
LLVM_DEBUG(dbgs() << "Autoload is " << (sAutoSG && sAutoSG->isEnabled() ? "ON" : "OFF"));
return sAutoSG && sAutoSG->isEnabled();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'sAutoSG' [clang-diagnostic-error]

    return sAutoSG && sAutoSG->isEnabled();
                      ^


bool GetLibrariesAutoload() {
LLVM_DEBUG(dbgs() << "Autoload is " << (sAutoSG && sAutoSG->isEnabled() ? "ON" : "OFF"));
return sAutoSG && sAutoSG->isEnabled();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'sAutoSG' [clang-diagnostic-error]

    return sAutoSG && sAutoSG->isEnabled();
           ^

@@ -2,55 +2,175 @@

#include "clang/Interpreter/CppInterOp.h"


#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header Core.h is not used directly [misc-include-cleaner]

Suggested change
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"

@@ -2,55 +2,175 @@

#include "clang/Interpreter/CppInterOp.h"


#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "llvm/Support/FileSystem.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header DebugUtils.h is not used directly [misc-include-cleaner]

Suggested change
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileSystem.h"


// This function isn't referenced outside its translation unit, but it
// can't use the "static" keyword because its address is used for
// GetMainExecutable (since some platforms don't support taking the
// address of main, and some platforms can't implement GetMainExecutable
// without being given the address of a function in the main executable).
std::string GetExecutablePath(const char* Argv0) {
std::string GetExecutablePath(const char* Argv0, void* mainAddr = nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::string" is directly included [misc-include-cleaner]

unittests/CppInterOp/DynamicLibraryManagerTest.cpp:10:

+ #include <string>

// This just needs to be some symbol in the binary; C++ doesn't
// allow taking the address of ::main however.
void* MainAddr = (void*)intptr_t(GetExecutablePath);
void* MainAddr = mainAddr ? mainAddr : (void*)intptr_t(GetExecutablePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

  void* MainAddr = mainAddr ? mainAddr : (void*)intptr_t(GetExecutablePath);
                                         ^

// This just needs to be some symbol in the binary; C++ doesn't
// allow taking the address of ::main however.
void* MainAddr = (void*)intptr_t(GetExecutablePath);
void* MainAddr = mainAddr ? mainAddr : (void*)intptr_t(GetExecutablePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]

  void* MainAddr = mainAddr ? mainAddr : (void*)intptr_t(GetExecutablePath);
                                         ^

// This just needs to be some symbol in the binary; C++ doesn't
// allow taking the address of ::main however.
void* MainAddr = (void*)intptr_t(GetExecutablePath);
void* MainAddr = mainAddr ? mainAddr : (void*)intptr_t(GetExecutablePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "intptr_t" is directly included [misc-include-cleaner]

unittests/CppInterOp/DynamicLibraryManagerTest.cpp:10:

+ #include <cstdint>

return nameForDlsym;
}

#include "../../lib/Interpreter/CppInterOp.cpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: suspicious #include of file with '.cpp' extension [bugprone-suspicious-include]

#include "../../lib/Interpreter/CppInterOp.cpp"
          ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 12. Check the log or trigger a new build to see more.

// Last assigned Autoload SearchGenerator
// TODO: Test fot thread safe.
class AutoLoadLibrarySearchGenerator;
static AutoLoadLibrarySearchGenerator *sAutoSG = null;
// Flag to indicate ownership when an external interpreter instance is used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'null' [clang-diagnostic-error]

  static AutoLoadLibrarySearchGenerator *sAutoSG = null;
                                                   ^

@@ -3435,4 +3440,188 @@
complete_column);
}

#define DEBUG_TYPE "autoload"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

      std::unique_ptr<char[]> content(new char[bufsize + 1]);
                      ^

@@ -3435,4 +3440,188 @@
complete_column);
}

#define DEBUG_TYPE "autoload"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::unique_ptr" is directly included [misc-include-cleaner]

      std::unique_ptr<char[]> content(new char[bufsize + 1]);
           ^

#define DEBUG_TYPE "autoload"

static inline std::string DemangleNameForDlsym(const std::string& name) {
std::string nameForDlsym = name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "SEEK_SET" is directly included [misc-include-cleaner]

      if (fseek(m_TempFile.get(), 0L, SEEK_SET) != 0)
                                      ^

static bool is_demangle_active = false;
static bool demangle = false;
if (!is_demangle_active) {
auto& I = getInterp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "fread" is directly included [misc-include-cleaner]

          fread(content.get(), sizeof(char), bufsize, m_TempFile.get());
          ^

static bool demangle = false;
if (!is_demangle_active) {
auto& I = getInterp();
llvm::orc::LLJIT& EE = *compat::getExecutionEngine(I);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "ferror" is directly included [misc-include-cleaner]

      if (ferror(m_TempFile.get()) != 0)
          ^

if (!is_demangle_active) {
auto& I = getInterp();
llvm::orc::LLJIT& EE = *compat::getExecutionEngine(I);
auto t = EE.getTargetTriple();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "fputs" is directly included [misc-include-cleaner]

        fputs("Error reading file", stderr);
        ^

if (!addr && !loadedLibrary) {
// Try to load the library which should provide the symbol definition.
if (DLM->loadLibrary(lib, false) != DynamicLibraryManager::LoadLibResult::kLoadLibSuccess) {
LLVM_DEBUG(dbgs() << "MU: Failed to load library " << lib);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'isEnabled' can be made const [readability-make-member-function-const]

Suggested change
LLVM_DEBUG(dbgs() << "MU: Failed to load library " << lib);
bool isEnabled() const {

if (addr) {
loadedSymbols[symbol] =
llvm::orc::ExecutorSymbolDef(llvm::orc::ExecutorAddr::fromPtr(addr), JITSymbolFlags::Exported);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'getName' should be marked [[nodiscard]] [modernize-use-nodiscard]

Suggested change
} else {
[[nodiscard]] StringRef getName() const override {

//I.getAddressOfGlobal(*Name);
}

for (auto &&KV : found) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "llvm::cantFail" is directly included [misc-include-cleaner]

          llvm::cantFail(R->notifyResolved(loadedSymbols));
                ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

static bool is_demangle_active = false;
static bool demangle = false;
if (!is_demangle_active) {
auto& I = getInterp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: The 1st argument to 'fread' is a buffer with size 0 but should be a buffer with size equal to or greater than the value of the 2nd argument (which is 1) times the 3rd argument (which is 18446744073709551615) [clang-analyzer-unix.StdCLibraryFunctions]

          fread(content.get(), sizeof(char), bufsize, m_TempFile.get());
          ^
Additional context

lib/Interpreter/CppInterOp.cpp:3475: Calling 'StreamCaptureInfo::GetCapturedString'

    std::string result = SCI.GetCapturedString();
                         ^

lib/Interpreter/CppInterOp.cpp:3430: Assuming the condition is false

      if (dup2(m_DupFD, m_FD) < 0)
          ^

lib/Interpreter/CppInterOp.cpp:3430: Taking false branch

      if (dup2(m_DupFD, m_FD) < 0)
      ^

lib/Interpreter/CppInterOp.cpp:3433: Assuming the condition is false

      if (fseek(m_TempFile.get(), 0L, SEEK_END) != 0)
          ^

lib/Interpreter/CppInterOp.cpp:3433: Taking false branch

      if (fseek(m_TempFile.get(), 0L, SEEK_END) != 0)
      ^

lib/Interpreter/CppInterOp.cpp:3437: 'bufsize' initialized here

      long bufsize = ftell(m_TempFile.get());
      ^

lib/Interpreter/CppInterOp.cpp:3438: Assuming the condition is true

      if (bufsize == -1)
          ^

lib/Interpreter/CppInterOp.cpp:3438: Taking true branch

      if (bufsize == -1)
      ^

lib/Interpreter/CppInterOp.cpp:3442: Storing uninitialized value

      std::unique_ptr<char[]> content(new char[bufsize + 1]);
                                      ^

lib/Interpreter/CppInterOp.cpp:3442: Passing value via 1st parameter '__p'

      std::unique_ptr<char[]> content(new char[bufsize + 1]);
                                      ^

lib/Interpreter/CppInterOp.cpp:3442: Calling constructor for 'unique_ptr<char[], std::default_delete<char[]>>'

      std::unique_ptr<char[]> content(new char[bufsize + 1]);
                              ^

/usr/include/c++/13/bits/unique_ptr.h:603: Calling constructor for '__uniq_ptr_data<char, std::default_delete<char[]>, true, true>'

	: _M_t(__p)
   ^

/usr/include/c++/13/bits/unique_ptr.h:603: Passing '' via 1st parameter '__p'

	: _M_t(__p)
        ^

/usr/include/c++/13/bits/unique_ptr.h:603: Calling constructor for '__uniq_ptr_impl<char, std::default_delete<char[]>>'

	: _M_t(__p)
   ^

/usr/include/c++/13/bits/unique_ptr.h:175: Calling '__uniq_ptr_impl::_M_ptr'

      __uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; }
                                              ^

/usr/include/c++/13/bits/unique_ptr.h:196: Calling 'get<0UL, char *, std::default_delete<char[]>>'

      pointer&   _M_ptr() noexcept { return std::get<0>(_M_t); }
                                            ^

/usr/include/c++/13/tuple:1803: Calling '__get_helper<0UL, char *, std::default_delete<char[]>>'

    { return std::__get_helper<__i>(__t); }
             ^

/usr/include/c++/13/tuple:1787: Calling '_Tuple_impl::_M_head'

    { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
             ^

/usr/include/c++/13/tuple:268: Calling '_Head_base::_M_head'

      _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
                                                  ^

/usr/include/c++/13/tuple:268: Returning from '_Head_base::_M_head'

      _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
                                                  ^

/usr/include/c++/13/tuple:1787: Returning from '_Tuple_impl::_M_head'

    { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
             ^

/usr/include/c++/13/tuple:1803: Returning from '__get_helper<0UL, char *, std::default_delete<char[]>>'

    { return std::__get_helper<__i>(__t); }
             ^

/usr/include/c++/13/bits/unique_ptr.h:196: Returning from 'get<0UL, char *, std::default_delete<char[]>>'

      pointer&   _M_ptr() noexcept { return std::get<0>(_M_t); }
                                            ^

/usr/include/c++/13/bits/unique_ptr.h:175: Returning from '__uniq_ptr_impl::_M_ptr'

      __uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; }
                                              ^

/usr/include/c++/13/bits/unique_ptr.h:175: The value of '__p' is assigned to 'content._M_t._M_t._M_head_impl'

      __uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; }
                                              ^

/usr/include/c++/13/bits/unique_ptr.h:603: Returning from constructor for '__uniq_ptr_impl<char, std::default_delete<char[]>>'

	: _M_t(__p)
   ^

/usr/include/c++/13/bits/unique_ptr.h:603: Returning from constructor for '__uniq_ptr_data<char, std::default_delete<char[]>, true, true>'

	: _M_t(__p)
   ^

lib/Interpreter/CppInterOp.cpp:3442: Returning from constructor for 'unique_ptr<char[], std::default_delete<char[]>>'

      std::unique_ptr<char[]> content(new char[bufsize + 1]);
                              ^

lib/Interpreter/CppInterOp.cpp:3445: Assuming the condition is false

      if (fseek(m_TempFile.get(), 0L, SEEK_SET) != 0)
          ^

lib/Interpreter/CppInterOp.cpp:3445: Taking false branch

      if (fseek(m_TempFile.get(), 0L, SEEK_SET) != 0)
      ^

lib/Interpreter/CppInterOp.cpp:3450: The 1st argument to 'fread' is a buffer with size 0 but should be a buffer with size equal to or greater than the value of the 2nd argument (which is 1) times the 3rd argument (which is 18446744073709551615)

          fread(content.get(), sizeof(char), bufsize, m_TempFile.get());
          ^

}
sAutoSG->setEnabled(autoload);

LLVM_DEBUG(dbgs() << "Autoload=" << (sAutoSG->isEnabled() ? "ON" : "OFF"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::unordered_map" is directly included [misc-include-cleaner]

lib/Interpreter/CppInterOp.cpp:26:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <unordered_map>
+ #if CLANG_VERSION_MAJOR >= 19

@@ -0,0 +1,13 @@
#ifndef UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB2_H
#define UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB2_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: header guard does not follow preferred style [llvm-header-guard]

Suggested change
#define UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB2_H
#ifndef GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB2_TESTSHAREDLIB2_H
#define GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB2_TESTSHAREDLIB2_H

unittests/CppInterOp/TestSharedLib2/TestSharedLib2.h:12:

- #endif // UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB2_H
+ #endif // GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB2_TESTSHAREDLIB2_H

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

// Last assigned Autoload SearchGenerator
// TODO: Test fot thread safe.
class AutoLoadLibrarySearchGenerator;
static AutoLoadLibrarySearchGenerator *sAutoSG = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'sAutoSG' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

  static AutoLoadLibrarySearchGenerator *sAutoSG = nullptr;
                                         ^

// Last assigned Autoload SearchGenerator
// TODO: Test fot thread safe.
class AutoLoadLibrarySearchGenerator;
static AutoLoadLibrarySearchGenerator *sAutoSG = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'sAutoSG' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]

  static AutoLoadLibrarySearchGenerator *sAutoSG = nullptr;
                                         ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

if (!loadedSymbols.empty()) {
llvm::cantFail(R->notifyResolved(loadedSymbols));

llvm::orc::SymbolDependenceGroup DepGroup;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no type named 'SymbolDependenceGroup' in namespace 'llvm::orc'; did you mean 'SymbolDependenceMap'? [clang-diagnostic-error]

Suggested change
llvm::orc::SymbolDependenceGroup DepGroup;
llvm::orc::SymbolDependenceMap DepGroup;
Additional context

llvm/include/llvm/ExecutionEngine/Orc/Core.h:125: 'SymbolDependenceMap' declared here

using SymbolDependenceMap = DenseMap<JITDylib *, SymbolNameSet>;
      ^

llvm::cantFail(R->notifyResolved(loadedSymbols));

llvm::orc::SymbolDependenceGroup DepGroup;
llvm::cantFail(R->notifyEmitted({DepGroup}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: too many arguments to function call, expected 0, have 1 [clang-diagnostic-error]

          llvm::cantFail(R->notifyEmitted({DepGroup}));
                                          ^
Additional context

llvm/include/llvm/ExecutionEngine/Orc/Core.h:1932: 'notifyEmitted' declared here

inline Error MaterializationResponsibility::notifyEmitted() {
                                            ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Debug.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: #includes are not sorted properly [llvm-include-order]

Suggested change
#include "llvm/Support/Debug.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"

@anutosh491
Copy link
Collaborator

Hey @alexander-penev

What is the progress on this ?

I haven't had the time to looking into the library loading feature yet but we would need this for xeus-cpp-lite and xeus-cpp I suppose. My understanding was that this would supersede the Loading shared objects feature we could achieve with cling's pragma.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

llvm::orc::SymbolNameVector fSymbols;
public:
AutoloadLibraryMU(const std::string &Library, const llvm::orc::SymbolNameVector &Symbols)
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), fLibrary(Library), fSymbols(Symbols) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: pass by value and use std::move [modernize-pass-by-value]

Suggested change
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), fLibrary(Library), fSymbols(Symbols) {}
AutoloadLibraryMU(std::string Library, const llvm::orc::SymbolNameVector &Symbols)
: MaterializationUnit({getSymbolFlagsMap(Symbols), nullptr}), fLibrary(std::move(Library)), fSymbols(Symbols) {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants