[Openmp-commits] [openmp] [OpenMP][test] Define print_possible_return_addresses on SPARC (PR #138523)
Rainer Orth via Openmp-commits
openmp-commits at lists.llvm.org
Wed May 14 00:33:30 PDT 2025
================
@@ -311,6 +311,14 @@ ompt_label_##id:
printf("%" PRIu64 ": current_address=%p or %p or %p\n", \
ompt_get_thread_data()->value, ((char *)addr) - 2, \
((char *)addr) - 8, ((char *)addr) - 12)
+#elif KMP_ARCH_SPARC
+// FIXME: Need to distinguish between 32 and 64-bit SPARC?
+// On SPARC the NOP instruction is 4 bytes long.
+// FIXME: Explain. Can use __builtin_frob_return_addr?
+#define print_possible_return_addresses(addr) \
----------------
rorth wrote:
> Wait, so this is essencially tries to find where the start of the inserted `nop` is right? If so, then I understand the `addr-12` case:
>
> * `nop` itself is 4 byte, so we need to decrement the label's address by that much: `addr-4`
>
> * Depending on optimization level there might be a `ba` plus the corresponding delay slot inserted, so need to decrement again by zero or two instruction: `addr-4-0` -> `addr-4` or `addr-4-8` -> `addr-12`
We don't need to worry about optimization, at least not initially: `print_possible_return_addresses` is only used inside the `openmp` testsuite, and that is always compiled with just `-fopenmp` without any `-O` option. I found that in both `Release` and `Debug` builds, where `libomp` itself **is** compiled with either optimization or debug options.
> See e.g https://godbolt.org/z/8hYcsWTTd Though, as far as I can tell there's no difference between 32 and 64 bit SPARC.
>
> But what I still don't understand is, why is `addr-20` a possible address?
I saw the need only in two tests: `ompt/synchronization/masked.c` and `ompt/synchronization/master.c`. In both cases, after a compiler-inserted call to `__kmpc_end_master` due to `#pragma omp` directives, we got a code sequence like
```
0x10000005fcc: sethi %hi(0x400), %i1
0x10000005fd0: add %i1, 0x220, %i1 ! 0x620
0x10000005fd4: call 0x100002008a0 <__kmpc_end_master at got.plt>
0x10000005fd8: ldx [ %i0 + %i1 ], %o0
0x10000005fdc: b 0x10000005fe4 <= codeptr_ra
0x10000005fe0: nop
0x10000005fe4: nop <= current_addr
0x10000005fe8: b 0x10000005ff0
0x10000005fec: nop
```
i.e. 8 more bytes to allow for.
https://github.com/llvm/llvm-project/pull/138523
More information about the Openmp-commits
mailing list