[Openmp-commits] [openmp] a2a280e - [OpenMP] Fix __builtin_return_address calls for SPARC (#138520)
via Openmp-commits
openmp-commits at lists.llvm.org
Wed May 14 04:11:23 PDT 2025
Author: Rainer Orth
Date: 2025-05-14T13:11:19+02:00
New Revision: a2a280e58c95f76185ab93c1b73cb1608318b699
URL: https://github.com/llvm/llvm-project/commit/a2a280e58c95f76185ab93c1b73cb1608318b699
DIFF: https://github.com/llvm/llvm-project/commit/a2a280e58c95f76185ab93c1b73cb1608318b699.diff
LOG: [OpenMP] Fix __builtin_return_address calls for SPARC (#138520)
`libomp` uses `__builtin_return_address` in two places. However, on some
targets those calls need to wrapped in `___builtin_extract_return_addr`
to get at the actual return address. SPARC is among those targets and
the only one where `clang` actually implements this, cf. [[clang][Sparc]
Fix __builtin_extract_return_addr
etc.](https://reviews.llvm.org/D91607). `compiler-rt` needed the same
adjustment, cf. [[sanitizer_common][test] Enable tests on
SPARC](https://reviews.llvm.org/D91608). On other targets, this is a
no-op. However, there are more targets that have the same issue and
`gcc`, unlike `clang`, correctly implements it, so there might be issues
when building `libomp` with `gcc`.
This patch adds the necessary calls.
Tested on `sparcv9-sun-solaris2.11`, `sparc64-unknown-linux-gnu`,
`amd64-pc-solaris2.11`, and `x86_64-pc-linux-gnu`.
Added:
Modified:
openmp/runtime/src/ompt-internal.h
openmp/runtime/src/ompt-specific.h
Removed:
################################################################################
diff --git a/openmp/runtime/src/ompt-internal.h b/openmp/runtime/src/ompt-internal.h
index 0cfab8bfaa190..36b45f7a91ea2 100644
--- a/openmp/runtime/src/ompt-internal.h
+++ b/openmp/runtime/src/ompt-internal.h
@@ -109,7 +109,8 @@ void ompt_pre_init(void);
void ompt_post_init(void);
void ompt_fini(void);
-#define OMPT_GET_RETURN_ADDRESS(level) __builtin_return_address(level)
+#define OMPT_GET_RETURN_ADDRESS(level) \
+ __builtin_extract_return_addr(__builtin_return_address(level))
#define OMPT_GET_FRAME_ADDRESS(level) __builtin_frame_address(level)
#define OMPT_FRAME_FLAGS_APP (ompt_frame_application | ompt_frame_cfa)
#define OMPT_FRAME_FLAGS_RUNTIME (ompt_frame_runtime | ompt_frame_cfa)
diff --git a/openmp/runtime/src/ompt-specific.h b/openmp/runtime/src/ompt-specific.h
index e9e40d43429ea..b7eb140458b40 100644
--- a/openmp/runtime/src/ompt-specific.h
+++ b/openmp/runtime/src/ompt-specific.h
@@ -102,15 +102,16 @@ inline void *__ompt_load_return_address(int gtid) {
if (ompt_enabled.enabled && gtid >= 0 && __kmp_threads[gtid] && \
!__kmp_threads[gtid]->th.ompt_thread_info.return_address) \
__kmp_threads[gtid]->th.ompt_thread_info.return_address = \
- __builtin_return_address(0)*/
+ __builtin_extract_return_addr(__builtin_return_address(0))*/
#define OMPT_STORE_RETURN_ADDRESS(gtid) \
- OmptReturnAddressGuard ReturnAddressGuard{gtid, __builtin_return_address(0)};
+ OmptReturnAddressGuard ReturnAddressGuard{ \
+ gtid, __builtin_extract_return_addr(__builtin_return_address(0))};
#define OMPT_LOAD_RETURN_ADDRESS(gtid) __ompt_load_return_address(gtid)
#define OMPT_LOAD_OR_GET_RETURN_ADDRESS(gtid) \
((ompt_enabled.enabled && gtid >= 0 && __kmp_threads[gtid] && \
__kmp_threads[gtid]->th.ompt_thread_info.return_address) \
? __ompt_load_return_address(gtid) \
- : __builtin_return_address(0))
+ : __builtin_extract_return_addr(__builtin_return_address(0)))
#define OMPT_GET_DISPATCH_CHUNK(chunk, lb, ub, incr) \
do { \
More information about the Openmp-commits
mailing list