[Openmp-commits] [openmp] 74a146d - [OpenMP] Improve dladdr error handling in ompd_init() (#201043)
via Openmp-commits
openmp-commits at lists.llvm.org
Thu Jun 18 09:03:13 PDT 2026
Author: Mark Zhuang
Date: 2026-06-19T00:03:07+08:00
New Revision: 74a146dd9c28c083db057d7f87afbcc617319392
URL: https://github.com/llvm/llvm-project/commit/74a146dd9c28c083db057d7f87afbcc617319392
DIFF: https://github.com/llvm/llvm-project/commit/74a146dd9c28c083db057d7f87afbcc617319392.diff
LOG: [OpenMP] Improve dladdr error handling in ompd_init() (#201043)
Guard dlerror() result against NULL before passing to fprintf to avoid
confusing "(null)" output. Also guard dli_fname against NULL on the
success path before calling strrchr.
Assisted-by: Claude Sonnet 4.6
Added:
Modified:
openmp/runtime/src/ompd-specific.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/ompd-specific.cpp b/openmp/runtime/src/ompd-specific.cpp
index dadfb26e0e125..82ffe652f3caa 100644
--- a/openmp/runtime/src/ompd-specific.cpp
+++ b/openmp/runtime/src/ompd-specific.cpp
@@ -81,14 +81,24 @@ void ompd_init() {
char *libname = NULL;
+ const char *ompd_env_var = getenv("OMP_DEBUG");
+ int ompd_debug = ompd_env_var && !strcmp(ompd_env_var, "enabled");
+
#if KMP_OS_UNIX
// Find the location of libomp.so thru dladdr and replace the libomp with
// libompd to get the full path of libompd
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 (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 : "");
+ } else if (dl_info.dli_fname && strrchr(dl_info.dli_fname, '/')) {
int lib_path_length = strrchr(dl_info.dli_fname, '/') - dl_info.dli_fname;
libname =
(char *)malloc(lib_path_length + 12 /*for '/libompd.so' and '\0'*/);
@@ -97,8 +107,7 @@ void ompd_init() {
}
#endif
- const char *ompd_env_var = getenv("OMP_DEBUG");
- if (ompd_env_var && !strcmp(ompd_env_var, "enabled")) {
+ if (ompd_debug) {
fprintf(stderr, "OMP_OMPD active\n");
ompt_enabled.enabled = 1;
ompd_state |= OMPD_ENABLE_BP;
More information about the Openmp-commits
mailing list