Skip to content

Commit a2a280e

Browse files
authored
[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`.
1 parent 2070044 commit a2a280e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

openmp/runtime/src/ompt-internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ void ompt_pre_init(void);
109109
void ompt_post_init(void);
110110
void ompt_fini(void);
111111

112-
#define OMPT_GET_RETURN_ADDRESS(level) __builtin_return_address(level)
112+
#define OMPT_GET_RETURN_ADDRESS(level) \
113+
__builtin_extract_return_addr(__builtin_return_address(level))
113114
#define OMPT_GET_FRAME_ADDRESS(level) __builtin_frame_address(level)
114115
#define OMPT_FRAME_FLAGS_APP (ompt_frame_application | ompt_frame_cfa)
115116
#define OMPT_FRAME_FLAGS_RUNTIME (ompt_frame_runtime | ompt_frame_cfa)

openmp/runtime/src/ompt-specific.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,16 @@ inline void *__ompt_load_return_address(int gtid) {
102102
if (ompt_enabled.enabled && gtid >= 0 && __kmp_threads[gtid] && \
103103
!__kmp_threads[gtid]->th.ompt_thread_info.return_address) \
104104
__kmp_threads[gtid]->th.ompt_thread_info.return_address = \
105-
__builtin_return_address(0)*/
105+
__builtin_extract_return_addr(__builtin_return_address(0))*/
106106
#define OMPT_STORE_RETURN_ADDRESS(gtid) \
107-
OmptReturnAddressGuard ReturnAddressGuard{gtid, __builtin_return_address(0)};
107+
OmptReturnAddressGuard ReturnAddressGuard{ \
108+
gtid, __builtin_extract_return_addr(__builtin_return_address(0))};
108109
#define OMPT_LOAD_RETURN_ADDRESS(gtid) __ompt_load_return_address(gtid)
109110
#define OMPT_LOAD_OR_GET_RETURN_ADDRESS(gtid) \
110111
((ompt_enabled.enabled && gtid >= 0 && __kmp_threads[gtid] && \
111112
__kmp_threads[gtid]->th.ompt_thread_info.return_address) \
112113
? __ompt_load_return_address(gtid) \
113-
: __builtin_return_address(0))
114+
: __builtin_extract_return_addr(__builtin_return_address(0)))
114115

115116
#define OMPT_GET_DISPATCH_CHUNK(chunk, lb, ub, incr) \
116117
do { \

0 commit comments

Comments
 (0)