File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
onnxruntime/core/platform/posix Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ limitations under the License.
2626#include < stdlib.h>
2727#include < string.h>
2828#include < sys/mman.h>
29+ #include < filesystem>
2930#if !defined(_AIX)
3031#include < sys/syscall.h>
3132#endif
@@ -592,6 +593,26 @@ class PosixEnv : public Env {
592593 return val == NULL ? std::string () : std::string (val);
593594 }
594595
596+ // Return the path of the executable/shared library for the current running code. This is to make it
597+ // possible to load other shared libraries installed next to our core runtime code.
598+ PathString GetRuntimePath () const override {
599+ Dl_info dl_info{};
600+ // Must be one of the symbols exported in libonnxruntime.{so,dynlib}.
601+ void * symbol_from_this_library = dlsym (RTLD_DEFAULT, " OrtGetApiBase" );
602+ // We will find OrtGetApiBase if onnxruntime is loaded as a shared library
603+ if (dladdr (symbol_from_this_library, &dl_info) && dl_info.dli_fname ) {
604+ return PathString (std::filesystem::path (dl_info.dli_fname ).parent_path ().string ()) + " /" ;
605+ } else {
606+ // else use path of current executable to mirror Windows behavior
607+ #if __linux__
608+ return PathString (std::filesystem::read_symlink (std::filesystem::path (" /proc/self/exe" )).parent_path ()) + " /" ;
609+ #else
610+ // TODO: MacOS could use _NSGetExecutablePath, but this needs to be tested!
611+ return PathString ();
612+ #endif
613+ }
614+ }
615+
595616 private:
596617 Telemetry telemetry_provider_;
597618#ifdef ORT_USE_CPUINFO
You can’t perform that action at this time.
0 commit comments