[Ada] Fix thinko in QNX's implementation of __gnat_install_handler

Message ID 20220516084313.GA3843684@adacore.com
State Committed
Commit 839e7f16abda3fd8bd46d59ff1521d402d328a24
Headers
Series [Ada] Fix thinko in QNX's implementation of __gnat_install_handler |

Commit Message

Pierre-Marie de Rodat May 16, 2022, 8:43 a.m. UTC
  On QNX, the sigaction handler is incorrectly installed via the
sa_handler field of struct sigaction, rather than the sa_sigaction
field. This triggers a compilation warning due to a mismatch between the
function's signature and the field's type.

    | init.c:2614:18: warning: assignment to 'void (*)(int)'
    | from incompatible pointer type 'void (*)(int,  siginfo_t *, void *)'
    | {aka 'void (*)(int,  struct _siginfo *, void *)'}
    | [-Wincompatible-pointer-types]

In practice, using the sa_handler field actually works, but only because
those two fields are inside a union:

    From target/qnx7/usr/include/signal.h:
    | union { \
    |     __handler_type  _sa_handler; \
    |     __action_type   _sa_sigaction; \
    |     } __sa_un; \

This commit fixes this.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* init.c (__gnat_install_handler) [__QNX__]: Set
	act.sa_sigaction rather than act.sa_handler.
  

Patch

diff --git a/gcc/ada/init.c b/gcc/ada/init.c
--- a/gcc/ada/init.c
+++ b/gcc/ada/init.c
@@ -2611,7 +2611,7 @@  __gnat_install_handler (void)
   struct sigaction act;
   int err;
 
-  act.sa_handler = __gnat_error_handler;
+  act.sa_sigaction = __gnat_error_handler;
   act.sa_flags = SA_NODEFER | SA_SIGINFO;
   sigemptyset (&act.sa_mask);