Skip to content

Commit 26b4f5d

Browse files
authored
Don't log an error when there are no CUDA backend symbols to promote (#23895)
### Summary `load_library` re-opens the library that holds the CUDA backend with `RTLD_NOLOAD | RTLD_GLOBAL` to make its symbols global. When the backend is linked into the executable, as in a statically linked runner, `dladdr` names the executable, and `dlopen` finds no library to re-open and sets no error. So every first load logged "Failed to promote symbols: (null)", although the executable's symbols are already global and there is nothing to promote. The error is now logged only when `dlopen` reports one; `dlerror()` is cleared before the call so a stale error is not reported. This PR was authored with AI (Claude Code). ### Test plan `backends/cuda/runtime/platform/platform.cpp` compiles (`g++ -std=c++17 -fsyntax-only -Wall -Wextra`). The `dlopen` behavior the change relies on, checked with a small program that calls `dlopen(<its own path>, RTLD_NOW | RTLD_GLOBAL | RTLD_NOLOAD)` on glibc 2.39 (Jetson AGX Thor, Ubuntu 24.04): ``` dli_fname=./noload handle=(nil) dlerror=(null) ``` cc @cccclai @nil-is-all @Gasoonjia @digantdesai
1 parent b086d44 commit 26b4f5d

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎backends/cuda/runtime/platform/platform.cpp‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,24 @@ executorch::runtime::Result<void*> load_library(
8686
Dl_info info;
8787
// Get info about a symbol we know exists in this backend library
8888
if (dladdr((void*)&load_library, &info) && info.dli_fname) {
89-
// Re-open with RTLD_GLOBAL | RTLD_NOLOAD to promote symbols
89+
// Re-open with RTLD_GLOBAL | RTLD_NOLOAD to promote symbols. Clear any
90+
// earlier error first, so dlerror() below reports only this call's.
91+
dlerror();
9092
void* handle =
9193
dlopen(info.dli_fname, RTLD_NOW | RTLD_GLOBAL | RTLD_NOLOAD);
9294
if (!handle) {
93-
ET_LOG(Error, "Failed to promote symbols: %s", dlerror());
95+
const char* error = dlerror();
96+
if (error != nullptr) {
97+
ET_LOG(Error, "Failed to promote symbols: %s", error);
98+
} else {
99+
// dlopen found no library to re-open and set no error. That is the
100+
// case when this backend is linked into the executable, whose
101+
// symbols are global already.
102+
ET_LOG(
103+
Debug,
104+
"Not promoting symbols: %s is not loaded as a shared library",
105+
info.dli_fname);
106+
}
94107
} else {
95108
// Close the handle after successful promotion
96109
dlclose(handle);

0 commit comments

Comments
 (0)