about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog25
-rw-r--r--NEWS2
-rw-r--r--bits/signum-generic.h102
-rw-r--r--bits/signum.h72
-rw-r--r--signal/Makefile3
-rw-r--r--signal/signal.h3
-rw-r--r--sysdeps/generic/siglist.h24
-rw-r--r--sysdeps/unix/bsd/bits/signum.h58
-rw-r--r--sysdeps/unix/sysv/linux/Makefile14
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/signum.h69
-rw-r--r--sysdeps/unix/sysv/linux/bits/signum.h91
-rw-r--r--sysdeps/unix/sysv/linux/hppa/bits/signum.h110
-rw-r--r--sysdeps/unix/sysv/linux/mips/bits/signum.h94
-rw-r--r--sysdeps/unix/sysv/linux/sparc/bits/signum.h70
-rw-r--r--sysdeps/unix/sysv/linux/tst-signal-numbers.sh86
15 files changed, 417 insertions, 406 deletions
diff --git a/ChangeLog b/ChangeLog
index efc7c7add2..b3693a45b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,30 @@
 2017-06-20  Zack Weinberg  <zackw@panix.com>
 
+	* bits/signum-generic.h: Renamed from bits/signum.h.
+	Add proper multiple include guard and misuse check.
+	Define __SIGRTMIN = __SIGRTMAX = 32, and define _NSIG = __SIGRTMAX+1.
+	Move definition of SIGIO to "archaic names for compatibility" section.
+	* bits/signum.h: New file which just includes bits/signum-generic.h.
+	* sysdeps/unix/bsd/bits/signum.h
+	* sysdeps/unix/sysv/linux/bits/signum.h
+	* sysdeps/unix/sysv/linux/alpha/bits/signum.h
+	* sysdeps/unix/sysv/linux/hppa/bits/signum.h
+	* sysdeps/unix/sysv/linux/mips/bits/signum.h
+	* sysdeps/unix/sysv/linux/sparc/bits/signum.h
+	Just include <bits/signum-generic.h> and then add or adjust
+	signal constants.  Do not define SIGUNUSED, SIGRTMIN, or SIGRTMAX.
+
+	* signal/Makefile: Install bits/signum-generic.h.
+	* signal/signal.h: Define SIGRTMIN and SIGRTMAX here.
+
+	* sysdeps/generic/siglist.h: SIGSYS and SIGWINCH are
+	universal.  Prefer SIGPOLL to SIGIO. Simplify #ifdeffage.
+
+	* sysdeps/unix/sysv/linux/tst-signal-numbers.sh: New test.
+	* sysdeps/unix/sysv/linux/Makefile: Run it.
+
+2017-06-20  Zack Weinberg  <zackw@panix.com>
+
 	* locale/xlocale.h: Rename to...
 	* locale/bits/types/__locale_t.h: ...here.  Adjust commentary.
 	Only define struct __locale_struct and __locale_t, not locale_t.
diff --git a/NEWS b/NEWS
index 0736b4b27f..1af73311a5 100644
--- a/NEWS
+++ b/NEWS
@@ -78,6 +78,8 @@ Version 2.26
   use <locale.h> instead.  If you have a specific need for the definition
   of locale_t with no other declarations, please talk to us.
 
+* The obsolete signal constant SIGUNUSED is no longer defined by <signal.h>.
+
 * The reallocarray function has been added to libc.  It is a realloc
   replacement with a check for integer overflow when calculating total
   allocation size.
