[Openmp-commits] [openmp] [OpenMP] Improve dladdr error handling in ompd_init() (PR #201043)
Mark Zhuang via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jun 2 00:24:14 PDT 2026
https://github.com/zqb-all created https://github.com/llvm/llvm-project/pull/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
>From 2d7700aa8194a2de8b9d898dae91ed3048c6adf9 Mon Sep 17 00:00:00 2001
From: Mark Zhuang <mark.zhuang at spacemit.com>
Date: Tue, 2 Jun 2026 10:48:36 +0800
Subject: [PATCH] [OpenMP] Improve dladdr error handling in ompd_init()
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
---
openmp/runtime/src/ompd-specific.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/openmp/runtime/src/ompd-specific.cpp b/openmp/runtime/src/ompd-specific.cpp
index dadfb26e0e125..de82b6e17d451 100644
--- a/openmp/runtime/src/ompd-specific.cpp
+++ b/openmp/runtime/src/ompd-specific.cpp
@@ -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);
+ } 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'*/);
More information about the Openmp-commits
mailing list