Add support and example for dynamically linked function#1005
Add support and example for dynamically linked function#1005pedroerp wants to merge 1 commit intofacebookincubator:mainfrom
Conversation
e13f494 to
b05d1e8
Compare
b05d1e8 to
6640a4f
Compare
|
|
||
| namespace facebook::velox::exec { | ||
|
|
||
| static constexpr const char* kSymbolName = "registry"; |
There was a problem hiding this comment.
I wonder if we should call it something like velox_registry to sort of namespace it ?
| // Try to dynamically load the shared library. | ||
| void* handler = dlopen(fileName, RTLD_NOW); | ||
|
|
||
| if (handler == nullptr) { |
There was a problem hiding this comment.
nit: just use VELOX_USER_CHECK(handler, "Error...").
| # Here's the actual test which will dynamically load the library defined above. | ||
| add_executable(velox_function_dynamic_link_test DynamicLinkTest.cpp) | ||
|
|
||
| add_test(NAME velox_function_dynamic_link_test |
|
|
||
| void loadDynamicLibraryFunctions(const char* fileName) { | ||
| // Try to dynamically load the shared library. | ||
| void* handler = dlopen(fileName, RTLD_NOW); |
There was a problem hiding this comment.
noob question: what will happen if multiple .so is loaded ? (will there be multiple "registry" symbol ?)
There was a problem hiding this comment.
I thought the registry name is loaded from file passed so it shouldnt matter if multiple .so are loaded as long as they have different paths. Collision between functions during registrations though can happen.
There was a problem hiding this comment.
From https://pubs.opengroup.org/onlinepubs/7908799/xsh/dlopen.html, it says
With the exception of the global symbol object obtained via a dlopen() operation on a file of 0, dependency ordering is used by the dlsym() function. Load ordering is used in dlsym() operations upon the global symbol object.
Since we didn't use RTLD_GLOBAL, it should use dependency ordering:
Dependency ordering uses a breadth-first order starting with a given object, then all of its dependencies, then any dependents of those, iterating until all dependencies are satisfied.
which should work since it searches first in the handler .
There was a problem hiding this comment.
Thanks Wenlei. I can also forsee another problem where say if a .so depends on another .so which has a registry function in that case behavior can be undefined.
|
Thanks @pedroerp for adding this. shall we move DynamicLibraryLoader from expression to exec/dynamic_loader? A couple of note for the extension of this work:
The interface might have things that might not be needed such as
But those enforcement can be skipped by using the unchecked interface of the loader. The interface provides several other functionalities such:
|
|
Closing stale PRs. Please, reopen if you'd like to continue working on this PR. |
Adding a
DynamicLibraryLoader.hheader to help loading and registering functions defined in dynamically loaded library. Also adding a unit test containing an example of a function dynamically linked and registered. Apart from complications related to .so built with different toolsets, this provides the base functionality that works for consistent platforms.