diff --git a/bits/signum-generic.h b/bits/signum-generic.h
new file mode 100644
index 0000000000..5a5683e753
--- /dev/null
+++ b/bits/signum-generic.h
@@ -0,0 +1,102 @@
+/* Signal number constants.  Generic template.
+   Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef	_BITS_SIGNUM_GENERIC_H
+#define _BITS_SIGNUM_GENERIC_H 1
+
+#ifndef _SIGNAL_H
+#error "Never include <bits/signum-generic.h> directly; use <signal.h> instead."
+#endif
+
+/* Fake signal functions.  */
+
+#define	SIG_ERR	 ((__sighandler_t) -1)	/* Error return.  */
+#define	SIG_DFL	 ((__sighandler_t)  0)	/* Default action.  */
+#define	SIG_IGN	 ((__sighandler_t)  1)	/* Ignore signal.  */
+
+#ifdef __USE_XOPEN
+# define SIG_HOLD ((__sighandler_t) 2)	/* Add signal to hold mask.  */
+#endif
+
+/* We define here all the signal names listed in POSIX (1003.1-2008);
+   as of 1003.1-2013, no additional signals have been added by POSIX.
+   We also define here signal names that historically exist in every
+   real-world POSIX variant (e.g. SIGWINCH).
+
+   Signals in the 1-15 range are defined with their historical numbers.
+   For other signals, we use the BSD numbers.
+   There are two unallocated signal numbers in the 1-31 range: 7 and 29.
+   Signal number 0 is reserved for use as kill(pid, 0), to test whether
+   a process exists without sending it a signal.  */
+
+/* ISO C99 signals.  */
+#define	SIGINT		2	/* Interactive attention signal.  */
+#define	SIGILL		4	/* Illegal instruction.  */
+#define	SIGABRT		6	/* Abnormal termination.  */
+#define	SIGFPE		8	/* Erroneous arithmetic operation.  */
+#define	SIGSEGV		11	/* Invalid access to storage.  */
+#define	SIGTERM		15	/* Termination request.  */
+
+/* Historical signals specified by POSIX. */
+#define	SIGHUP		1	/* Hangup.  */
+#define	SIGQUIT		3	/* Quit.  */
+#define	SIGTRAP		5	/* Trace/breakpoint trap.  */
+#define	SIGKILL		9	/* Killed.  */
+#define SIGBUS		10	/* Bus error.  */
+#define	SIGSYS		12	/* Bad system call.  */
+#define	SIGPIPE		13	/* Broken pipe.  */
+#define	SIGALRM		14	/* Alarm clock.  */
+
+/* New(er) POSIX signals (1003.1-2008, 1003.1-2013).  */
+#define	SIGURG		16	/* Urgent data is available at a socket.  */
+#define	SIGSTOP		17	/* Stop, unblockable.  */
+#define	SIGTSTP		18	/* Keyboard stop.  */
+#define	SIGCONT		19	/* Continue.  */
+#define	SIGCHLD		20	/* Child terminated or stopped.  */
+#define	SIGTTIN		21	/* Background read from control terminal.  */
+#define	SIGTTOU		22	/* Background write to control terminal.  */
+#define	SIGPOLL		23	/* Pollable event occurred (System V).  */
+#define	SIGXCPU		24	/* CPU time limit exceeded.  */
+#define	SIGXFSZ		25	/* File size limit exceeded.  */
+#define	SIGVTALRM	26	/* Virtual timer expired.  */
+#define	SIGPROF		27	/* Profiling timer expired.  */
+#define	SIGUSR1		30	/* User-defined signal 1.  */
+#define	SIGUSR2		31	/* User-defined signal 2.  */
+
+/* Nonstandard signals found in all modern POSIX systems
+   (including both BSD and Linux).  */
+#define	SIGWINCH	28	/* Window size change (4.3 BSD, Sun).  */
+
+/* Archaic names for compatibility.  */
+#define	SIGIO		SIGPOLL	/* I/O now possible (4.2 BSD).  */
+#define	SIGIOT		SIGABRT	/* IOT instruction, abort() on a PDP-11.  */
+#define	SIGCLD		SIGCHLD	/* Old System V name */
+
+/* Not all systems support real-time signals.  bits/signum.h indicates
+   that they are supported by overriding __SIGRTMAX to a value greater
+   than __SIGRTMIN.  These constants give the kernel-level hard limits,
+   but some real-time signals may be used internally by glibc.  Do not
+   use these constants in application code; use SIGRTMIN and SIGRTMAX
+   (defined in signal.h) instead.  */
+#define __SIGRTMIN	32
+#define __SIGRTMAX	__SIGRTMIN
+
+/* Biggest signal number + 1 (including real-time signals).  */
+#define _NSIG		(__SIGRTMAX + 1)
+
+#endif /* bits/signum-generic.h.  */
diff --git a/bits/signum.h b/bits/signum.h
index cfbc7ac8bb..8d6d03c918 100644
--- a/bits/signum.h
+++ b/bits/signum.h
@@ -1,5 +1,5 @@
 /* Signal number constants.  Generic version.
-   Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,69 +16,17 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef	_SIGNAL_H
+#ifndef _BITS_SIGNUM_H
+#define _BITS_SIGNUM_H 1
 
-/* Fake signal functions.  */
-
-#define	SIG_ERR	 ((__sighandler_t) -1)	/* Error return.  */
-#define	SIG_DFL	 ((__sighandler_t)  0)	/* Default action.  */
-#define	SIG_IGN	 ((__sighandler_t)  1)	/* Ignore signal.  */
-
-#ifdef __USE_XOPEN
-# define SIG_HOLD ((__sighandler_t)  2)	/* Add signal to hold mask.  */
+#ifndef _SIGNAL_H
+#error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
-/* We define here all the signal names listed in POSIX (1003.1-2008);
-   as of 1003.1-2013, no additional signals have been added by POSIX.
-   We also define here signal names that historically exist in every
-   real-world POSIX variant (e.g. SIGWINCH).
-
-   Signals in the 1-15 range are defined with their historical numbers.
-   For other signals, we use the BSD numbers.  */
-
-/* ISO C99 signals.  */
-#define	SIGINT		2	/* Interactive attention signal.  */
-#define	SIGILL		4	/* Illegal instruction.  */
-#define	SIGABRT		6	/* Abnormal termination.  */
-#define	SIGFPE		8	/* Erroneous arithmetic operation.  */
-#define	SIGSEGV		11	/* Invalid access to storage.  */
-#define	SIGTERM		15	/* Termination request.  */
-
-/* Historical signals specified by POSIX. */
-#define	SIGHUP		1	/* Hangup.  */
-#define	SIGQUIT		3	/* Quit.  */
-#define	SIGTRAP		5	/* Trace/breakpoint trap.  */
-#define	SIGKILL		9	/* Killed.  */
-#define SIGBUS		10	/* Bus error.  */
-#define	SIGSYS		12	/* Bad system call.  */
-#define	SIGPIPE		13	/* Broken pipe.  */
-#define	SIGALRM		14	/* Alarm clock.  */
-
-/* New(er) POSIX signals (1003.1-2008, 1003.1-2013).  */
-#define	SIGURG		16 /* High bandwidth data is available at a socket.  */
-#define	SIGSTOP		17	/* Stopped (signal).  */
-#define	SIGTSTP		18	/* Stopped.  */
-#define	SIGCONT		19	/* Continued.  */
-#define	SIGCHLD		20	/* Child terminated or stopped.  */
-#define	SIGTTIN		21	/* Background read from control terminal.  */
-#define	SIGTTOU		22	/* Background write to control terminal.  */
-#define	SIGPOLL 	23	/* Pollable event occurred (System V).  */
-#define	SIGIO		SIGPOLL /* I/O now possible (4.2 BSD).  */
-#define	SIGXCPU		24	/* CPU time limit exceeded.  */
-#define	SIGXFSZ		25	/* File size limit exceeded.  */
-#define	SIGVTALRM	26	/* Virtual timer expired.  */
-#define	SIGPROF		27	/* Profiling timer expired.  */
-#define	SIGUSR1		30	/* User-defined signal 1.  */
-#define	SIGUSR2		31	/* User-defined signal 2.  */
-
-/* Nonstandard signals found in all modern POSIX systems
-   (including both BSD and Linux).  */
-#define	SIGWINCH	28	/* Window size change (4.3 BSD, Sun).  */
-
-#define	_NSIG		32
+#include <bits/signum-generic.h>
 
-/* Archaic names for compatibility. */
-#define	SIGIOT		SIGABRT	/* IOT instruction, abort() on a PDP-11.  */
-#define	SIGCLD		SIGCHLD	/* Old System V name */
+/* This operating system does not need to override any of the generic
+   signal number assignments in bits/signum-generic.h, nor to add any
+   additional signal constants.  */
 
