From f752a3e5bdff44386f8b2cafa4d82e91475b451b Mon Sep 17 00:00:00 2001 From: miod Date: Wed, 22 Oct 2025 18:44:06 +0000 Subject: [PATCH] The __builtin_return_address() internal logic, on PA-Risc, tries to read the code at the tentative return address in order to check for a possible inter-space thunk ("export stub" as called by HP), and in this case, unfolds a bit more to retrieve the stub return address. When the code pages are not readable, which is the case by default under OpenBSD/hppa, this causes an immediate segmentation fault. But there is no use of multiple space registers under OpenBSD either, so such thunks are never created by ld(1). We can therefore override the logic by simply returning the tentative return address, which is correct and does not require read permission on the code pages. ok jca@ --- gnu/gcc/gcc/config/pa/openbsd.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gnu/gcc/gcc/config/pa/openbsd.h b/gnu/gcc/gcc/config/pa/openbsd.h index 9169d37e548..169c124991f 100644 --- a/gnu/gcc/gcc/config/pa/openbsd.h +++ b/gnu/gcc/gcc/config/pa/openbsd.h @@ -195,3 +195,13 @@ Boston, MA 02111-1307, USA. */ %{!nopie:rcrt0%O%s}}}} crtbegin%O%s} %{shared:crtbeginS%O%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}" + +/* Find the return address associated with the frame given by + FRAMEADDR. + The default code in pa.h invokes return_addr_rtx(), which attemps to + read code at the return pointer in order to check for an export stub. + This is not possible under OpenBSD as code is not readable; but such + export stubs are not used under OpenBSD anymay. */ +#undef RETURN_ADDR_RTX +#define RETURN_ADDR_RTX(COUNT, FRAMEADDR) \ + ((COUNT) == 0 ? get_hard_reg_initial_val (Pmode, 2) : NULL_RTX)