Skip to content

Commit aa9b3b3

Browse files
authored
Merge pull request #816 from pbalcer/optional-deep-bind
[loader] make RTLD_DEEPBIND optional when loading adapters
2 parents cc12f71 + 6e827f3 commit aa9b3b3

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

scripts/core/INTRO.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,15 @@ Specific environment variables can be set to control the behavior of unified run
296296

297297
This environment variable is ignored when :envvar:`UR_ADAPTERS_FORCE_LOAD` environment variable is used.
298298

299+
.. envvar:: UR_ADAPTERS_DEEP_BIND
300+
301+
If set, the loader will use `RTLD_DEEPBIND` when opening adapter libraries. This might be useful if an adapter
302+
requires a different version of a shared library compared to the rest of the applcation.
303+
304+
.. note::
305+
306+
This environment variable is Linux-only.
307+
299308
.. envvar:: UR_ENABLE_LAYERS
300309

301310
Holds a comma-separated list of layers to enable in addition to any specified via ``urInit``.

source/common/linux/ur_lib_loader.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
#include "logger/ur_logger.hpp"
1313
#include "ur_lib_loader.hpp"
1414

15-
#if defined(SANITIZER_ANY) || defined(__APPLE__)
16-
#define LOAD_DRIVER_LIBRARY(NAME) dlopen(NAME, RTLD_LAZY | RTLD_LOCAL)
17-
#else
18-
#define LOAD_DRIVER_LIBRARY(NAME) \
19-
dlopen(NAME, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND)
20-
#endif
15+
#define DEEP_BIND_ENV "UR_ADAPTERS_DEEP_BIND"
2116

2217
namespace ur_loader {
2318

@@ -34,8 +29,21 @@ void LibLoader::freeAdapterLibrary(HMODULE handle) {
3429

3530
std::unique_ptr<HMODULE, LibLoader::lib_dtor>
3631
LibLoader::loadAdapterLibrary(const char *name) {
37-
return std::unique_ptr<HMODULE, LibLoader::lib_dtor>(
38-
LOAD_DRIVER_LIBRARY(name));
32+
int mode = RTLD_LAZY | RTLD_LOCAL;
33+
#if !defined(__APPLE__)
34+
bool deepbind = getenv_tobool(DEEP_BIND_ENV);
35+
if (deepbind) {
36+
#if defined(SANITIZER_ANY)
37+
logger::warning(
38+
"Enabling RTLD_DEEPBIND while running under a sanitizer is likely "
39+
"to cause issues. Consider disabling {} environment variable.",
40+
DEEP_BIND_ENV);
41+
#endif
42+
mode |= RTLD_DEEPBIND;
43+
}
44+
#endif
45+
46+
return std::unique_ptr<HMODULE, LibLoader::lib_dtor>(dlopen(name, mode));
3947
}
4048

4149
void *LibLoader::getFunctionPtr(HMODULE handle, const char *func_name) {

0 commit comments

Comments
 (0)