-#endif	/* <signal.h> included.  */
+#endif /* bits/signum.h.  */
diff --git a/signal/Makefile b/signal/Makefile
index 9ce8232d43..8c9a7d1844 100644
--- a/signal/Makefile
+++ b/signal/Makefile
@@ -23,7 +23,8 @@ subdir	:= signal
 include ../Makeconfig
 
 headers := signal.h sys/signal.h \
-	   bits/signum.h bits/sigcontext.h bits/sigaction.h \
+	   bits/signum.h bits/signum-generic.h \
+	   bits/sigcontext.h bits/sigaction.h \
 	   bits/sigevent-consts.h bits/siginfo-consts.h \
 	   bits/sigstack.h bits/sigthread.h bits/ss_flags.h \
 	   bits/types/__sigset_t.h bits/types/sig_atomic_t.h \
diff --git a/signal/signal.h b/signal/signal.h
index ddb79c7d98..c8f6100ac4 100644
--- a/signal/signal.h
+++ b/signal/signal.h
@@ -363,6 +363,9 @@ extern int __libc_current_sigrtmin (void) __THROW;
 /* Return number of available real-time signal with lowest priority.  */
 extern int __libc_current_sigrtmax (void) __THROW;
 
+#define SIGRTMIN        (__libc_current_sigrtmin ())
+#define SIGRTMAX        (__libc_current_sigrtmax ())
+
 __END_DECLS
 
 #endif /* not signal.h */
diff --git a/sysdeps/generic/siglist.h b/sysdeps/generic/siglist.h
index dd72929ed5..022be56059 100644
--- a/sysdeps/generic/siglist.h
+++ b/sysdeps/generic/siglist.h
@@ -24,7 +24,8 @@
 
 /* This file is included multiple times.  */
 
-/* Standard signals  */
+/* Standard signals, in the numerical order defined in
+   bits/signum-generic.h.  */
   init_sig (SIGHUP, "HUP", N_("Hangup"))
   init_sig (SIGINT, "INT", N_("Interrupt"))
   init_sig (SIGQUIT, "QUIT", N_("Quit"))
@@ -34,6 +35,7 @@
   init_sig (SIGFPE, "FPE", N_("Floating point exception"))
   init_sig (SIGKILL, "KILL", N_("Killed"))
   init_sig (SIGBUS, "BUS", N_("Bus error"))
+  init_sig (SIGSYS, "SYS", N_("Bad system call"))
   init_sig (SIGSEGV, "SEGV", N_("Segmentation fault"))
   init_sig (SIGPIPE, "PIPE", N_("Broken pipe"))
   init_sig (SIGALRM, "ALRM", N_("Alarm clock"))
@@ -45,32 +47,28 @@
   init_sig (SIGCHLD, "CHLD", N_("Child exited"))
   init_sig (SIGTTIN, "TTIN", N_("Stopped (tty input)"))
   init_sig (SIGTTOU, "TTOU", N_("Stopped (tty output)"))
-  init_sig (SIGIO, "IO", N_("I/O possible"))
+  init_sig (SIGPOLL, "POLL", N_("I/O possible"))
   init_sig (SIGXCPU, "XCPU", N_("CPU time limit exceeded"))
   init_sig (SIGXFSZ, "XFSZ", N_("File size limit exceeded"))
   init_sig (SIGVTALRM, "VTALRM", N_("Virtual timer expired"))
   init_sig (SIGPROF, "PROF", N_("Profiling timer expired"))
   init_sig (SIGUSR1, "USR1", N_("User defined signal 1"))
   init_sig (SIGUSR2, "USR2", N_("User defined signal 2"))
+  init_sig (SIGWINCH, "WINCH", N_("Window changed"))
 
-/* Variations  */
+/* Signals that are not present on all supported platforms.  */
 #ifdef SIGEMT
   init_sig (SIGEMT, "EMT", N_("EMT trap"))
 #endif
-#ifdef SIGSYS
-  init_sig (SIGSYS, "SYS", N_("Bad system call"))
-#endif
 #ifdef SIGSTKFLT
   init_sig (SIGSTKFLT, "STKFLT", N_("Stack fault"))
 #endif
-#ifdef SIGINFO
-  init_sig (SIGINFO, "INFO", N_("Information request"))
-#elif defined(SIGPWR) && (!defined(SIGLOST) || (SIGPWR != SIGLOST))
+#ifdef SIGPWR
   init_sig (SIGPWR, "PWR", N_("Power failure"))
 #endif
-#ifdef SIGLOST
-  init_sig (SIGLOST, "LOST", N_("Resource lost"))
+#if defined SIGINFO && (!defined SIGPWR || SIGPWR != SIGINFO)
+  init_sig (SIGINFO, "INFO", N_("Information request"))
 #endif
-#ifdef SIGWINCH
-  init_sig (SIGWINCH, "WINCH", N_("Window changed"))
+#if defined SIGLOST && (!defined SIGPWR || SIGPWR != SIGLOST)
+  init_sig (SIGLOST, "LOST", N_("Resource lost"))
 #endif
diff --git a/sysdeps/unix/bsd/bits/signum.h b/sysdeps/unix/bsd/bits/signum.h
index 268c24a702..f55edc93a3 100644
--- a/sysdeps/unix/bsd/bits/signum.h
+++ b/sysdeps/unix/bsd/bits/signum.h
@@ -16,58 +16,20 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef	_SIGNAL_H
+#ifndef _BITS_SIGNUM_H
+#define _BITS_SIGNUM_H 1
 
-/* This file defines the fake signal functions and signal
-   number constants for 4.2 or 4.3 BSD-derived Unix system.  */
-
-/* Fake signal functions.  */
-#define	SIG_ERR	((__sighandler_t) -1) /* Error return.  */
-#define	SIG_DFL	((__sighandler_t) 0) /* Default action.  */
-#define	SIG_IGN	((__sighandler_t) 1) /* Ignore signal.  */
-
-#ifdef __USE_XOPEN
-# define SIG_HOLD      ((__sighandler_t) 2)    /* Add signal to hold mask.  */
+#ifndef _SIGNAL_H
+#error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
+#include <bits/signum-generic.h>
 
