2 # Test that glibc's signal numbers match the kernel's.
3 # Copyright (C) 2017 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
21 if [ -n "$BASH_VERSION" ]; then set -o pipefail
; fi
22 LC_ALL
=C
; export LC_ALL
24 # We cannot use Linux's asm/signal.h to define signal numbers, because
25 # it isn't sufficiently namespace-clean. Instead, this test checks
26 # that our signal numbers match the kernel's. This script expects
27 # "$@" to be $(CC) $(CPPFLAGS) as set by glibc's Makefiles, and $AWK
28 # to be set in the environment.
30 # Before doing anything else, fail if the compiler doesn't work.
31 "$@" -E -xc -dM - < /dev
/null
> /dev
/null
33 tmpG
=`mktemp -t signums_glibc.XXXXXXXXX`
34 tmpK
=`mktemp -t signums_kernel.XXXXXXXXX`
35 trap "rm -f '$tmpG' '$tmpK'" 0
37 # Filter out constants that aren't signal numbers.
38 # If SIGPOLL is defined as SIGIO, swap it around so SIGIO is defined as
39 # SIGPOLL. Similarly for SIGABRT and SIGIOT.
40 # Discard obsolete signal numbers and unrelated constants:
41 # SIGCLD, SIGIOT, SIGSWI, SIGUNUSED.
42 # SIGSTKSZ, SIGRTMIN, SIGRTMAX.
47 /^#define SIG[A-Z]+ ([0-9]+|SIG[A-Z0-9]+)$/ { signals[$2] = $3 }
49 if ("SIGPOLL" in signals && "SIGIO" in signals &&
50 signals["SIGPOLL"] == "SIGIO") {
51 signals["SIGPOLL"] = signals["SIGIO"]
52 signals["SIGIO"] = "SIGPOLL"
54 if ("SIGABRT" in signals && "SIGIOT" in signals &&
55 signals["SIGABRT"] == "SIGIOT") {
56 signals["SIGABRT"] = signals["SIGIOT"]
57 signals["SIGIOT"] = "SIGABRT"
59 for (sig in signals) {
60 if (sig !~ /^SIG(CLD|IOT|RT(MIN|MAX)|STKSZ|SWI|UNUSED)$/) {
61 printf("#define %s %s\n", sig, signals[sig])
67 # $CC may contain command-line switches, so it should be word-split.
68 printf '%s' '#define _GNU_SOURCE 1
72 filter_defines
> "$tmpG"
74 printf '%s' '#define _GNU_SOURCE 1
75 #define __ASSEMBLER__ 1
76 #include <asm/signal.h>
79 filter_defines
> "$tmpK"
81 if cmp -s "$tmpG" "$tmpK"; then
84 diff -u "$tmpG" "$tmpK"