https://gcc.gnu.org/g:833aa09c1c4602a24283222850ef38a59cf75238
commit r16-5241-g833aa09c1c4602a24283222850ef38a59cf75238 Author: Douglas B Rupp <[email protected]> Date: Fri Oct 3 09:54:47 2025 -0700 ada: Corrupted unwind info in aarch64-vx7r2 llvm kernel tests Adjust the register restoration on aarch64 to not use register 96 on llvm. Avoids the "reg too big" warning on aarch64 when sigtramp is called. For llvm and aarch64, the correct choice seems to be 32. Remove parens on REGNO_PC_OFFSET when compiling, it causes a silent failure due to alphanumeric register names. Define a macro for __attribute ((optimize (2))) which is empty if not availble. (Despite being documented, it generates an "unknown attribute" warning with clang.) Define ATTRIBUTE_PRINTF_2 if not defined. gcc/ada/ChangeLog: * sigtramp-vxworks-target.h (REGNO_PC_OFFSET): Use 32 vice 96 with llvm/clang. (REGNO_G_REG_OFFSET): Remove parens on operand. (REGNO_GR): Likewise. * sigtramp-vxworks.c (__gnat_sigtramp): Define a macro for __attribute__ optimize, which is empty of not available. * raise-gcc.c (db): Define ATTRIBUTE_PRINTF_2 if not defined. Diff: --- gcc/ada/raise-gcc.c | 6 ++++++ gcc/ada/sigtramp-vxworks-target.h | 29 +++++++++++++++++++++++++---- gcc/ada/sigtramp-vxworks.c | 12 ++++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/gcc/ada/raise-gcc.c b/gcc/ada/raise-gcc.c index 34aa707ef554..0a70cce7d38c 100644 --- a/gcc/ada/raise-gcc.c +++ b/gcc/ada/raise-gcc.c @@ -274,6 +274,12 @@ db_indent (int requests) fprintf (stderr, "%*s", current_indentation_level * DB_INDENT_UNIT, " "); } +/* If ATTRIBUTE_PRINTF_2 is not available, assume a printf format + attribute a-la gcc such as: */ +#ifndef ATTRIBUTE_PRINTF_2 +#define ATTRIBUTE_PRINTF_2 __attribute((format(printf, 2, 3))) +#endif + static void ATTRIBUTE_PRINTF_2 db (int db_code, const char * msg_format, ...) { diff --git a/gcc/ada/sigtramp-vxworks-target.h b/gcc/ada/sigtramp-vxworks-target.h index 90c9c3cedfb3..00fb103b7a1b 100644 --- a/gcc/ada/sigtramp-vxworks-target.h +++ b/gcc/ada/sigtramp-vxworks-target.h @@ -79,7 +79,20 @@ #undef TCR #define TCR(S) TAB(CR(S)) -/* REGNO constants, dwarf column numbers for registers of interest. */ +/* REGNO constants, dwarf column numbers for registers of interest. + + In the REGNO definitions that follow, when there is a register + number argument N, the use of parens around N in the result + is to be avoided. These eventually expand as a register column + number in a .cfi_offset directive within an "asm" statement, + through stringification. Parens in the macro expansion would + end up in the result and yield code such as + + asm(".cfi_offset (0), <offset-expr>") + + The parens impair readability here, and could even cause + processing errors from llvm compilers that interpret the + directives. */ #if defined (__PPC__) @@ -87,7 +100,7 @@ #define REGNO_CTR 66 #define REGNO_CR 70 #define REGNO_XER 76 -#define REGNO_GR(N) (N) +#define REGNO_GR(N) N #define REGNO_PC 67 /* ARG_POINTER_REGNUM */ @@ -95,12 +108,20 @@ #elif defined (ARMEL) -#define REGNO_G_REG_OFFSET(N) (N) +#define REGNO_G_REG_OFFSET(N) N #define FUNCTION "%function" #ifdef __aarch64__ -#define REGNO_PC_OFFSET 96 /* DWARF_ALT_FRAME_RETURN_COLUMN */ + +/* For the return column, GCC has DWARF_ALT_FRAME_RETURN_COLUMN (96) + while libunwind, used with llvm toolchains, implements the PC (!= LR) + ABI column 32. */ +#ifdef __llvm__ +#define REGNO_PC_OFFSET 32 +#else +#define REGNO_PC_OFFSET 96 /* DWARF_ALT_FRAME_RETURN_COLUMN */ +#endif #else #define REGNO_PC_OFFSET 15 /* PC_REGNUM */ #endif diff --git a/gcc/ada/sigtramp-vxworks.c b/gcc/ada/sigtramp-vxworks.c index 83bd2c6923f4..2dff40d81b42 100644 --- a/gcc/ada/sigtramp-vxworks.c +++ b/gcc/ada/sigtramp-vxworks.c @@ -114,9 +114,17 @@ void __gnat_set_is_vxsim(int val) { } #endif +/* When one is known for the compiler processing this runtime file, + a function attribute requesting optimization for the said function. + Assume __has_attribute is available for such queries, valid for at + least gcc and clang. */ +#if __has_attribute(optimize) +#define OPTIMIZE_O2 __attribute__((optimize(2))); +#else +#define OPTIMIZE_O2 +#endif void __gnat_sigtramp (int signo, void *si, void *sc, - __sigtramphandler_t * handler) - __attribute__((optimize(2))); + __sigtramphandler_t * handler) OPTIMIZE_O2; void __gnat_sigtramp (int signo, void *si, void *sc, __sigtramphandler_t * handler)