-/* Signals.  */
-#define	SIGHUP		1	/* Hangup (POSIX).  */
-#define	SIGINT		2	/* Interrupt (ANSI).  */
-#define	SIGQUIT		3	/* Quit (POSIX).  */
-#define	SIGILL		4	/* Illegal instruction (ANSI).  */
-#define	SIGABRT		SIGIOT	/* Abort (ANSI).  */
-#define	SIGTRAP		5	/* Trace trap (POSIX).  */
-#define	SIGIOT		6	/* IOT trap (4.2 BSD).  */
-#define	SIGEMT		7	/* EMT trap (4.2 BSD).  */
-#define	SIGFPE		8	/* Floating-point exception (ANSI).  */
-#define	SIGKILL		9	/* Kill, unblockable (POSIX).  */
-#define	SIGBUS		10	/* Bus error (4.2 BSD).  */
-#define	SIGSEGV		11	/* Segmentation violation (ANSI).  */
-#define	SIGSYS		12	/* Bad argument to system call (4.2 BSD).  */
-#define	SIGPIPE		13	/* Broken pipe (POSIX).  */
-#define	SIGALRM		14	/* Alarm clock (POSIX).  */
-#define	SIGTERM		15	/* Termination (ANSI).  */
-#define	SIGURG		16	/* Urgent condition on socket (4.2 BSD).  */
-#define	SIGSTOP		17	/* Stop, unblockable (POSIX).  */
-#define	SIGTSTP		18	/* Keyboard stop (POSIX).  */
-#define	SIGCONT		19	/* Continue (POSIX).  */
-#define	SIGCHLD		20	/* Child status has changed (POSIX).  */
-#define	SIGCLD		SIGCHLD	/* Same as SIGCHLD (System V).  */
-#define	SIGTTIN		21	/* Background read from tty (POSIX).  */
-#define	SIGTTOU		22	/* Background write to tty (POSIX).  */
-#define	SIGIO		23	/* I/O now possible (4.2 BSD).  */
-#define	SIGPOLL		SIGIO	/* Same as SIGIO? (SVID).  */
-#define	SIGXCPU		24	/* CPU limit exceeded (4.2 BSD).  */
-#define	SIGXFSZ		25	/* File size limit exceeded (4.2 BSD).  */
-#define	SIGVTALRM	26	/* Virtual alarm clock (4.2 BSD).  */
-#define	SIGPROF		27	/* Profiling alarm clock (4.2 BSD).  */
-#define	SIGWINCH	28	/* Window size change (4.3 BSD, Sun).  */
+/* Adjustments and additions to the signal number constants for
+   4.2 or 4.3 BSD-derived Unix systems.  */
+
+#define SIGEMT		 7	/* Emulator trap (4.2 BSD).  */
 #define SIGINFO		29	/* Information request (4.4 BSD).  */
-#define	SIGUSR1		30	/* User-defined signal 1 (POSIX).  */
-#define	SIGUSR2		31	/* User-defined signal 2 (POSIX).  */
 #define SIGLOST		32	/* Resource lost (Sun); server died (GNU).  */
 
-#endif	/* <signal.h> included.  */
-
-#define	_NSIG		33	/* Biggest signal number + 1.  */
+#endif /* bits/signum.h.  */
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 1a170c29d6..8b340d4988 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -128,6 +128,20 @@ sysdep_headers += sys/timex.h bits/timex.h
 sysdep_routines += ntp_gettime ntp_gettimex
 endif
 
+ifeq ($(subdir),signal)
+tests-special += $(objpfx)tst-signal-numbers.out
+# Depending on signal.o* is a hack.  What we actually want is a dependency
+# on signal.h and everything it includes.  That's impractical to write
+# in this context, but signal.c includes signal.h and not much else so it'll
+# be conservatively correct.
+$(objpfx)tst-signal-numbers.out: \
+		../sysdeps/unix/sysv/linux/tst-signal-numbers.sh \
+		$(objpfx)signal.o*
+	AWK=$(AWK) $(SHELL) ../sysdeps/unix/sysv/linux/tst-signal-numbers.sh \
+	$(CC) $(patsubst -DMODULE_NAME=%,-DMODULE_NAME=testsuite,$(CPPFLAGS)) \
+	< /dev/null > $@; $(evaluate-test)
+endif
+
 ifeq ($(subdir),socket)
 sysdep_headers += net/if_ppp.h net/ppp-comp.h \
 		  net/ppp_defs.h net/if_arp.h net/route.h net/ethernet.h \
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/signum.h b/sysdeps/unix/sysv/linux/alpha/bits/signum.h
index e5cc5218e3..8227be91b5 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/signum.h
@@ -16,66 +16,25 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef	_SIGNAL_H
+#ifndef _BITS_SIGNUM_H
+#define _BITS_SIGNUM_H 1
 
-/* Fake signal functions.  */
-#define SIG_ERR ((__sighandler_t) -1) /* Error return.  */
-#define SIG_DFL ((__sighandler_t) 0) /* Default action.  */
-#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal.  */
-
-#ifdef __USE_XOPEN
-# define SIG_HOLD	((__sighandler_t) 2)	/* Add signal to hold mask.  */
+#ifndef _SIGNAL_H
+#error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
-/*
- * Linux/AXP has different signal numbers that Linux/i386: I'm trying
- * to make it OSF/1 binary compatible, at least for normal binaries.
- */
-#define SIGHUP		 1
-#define SIGINT		 2
-#define SIGQUIT		 3
-#define SIGILL		 4
-#define SIGTRAP		 5
-#define SIGABRT		 6
-#define SIGEMT		 7
-#define SIGFPE		 8
-#define SIGKILL		 9
-#define SIGBUS		10
-#define SIGSEGV		11
-#define SIGSYS		12
-#define SIGPIPE		13
-#define SIGALRM		14
-#define SIGTERM		15
-#define SIGURG		16
-#define SIGSTOP		17
-#define SIGTSTP		18
-#define SIGCONT		19
-#define SIGCHLD		20
-#define SIGCLD          SIGCHLD
-#define SIGTTIN		21
-#define SIGTTOU		22
-#define SIGIO		23
-#define SIGXCPU		24
-#define SIGXFSZ		25
-#define SIGVTALRM	26
-#define SIGPROF		27
-#define SIGWINCH	28
-#define SIGINFO		29
-#define SIGUSR1		30
-#define SIGUSR2		31
-
-#define SIGPOLL	SIGIO
-#define SIGPWR	SIGINFO
-#define SIGIOT	SIGABRT
+#include <bits/signum-generic.h>
 
