-
Notifications
You must be signed in to change notification settings - Fork 11
Add platform specific dynamic library loading #119
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
base: main
Are you sure you want to change the base?
Conversation
| // Use dlmopen with LM_ID_NEWLM to load in a new namespace for isolation. | ||
| handle_ = dlmopen(LM_ID_NEWLM, path.c_str(), RTLD_LAZY | RTLD_LOCAL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it intentional to not check if the library is already loaded and reuse if so? The previous code was doing that (RTLD_NOLOAD) but the new code always creates a new namespace via LM_ID_NEWLM. Just checking because this could lead to duplicate copies of the library in different namespaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the idea I had was to support reloading the same library multiple times. It avoids having to manage separately loaded version (e.g. something load the libIreeCompiler.so for its own implementation now having duplicate ownership). One of the problems with core dlopen is that if another took uses the library it could get into an illegal state (because of self counting destroy).
| #include <span> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR but we should include <cstdint> for the uint8_t type used below. I wonder why clang-tidy didn't catch this before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clang just auto includes core libraries a lot of the time. Not really sure why they chose to do that but they did ¯_(ツ)_/¯
Windows differs from Linux in how it loads from dynamic libraries. Adding a support shim to select between platforms allows the libraries to be loaded platform independently.