Skip to content

Commit

Permalink
[Hexagon] Make local symbols visible to loaded modules in RPC server (#…
Browse files Browse the repository at this point in the history
…11611)

The simulator library `libhexagon_rpc_sim.so` contains TVM runtime built
into it, but since it's loaded as a "local" library these symbols are not
visible to shared libraries loaded by subsequent dlopens. (Same applies to
symbols from the C++ runtime.)

To make these symbols visible, dlopen the defining libraries as "global".
(Re-dlopeninig an already loaded library is a well-defined operation.)
  • Loading branch information
Krzysztof Parzyszek authored Jun 8, 2022
1 parent 6dc0c62 commit b00b122
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/runtime/hexagon/rpc/simulator/rpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <HAP_farf.h>
#include <dlfcn.h>

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -288,7 +289,16 @@ int DISPATCH_FUNCTION_NAME(void* serverp) {
return 0;
}

int main() {
int main(int argc, char* argv[]) {
// Load C++RT and ourselves as "global" to make all the symbols defined
// there be visible to any subsequent libraries loaded via dlopen.
void* cxx_abi = dlopen("libc++abi.so", RTLD_GLOBAL);
ICHECK(cxx_abi != nullptr);
void* cxx = dlopen("libc++.so", RTLD_GLOBAL);
ICHECK(cxx != nullptr);
void* self = dlopen(argv[0], RTLD_GLOBAL);
ICHECK(self != nullptr);

const auto* api = tvm::runtime::Registry::Get("device_api.hexagon");
ICHECK(api != nullptr);
tvm::runtime::Registry::Register("device_api.cpu", true).set_body(*api);
Expand All @@ -308,6 +318,9 @@ int main() {
// nothing
}

dlclose(self);
dlclose(cxx);
dlclose(cxx_abi);
return 0;
}

Expand Down

0 comments on commit b00b122

Please sign in to comment.