-#define	_NSIG		65	/* Biggest signal number + 1.  */
+/* Adjustments and additions to the signal number constants for
+   Linux/Alpha.  Signal values on this platform were chosen for OSF/1
+   binary compatibility, and are therefore almost identical to the
+   BSD-derived defaults.  */
 
-#define SIGRTMIN	(__libc_current_sigrtmin ())
-#define SIGRTMAX	(__libc_current_sigrtmax ())
+#define SIGEMT		 7	/* Emulator trap (4.2 BSD).  */
+#define SIGINFO		29	/* Information request (BSD).  */
+#define SIGPWR		SIGINFO	/* Power failure imminent (System V).  */
 
-/* These are the hard limits of the kernel.  These values should not be
-   used directly at user level.  */
-#define __SIGRTMIN	32
-#define __SIGRTMAX	(_NSIG - 1)
+#undef	__SIGRTMAX
+#define __SIGRTMAX	64
 
 #endif	/* <signal.h> included.  */
diff --git a/sysdeps/unix/sysv/linux/bits/signum.h b/sysdeps/unix/sysv/linux/bits/signum.h
index e30efead0d..1a68255d02 100644
--- a/sysdeps/unix/sysv/linux/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/bits/signum.h
@@ -16,64 +16,43 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef	_SIGNAL_H
+#ifndef _BITS_SIGNUM_H
+#define _BITS_SIGNUM_H 1
 
-/* Fake signal functions.  */
-#define SIG_ERR	((__sighandler_t) -1)		/* Error return.  */
-#define SIG_DFL	((__sighandler_t) 0)		/* Default action.  */
-#define SIG_IGN	((__sighandler_t) 1)		/* Ignore signal.  */
-
-#ifdef __USE_XOPEN
-# define SIG_HOLD	((__sighandler_t) 2)	/* Add signal to hold mask.  */
+#ifndef _SIGNAL_H
+#error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
-
-/* Signals.  */
-#define	SIGHUP		1	/* Hangup (POSIX).  */
-#define	SIGINT		2	/* Interrupt (ANSI).  */
-#define	SIGQUIT		3	/* Quit (POSIX).  */
-#define	SIGILL		4	/* Illegal instruction (ANSI).  */
-#define	SIGTRAP		5	/* Trace trap (POSIX).  */
-#define	SIGABRT		6	/* Abort (ANSI).  */
-#define	SIGIOT		6	/* IOT trap (4.2 BSD).  */
-#define	SIGBUS		7	/* BUS error (4.2 BSD).  */
-#define	SIGFPE		8	/* Floating-point exception (ANSI).  */
-#define	SIGKILL		9	/* Kill, unblockable (POSIX).  */
-#define	SIGUSR1		10	/* User-defined signal 1 (POSIX).  */
-#define	SIGSEGV		11	/* Segmentation violation (ANSI).  */
-#define	SIGUSR2		12	/* User-defined signal 2 (POSIX).  */
-#define	SIGPIPE		13	/* Broken pipe (POSIX).  */
-#define	SIGALRM		14	/* Alarm clock (POSIX).  */
-#define	SIGTERM		15	/* Termination (ANSI).  */
-#define	SIGSTKFLT	16	/* Stack fault.  */
-#define	SIGCLD		SIGCHLD	/* Same as SIGCHLD (System V).  */
-#define	SIGCHLD		17	/* Child status has changed (POSIX).  */
-#define	SIGCONT		18	/* Continue (POSIX).  */
-#define	SIGSTOP		19	/* Stop, unblockable (POSIX).  */
-#define	SIGTSTP		20	/* Keyboard stop (POSIX).  */
-#define	SIGTTIN		21	/* Background read from tty (POSIX).  */
-#define	SIGTTOU		22	/* Background write to tty (POSIX).  */
-#define	SIGURG		23	/* Urgent condition on socket (4.2 BSD).  */
-#define	SIGXCPU		24	/* CPU limit exceeded (4.2 BSD).  */
-#define	SIGXFSZ		25	/* File size limit exceeded (4.2 BSD).  */
-#define	SIGVTALRM	26	/* Virtual alarm clock (4.2 BSD).  */
-#define	SIGPROF		27	/* Profiling alarm clock (4.2 BSD).  */
-#define	SIGWINCH	28	/* Window size change (4.3 BSD, Sun).  */
-#define	SIGPOLL		SIGIO	/* Pollable event occurred (System V).  */
-#define	SIGIO		29	/* I/O now possible (4.2 BSD).  */
-#define	SIGPWR		30	/* Power failure restart (System V).  */
-#define SIGSYS		31	/* Bad system call.  */
-#define SIGUNUSED	31
-
-#define	_NSIG		65	/* Biggest signal number + 1
-				   (including real-time signals).  */
-
-#define SIGRTMIN        (__libc_current_sigrtmin ())
-#define SIGRTMAX        (__libc_current_sigrtmax ())
-
-/* These are the hard limits of the kernel.  These values should not be
-   used directly at user level.  */
-#define __SIGRTMIN	32
-#define __SIGRTMAX	(_NSIG - 1)
+#include <bits/signum-generic.h>
+
+/* Adjustments and additions to the signal number constants for
+   most Linux systems.  */
+
+#define	SIGSTKFLT	16	/* Stack fault (obsolete).  */
+#define	SIGPWR		30	/* Power failure imminent.  */
+
+#undef	SIGBUS
+#define	SIGBUS		 7
+#undef	SIGUSR1
+#define	SIGUSR1		10
+#undef	SIGUSR2
+#define	SIGUSR2		12
+#undef	SIGCHLD
+#define	SIGCHLD		17
+#undef	SIGCONT
+#define	SIGCONT		18
+#undef	SIGSTOP
+#define	SIGSTOP		19
+#undef	SIGTSTP
+#define	SIGTSTP		20
+#undef	SIGURG
+#define	SIGURG		23
+#undef	SIGPOLL
+#define	SIGPOLL		29
+#undef	SIGSYS
+#define SIGSYS		31
+
+#undef	__SIGRTMAX
+#define __SIGRTMAX	64
 
 #endif	/* <signal.h> included.  */
