[Openmp-commits] [openmp] [OpenMP] Improve dladdr error handling in ompd_init() (PR #201043)
Mark Zhuang via Openmp-commits
openmp-commits at lists.llvm.org
Mon Jun 8 06:56:15 PDT 2026
================
@@ -87,8 +87,10 @@ void ompd_init() {
Dl_info dl_info;
int ret = dladdr((void *)ompd_init, &dl_info);
if (!ret) {
- fprintf(stderr, "%s\n", dlerror());
- } else if (strrchr(dl_info.dli_fname, '/')) {
+ const char *err = dlerror();
+ if (err)
+ fprintf(stderr, "dladdr failed in ompd_init: %s\n", err);
----------------
zqb-all wrote:
Thanks @jprotze and @mjklemm for the suggestions.
To print the hint only when debugging, I see two options:
**Option A — move the `OMP_DEBUG` check before `dladdr` and gate the message on it:**
```c
const char *ompd_env_var = getenv("OMP_DEBUG");
int ompd_debug = ompd_env_var && !strcmp(ompd_env_var, "enabled");
#if KMP_OS_UNIX
...
if (!ret) {
const char *err = dlerror();
if (ompd_debug || err)
fprintf(stderr,
"The OpenMP runtime could not determine the location of "
"libompd.so. If the debugger fails to load the library, make "
"sure to add the directory containing a compatible libompd.so "
"to your LD_LIBRARY_PATH%s%s\n",
err ? ": " : "", err ? err : "");
} ...
#endif
```
**Option B — use libomp's trace facility (as @mjklemm suggested):**
```c
if (!ret) {
const char *err = dlerror();
KA_TRACE(10, ("The OpenMP runtime could not determine the location of "
"libompd.so. If the debugger fails to load the library, make "
"sure to add the directory containing a compatible libompd.so "
"to your LD_LIBRARY_PATH%s%s\n",
err ? ": " : "", err ? err : ""));
}
```
Do you have a preference between the two? Happy to go either way.
https://github.com/llvm/llvm-project/pull/201043
More information about the Openmp-commits
mailing list