diff --git a/sysdeps/unix/sysv/linux/hppa/bits/signum.h b/sysdeps/unix/sysv/linux/hppa/bits/signum.h
index 20c0b60c9f..5f54d1c893 100644
--- a/sysdeps/unix/sysv/linux/hppa/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/hppa/bits/signum.h
@@ -16,74 +16,60 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef	_SIGNAL_H
+#ifndef _BITS_SIGNUM_H
+#define _BITS_SIGNUM_H 1
 
-/* Fake signal functions.  */
-#define SIG_ERR	((__sighandler_t) -1)		/* Error return.  */
-#define SIG_DFL	((__sighandler_t) 0)		/* Default action.  */
-#define SIG_IGN	((__sighandler_t) 1)		/* Ignore signal.  */
-
-#ifdef __USE_XOPEN
-# define SIG_HOLD	((__sighandler_t) 2)	/* Add signal to hold mask.  */
+#ifndef _SIGNAL_H
+#error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
+#include <bits/signum-generic.h>
 
-/* Signals.  */
-#define	SIGHUP		1	/* Hangup (POSIX).  */
-#define	SIGINT		2	/* Interrupt (ANSI).  */
-#define	SIGQUIT		3	/* Quit (POSIX).  */
-#define	SIGILL		4	/* Illegal instruction (ANSI).  */
-#define	SIGTRAP		5	/* Trace trap (POSIX).  */
-#define	SIGABRT		6	/* Abort (ANSI).  */
-#define	SIGIOT		6	/* IOT trap (4.2 BSD).  */
-#define	SIGSTKFLT	7	/* Stack fault.  */
-#define	SIGFPE		8	/* Floating-point exception (ANSI).  */
-#define	SIGKILL		9	/* Kill, unblockable (POSIX).  */
-#define	SIGBUS		10	/* BUS error (4.2 BSD).  */
-#define	SIGSEGV		11	/* Segmentation violation (ANSI).  */
-#define	SIGXCPU		12	/* CPU limit exceeded (4.2 BSD).  */
-#define	SIGPIPE		13	/* Broken pipe (POSIX).  */
-#define	SIGALRM		14	/* Alarm clock (POSIX).  */
-#define	SIGTERM		15	/* Termination (ANSI).  */
-#define	SIGUSR1		16	/* User-defined signal 1 (POSIX).  */
-#define SIGUSR2		17	/* User-defined signal 2 (POSIX).  */
-#define	SIGCLD		SIGCHLD	/* Same as SIGCHLD (System V).  */
-#define	SIGCHLD		18	/* Child status has changed (POSIX).  */
-#define	SIGPWR		19	/* Power failure restart (System V).  */
-#define	SIGVTALRM	20	/* Virtual alarm clock (4.2 BSD).  */
-#define	SIGPROF		21	/* Profiling alarm clock (4.2 BSD).  */
-#define	SIGPOLL		SIGIO	/* Pollable event occurred (System V).  */
-#define	SIGIO		22	/* I/O now possible (4.2 BSD).  */
-#define	SIGWINCH	23	/* Window size change (4.3 BSD, Sun).  */
-#define	SIGSTOP		24	/* Stop, unblockable (POSIX).  */
-#define	SIGTSTP		25	/* Keyboard stop (POSIX).  */
-#define	SIGCONT		26	/* Continue (POSIX).  */
-#define	SIGTTIN		27	/* Background read from tty (POSIX).  */
-#define	SIGTTOU		28	/* Background write to tty (POSIX).  */
-#define	SIGURG		29	/* Urgent condition on socket (4.2 BSD).  */
-#define	SIGXFSZ		30	/* File size limit exceeded (4.2 BSD).  */
-#define SIGSYS		31	/* Bad system call.  */
-#define SIGUNUSED	31
+/* Adjustments and additions to the signal number constants for
+   Linux/HPPA.  These values were originally chosen for HP/UX
+   compatibility, but were renumbered as of kernel 3.17 and glibc 2.21
+   to accommodate software (notably systemd) that assumed at least 29
+   real-time signal numbers would be available.  SIGEMT and SIGLOST
+   were removed, and the values of SIGSTKFLT, SIGXCPU, XIGXFSZ, and
+   SIGSYS were changed, enabling __SIGRTMIN to be 32.  */
 
-#define	_NSIG		65	/* Biggest signal number + 1
-				   (including real-time signals).  */
+#define	SIGSTKFLT	 7	/* Stack fault (obsolete).  */
+#define	SIGPWR		19	/* Power failure imminent.  */
 
-#define SIGRTMIN        (__libc_current_sigrtmin ())
-#define SIGRTMAX        (__libc_current_sigrtmax ())
+#undef	SIGXCPU
+#define	SIGXCPU		12
+#undef	SIGUSR1
+#define	SIGUSR1		16
+#undef	SIGUSR2
+#define SIGUSR2		17
+#undef	SIGCHLD
+#define	SIGCHLD		18
+#undef	SIGVTALRM
+#define	SIGVTALRM	20
+#undef	SIGPROF
+#define	SIGPROF		21
+#undef	SIGPOLL
+#define	SIGPOLL		22
+#undef	SIGWINCH
+#define	SIGWINCH	23
+#undef	SIGSTOP
+#define	SIGSTOP		24
+#undef	SIGTSTP
+#define	SIGTSTP		25
+#undef	SIGCONT
+#define	SIGCONT		26
+#undef	SIGTTIN
+#define	SIGTTIN		27
+#undef	SIGTTOU
+#define	SIGTTOU		28
+#undef	SIGURG
+#define	SIGURG		29
+#undef	SIGXFSZ
+#define	SIGXFSZ		30
+#undef	SIGSYS
+#define SIGSYS		31
 
-/* These are the hard limits of the kernel.  These values should not be
-   used directly at user level.  */
-/* In the Linux kernel version 3.17, and glibc 2.21, the signal numbers
-   were rearranged in order to make hppa like every other arch. Previously
-   we started __SIGRTMIN at 37, and that meant several pieces of important
-   software, including systemd, would fail to build. To support systemd we
-   removed SIGEMT and SIGLOST, and rearranged the others according to
-   expected values. This is technically an ABI incompatible change, but
-   because zero applications use SIGSTKFLT, SIGXCPU, SIGXFSZ and SIGSYS
-   nothing broke.  Nothing uses SIGEMT and SIGLOST, and they were present
-   for HPUX compatibility which is no longer supported.  Thus because
-   nothing breaks we don't do any compatibility work here.  */
-#define __SIGRTMIN	32	/* Kernel > 3.17.  */
-#define __SIGRTMAX	(_NSIG - 1)
+#undef	__SIGRTMAX
+#define __SIGRTMAX	64
 
 #endif	/* <signal.h> included.  */
diff --git a/sysdeps/unix/sysv/linux/mips/bits/signum.h b/sysdeps/unix/sysv/linux/mips/bits/signum.h
index 6c31e01cd7..1672847212 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/signum.h
@@ -1,4 +1,4 @@
-/* Signal number definitions.  Linux version.
+/* Signal number definitions.  Linux/MIPS version.
    Copyright (C) 1995-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,63 +16,53 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef	_SIGNAL_H
+#ifndef _BITS_SIGNUM_H
+#define _BITS_SIGNUM_H 1
 
-/* Fake signal functions.  */
-#define SIG_ERR ((__sighandler_t) -1)		/* Error return.  */
-#define SIG_DFL ((__sighandler_t) 0)		/* Default action.  */
-#define SIG_IGN ((__sighandler_t) 1)		/* Ignore signal.  */
-
-#ifdef __USE_XOPEN
-# define SIG_HOLD	((__sighandler_t) 2)	/* Add signal to hold mask.  */
+#ifndef _SIGNAL_H
+#error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
+#include <bits/signum-generic.h>
 
-#define SIGHUP		 1	/* Hangup (POSIX).  */
-#define SIGINT		 2	/* Interrupt (ANSI).  */
-#define SIGQUIT		 3	/* Quit (POSIX).  */
-#define SIGILL		 4	/* Illegal instruction (ANSI).  */
-#define SIGTRAP		 5	/* Trace trap (POSIX).  */
-#define SIGIOT		 6	/* IOT trap (4.2 BSD).  */
-#define SIGABRT		 SIGIOT	/* Abort (ANSI).  */
-#define SIGEMT		 7
-#define SIGFPE		 8	/* Floating-point exception (ANSI).  */
-#define SIGKILL		 9	/* Kill, unblockable (POSIX).  */
-#define SIGBUS		10	/* BUS error (4.2 BSD).  */
-#define SIGSEGV		11	/* Segmentation violation (ANSI).  */
-#define SIGSYS		12
-#define SIGPIPE		13	/* Broken pipe (POSIX).  */
-#define SIGALRM		14	/* Alarm clock (POSIX).  */
-#define SIGTERM		15	/* Termination (ANSI).  */
-#define SIGUSR1		16	/* User-defined signal 1 (POSIX).  */
-#define SIGUSR2		17	/* User-defined signal 2 (POSIX).  */
-#define SIGCHLD		18	/* Child status has changed (POSIX).  */
-#define SIGCLD		SIGCHLD	/* Same as SIGCHLD (System V).  */
-#define SIGPWR		19	/* Power failure restart (System V).  */
-#define SIGWINCH	20	/* Window size change (4.3 BSD, Sun).  */
-#define SIGURG		21	/* Urgent condition on socket (4.2 BSD).  */
-#define SIGIO		22	/* I/O now possible (4.2 BSD).  */
-#define SIGPOLL		SIGIO	/* Pollable event occurred (System V).  */
-#define SIGSTOP		23	/* Stop, unblockable (POSIX).  */
-#define SIGTSTP		24	/* Keyboard stop (POSIX).  */
-#define SIGCONT		25	/* Continue (POSIX).  */
-#define SIGTTIN		26	/* Background read from tty (POSIX).  */
-#define SIGTTOU		27	/* Background write to tty (POSIX).  */
-#define SIGVTALRM	28	/* Virtual alarm clock (4.2 BSD).  */
-#define SIGPROF		29	/* Profiling alarm clock (4.2 BSD).  */
-#define SIGXCPU		30	/* CPU limit exceeded (4.2 BSD).  */
-#define SIGXFSZ		31	/* File size limit exceeded (4.2 BSD).  */
-
+/* Adjustments and additions to the signal number constants for
+   Linux/MIPS.  */
 
-#define _NSIG		128	/* Biggest signal number + 1
-				   (including real-time signals).  */
+#define SIGEMT		 7	/* Emulator trap.  */
+#define SIGPWR		19	/* Power failure imminent.  */
 
-#define SIGRTMIN	(__libc_current_sigrtmin ())
-#define SIGRTMAX	(__libc_current_sigrtmax ())
+#undef	SIGUSR1
+#define SIGUSR1		16
+#undef	SIGUSR2
+#define SIGUSR2		17
+#undef	SIGCHLD
+#define SIGCHLD		18
+#undef	SIGWINCH
+#define SIGWINCH	20
+#undef	SIGURG
+#define SIGURG		21
+#undef	SIGPOLL
+#define SIGPOLL		22
+#undef	SIGSTOP
+#define SIGSTOP		23
+#undef	SIGTSTP
+#define SIGTSTP		24
+#undef	SIGCONT
+#define SIGCONT		25
+#undef	SIGTTIN
+#define SIGTTIN		26
+#undef	SIGTTOU
+#define SIGTTOU		27
+#undef	SIGVTALRM
+#define SIGVTALRM	28
+#undef	SIGPROF
+#define SIGPROF		29
+#undef	SIGXCPU
+#define SIGXCPU		30
+#undef	SIGXFSZ
+#define SIGXFSZ		31
 
-/* These are the hard limits of the kernel.  These values should not be
-   used directly at user level.  */
-#define __SIGRTMIN	32
-#define __SIGRTMAX	(_NSIG - 1)
+#undef	__SIGRTMAX
+#define __SIGRTMAX	127
 
 #endif	/* <signal.h> included.  */
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/signum.h b/sysdeps/unix/sysv/linux/sparc/bits/signum.h
index a0c5be5fa5..25341ee42b 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/signum.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/signum.h
@@ -16,68 +16,24 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef	_SIGNAL_H
+#ifndef _BITS_SIGNUM_H
+#define _BITS_SIGNUM_H 1
 
-/* Fake signal functions.  */
-#define SIG_ERR ((__sighandler_t) -1) /* Error return.  */
-#define SIG_DFL ((__sighandler_t) 0) /* Default action.  */
-#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal.  */
-
-#ifdef __USE_XOPEN
-# define SIG_HOLD	((__sighandler_t) 2)	/* Add signal to hold mask.  */
+#ifndef _SIGNAL_H
+#error "Never include <bits/signum.h> directly; use <signal.h> instead."
 #endif
 
-/*
- * Linux/SPARC has different signal numbers that Linux/i386: I'm trying
- * to make it OSF/1 binary compatible, at least for normal binaries.
- */
-#define SIGHUP		 1
-#define SIGINT		 2
-#define SIGQUIT		 3
-#define SIGILL		 4
-#define SIGTRAP		 5
-#define SIGABRT		 6
-#define SIGIOT		 6
-#define SIGEMT           7
-#define SIGFPE		 8
-#define SIGKILL		 9
-#define SIGBUS          10
-#define SIGSEGV		11
-#define SIGSYS		12
-#define SIGPIPE		13
-#define SIGALRM		14
-#define SIGTERM		15
-#define SIGURG          16
-
-/* SunOS values which deviate from the Linux/i386 ones */
-#define SIGSTOP		17
-#define SIGTSTP		18
-#define SIGCONT		19
-#define SIGCHLD		20
-#define SIGCLD		SIGCHLD	/* Same as SIGCHLD (System V).  */
-#define SIGTTIN		21
-#define SIGTTOU		22
-#define SIGIO		23
-#define SIGPOLL		SIGIO   /* SysV name for SIGIO */
-#define SIGXCPU		24
-#define SIGXFSZ		25
-#define SIGVTALRM	26
-#define SIGPROF		27
-#define SIGWINCH	28
-#define SIGLOST		29
-#define SIGPWR          SIGLOST
-#define SIGUSR1		30
-#define SIGUSR2		31
+#include <bits/signum-generic.h>
 
-#define	_NSIG		65	/* Biggest signal number + 1
-				   (including real-time signals).  */
+/* Adjustments and additions to the signal number constants for
+   Linux/SPARC systems.  Signal values on this platform were chosen
+   for SunOS binary compatibility.  */
 
-#define SIGRTMIN        (__libc_current_sigrtmin ())
-#define SIGRTMAX        (__libc_current_sigrtmax ())
+#define SIGEMT		 7	/* Emulator trap.  */
+#define SIGLOST		29	/* Resource lost (Sun); server died (GNU).  */
+#define SIGPWR		SIGLOST	/* Power failure imminent (SysV).  */
 
-/* These are the hard limits of the kernel.  These values should not be
-   used directly at user level.  */
-#define __SIGRTMIN	32
-#define __SIGRTMAX	(_NSIG - 1)
+#undef	__SIGRTMAX
+#define __SIGRTMAX	64
 
 #endif	/* <signal.h> included.  */
diff --git a/sysdeps/unix/sysv/linux/tst-signal-numbers.sh b/sysdeps/unix/sysv/linux/tst-signal-numbers.sh
new file mode 100644
index 0000000000..bdd75fbc25
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-signal-numbers.sh
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Test that glibc's signal numbers match the kernel's.
+# Copyright (C) 2017 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+if [ -n "$BASH_VERSION" ]; then set -o pipefail; fi
+LC_ALL=C; export LC_ALL
+
+# We cannot use Linux's asm/signal.h to define signal numbers, because
+# it isn't sufficiently namespace-clean.  Instead, this test checks
+# that our signal numbers match the kernel's.  This script expects
+# "$@" to be $(CC) $(CPPFLAGS) as set by glibc's Makefiles, and $AWK
+# to be set in the environment.
+
+# Before doing anything else, fail if the compiler doesn't work.
+"$@" -E -xc -dM - < /dev/null > /dev/null
+
+tmpG=`mktemp -t signums_glibc.XXXXXXXXX`
+tmpK=`mktemp -t signums_kernel.XXXXXXXXX`
+trap "rm -f '$tmpG' '$tmpK'" 0
+
+# Filter out constants that aren't signal numbers.
+# If SIGPOLL is defined as SIGIO, swap it around so SIGIO is defined as
+# SIGPOLL. Similarly for SIGABRT and SIGIOT.
+# Discard obsolete signal numbers and unrelated constants:
+#    SIGCLD, SIGIOT, SIGSWI, SIGUNUSED.
+#    SIGSTKSZ, SIGRTMIN, SIGRTMAX.
+# Then sort the list.
+filter_defines ()
+{
+    $AWK '
+/^#define SIG[A-Z]+ ([0-9]+|SIG[A-Z0-9]+)$/ { signals[$2] = $3 }
+END {
+  if ("SIGPOLL" in signals && "SIGIO" in signals &&
+      signals["SIGPOLL"] == "SIGIO") {
+    signals["SIGPOLL"] = signals["SIGIO"]
+    signals["SIGIO"] = "SIGPOLL"
+  }
+  if ("SIGABRT" in signals && "SIGIOT" in signals &&
+      signals["SIGABRT"] == "SIGIOT") {
+    signals["SIGABRT"] = signals["SIGIOT"]
+    signals["SIGIOT"] = "SIGABRT"
+  }
+  for (sig in signals) {
+    if (sig !~ /^SIG(CLD|IOT|RT(MIN|MAX)|STKSZ|SWI|UNUSED)$/) {
+      printf("#define %s %s\n", sig, signals[sig])
+    }
+  }
+}' | sort
+}
+
+# $CC may contain command-line switches, so it should be word-split.
+printf '%s' '#define _GNU_SOURCE 1
+#include <signal.h>
+' |
+    "$@" -E -xc -dM - |
+    filter_defines > "$tmpG"
+
+printf '%s' '#define _GNU_SOURCE 1
+#define __ASSEMBLER__ 1
+#include <asm/signal.h>
+' |
+    "$@" -E -xc -dM - |
+    filter_defines > "$tmpK"
+
+if cmp -s "$tmpG" "$tmpK"; then
+    exit 0
+else
+    diff -u "$tmpG" "$tmpK"
+    exit 1
+fi