76b6d9
commit a8110b727e508f7ddf34f940af622e6f95435201
76b6d9
Author: Joseph Myers <joseph@codesourcery.com>
76b6d9
Date:   Mon Dec 10 22:27:13 2018 +0000
76b6d9
76b6d9
    Move tst-signal-numbers to Python.
76b6d9
    
76b6d9
    This patch converts the tst-signal-numbers test from shell + awk to
76b6d9
    Python.
76b6d9
    
76b6d9
    As with gen-as-const, the point is not so much that shell and awk are
76b6d9
    problematic for this code, as that it's useful to build up general
76b6d9
    infrastructure in Python for use of a range of code involving
76b6d9
    extracting values from C headers.  This patch moves some code from
76b6d9
    gen-as-const.py to a new glibcextract.py, which also gains functions
76b6d9
    relating to listing macros, and comparing the values of a set of
76b6d9
    macros from compiling two different pieces of code.
76b6d9
    
76b6d9
    It's not just signal numbers that should have such tests; pretty much
76b6d9
    any case where glibc copies constants from Linux kernel headers should
76b6d9
    have such tests that the values and sets of constants agree except
76b6d9
    where differences are known to be OK.  Much the same also applies to
76b6d9
    structure layouts (although testing those without hardcoding lists of
76b6d9
    fields to test will be more complicated).
76b6d9
    
76b6d9
    Given this patch, another test for a set of macros would essentially
76b6d9
    be just a call to glibcextract.compare_macro_consts (plus boilerplate
76b6d9
    code - and we could move to having separate text files defining such
76b6d9
    tests, like the .sym inputs to gen-as-const, so that only a single
76b6d9
    Python script is needed for most such tests).  Some such tests would
76b6d9
    of course need new features, e.g. where the set of macros changes in
76b6d9
    new kernel versions (so you need to allow new macro names on the
76b6d9
    kernel side if the kernel headers are newer than the version known to
76b6d9
    glibc, and extra macros on the glibc side if the kernel headers are
76b6d9
    older).  tst-syscall-list.sh could become a Python script that uses
76b6d9
    common code to generate lists of macros but does other things with its
76b6d9
    own custom logic.
76b6d9
    
76b6d9
    There are a few differences from the existing shell + awk test.
76b6d9
    Because the new test evaluates constants using the compiler, no
76b6d9
    special handling is needed any more for one signal name being defined
76b6d9
    to another.  Because asm/signal.h now needs to pass through the
76b6d9
    compiler, not just the preprocessor, stddef.h is included as well
76b6d9
    (given the asm/signal.h issue that it requires an externally provided
76b6d9
    definition of size_t).  The previous code defined __ASSEMBLER__ with
76b6d9
    asm/signal.h; this is removed (__ASSEMBLY__, a different macro,
76b6d9
    eliminates the requirement for stddef.h on some but not all
76b6d9
    architectures).
76b6d9
    
76b6d9
    Tested for x86_64, and with build-many-glibcs.py.
76b6d9
    
76b6d9
            * scripts/glibcextract.py: New file.
76b6d9
            * scripts/gen-as-const.py: Do not import os.path, re, subprocess
76b6d9
            or tempfile.  Import glibcexctract.
76b6d9
            (compute_c_consts): Remove.  Moved to glibcextract.py.
76b6d9
            (gen_test): Update reference to compute_c_consts.
76b6d9
            (main): Likewise.
76b6d9
            * sysdeps/unix/sysv/linux/tst-signal-numbers.py: New file.
76b6d9
            * sysdeps/unix/sysv/linux/tst-signal-numbers.sh: Remove.
76b6d9
            * sysdeps/unix/sysv/linux/Makefile
76b6d9
            ($(objpfx)tst-signal-numbers.out): Use tst-signal-numbers.py.
76b6d9
            Redirect stderr as well as stdout.
76b6d9
76b6d9
diff --git a/scripts/gen-as-const.py b/scripts/gen-as-const.py
76b6d9
index eb85ef1aa0f4934d..f85e359394acb1a4 100644
76b6d9
--- a/scripts/gen-as-const.py
76b6d9
+++ b/scripts/gen-as-const.py
76b6d9
@@ -24,68 +24,14 @@
76b6d9
 # A line giving just a name implies an expression consisting of just that name.
76b6d9
 
76b6d9
 import argparse
76b6d9
-import os.path
76b6d9
-import re
76b6d9
-import subprocess
76b6d9
-import tempfile
76b6d9
 
76b6d9
-
76b6d9
-def compute_c_consts(sym_data, cc):
76b6d9
-    """Compute the values of some C constants.
76b6d9
-
76b6d9
-    The first argument is a list whose elements are either strings
76b6d9
-    (preprocessor directives, or the special string 'START' to
76b6d9
-    indicate this function should insert its initial boilerplate text
76b6d9
-    in the output there) or pairs of strings (a name and a C
76b6d9
-    expression for the corresponding value).  Preprocessor directives
76b6d9
-    in the middle of the list may be used to select which constants
76b6d9
-    end up being evaluated using which expressions.
76b6d9
-
76b6d9
-    """
76b6d9
-    out_lines = []
76b6d9
-    for arg in sym_data:
76b6d9
-        if isinstance(arg, str):
76b6d9
-            if arg == 'START':
76b6d9
-                out_lines.append('void\ndummy (void)\n{')
76b6d9
-            else:
76b6d9
-                out_lines.append(arg)
76b6d9
-            continue
76b6d9
-        name = arg[0]
76b6d9
-        value = arg[1]
76b6d9
-        out_lines.append('asm ("@@@name@@@%s@@@value@@@%%0@@@end@@@" '
76b6d9
-                         ': : \"i\" ((long int) (%s)));'
76b6d9
-                         % (name, value))
76b6d9
-    out_lines.append('}')
76b6d9
-    out_lines.append('')
76b6d9
-    out_text = '\n'.join(out_lines)
76b6d9
-    with tempfile.TemporaryDirectory() as temp_dir:
76b6d9
-        c_file_name = os.path.join(temp_dir, 'test.c')
76b6d9
-        s_file_name = os.path.join(temp_dir, 'test.s')
76b6d9
-        with open(c_file_name, 'w') as c_file:
76b6d9
-            c_file.write(out_text)
76b6d9
-        # Compilation has to be from stdin to avoid the temporary file
76b6d9
-        # name being written into the generated dependencies.
76b6d9
-        cmd = ('%s -S -o %s -x c - < %s' % (cc, s_file_name, c_file_name))
76b6d9
-        subprocess.check_call(cmd, shell=True)
76b6d9
-        consts = {}
76b6d9
-        with open(s_file_name, 'r') as s_file:
76b6d9
-            for line in s_file:
76b6d9
-                match = re.search('@@@name@@@([^@]*)'
76b6d9
-                                  '@@@value@@@[^0-9Xxa-fA-F-]*'
76b6d9
-                                  '([0-9Xxa-fA-F-]+).*@@@end@@@', line)
76b6d9
-                if match:
76b6d9
-                    if (match.group(1) in consts
76b6d9
-                        and match.group(2) != consts[match.group(1)]):
76b6d9
-                        raise ValueError('duplicate constant %s'
76b6d9
-                                         % match.group(1))
76b6d9
-                    consts[match.group(1)] = match.group(2)
76b6d9
-        return consts
76b6d9
+import glibcextract
76b6d9
 
76b6d9
 
76b6d9
 def gen_test(sym_data):
76b6d9
     """Generate a test for the values of some C constants.
76b6d9
 
76b6d9
-    The first argument is as for compute_c_consts.
76b6d9
+    The first argument is as for glibcextract.compute_c_consts.
76b6d9
 
76b6d9
     """
76b6d9
     out_lines = []
76b6d9
@@ -158,7 +104,7 @@ def main():
76b6d9
     if args.test:
76b6d9
         print(gen_test(sym_data))
76b6d9
     else:
76b6d9
-        consts = compute_c_consts(sym_data, args.cc)
76b6d9
+        consts = glibcextract.compute_c_consts(sym_data, args.cc)
76b6d9
         print(''.join('#define %s %s\n' % c for c in sorted(consts.items())), end='')
76b6d9
 
76b6d9
 if __name__ == '__main__':
76b6d9
diff --git a/scripts/glibcextract.py b/scripts/glibcextract.py
76b6d9
new file mode 100644
76b6d9
index 0000000000000000..ecc4d5b6cc387c7d
76b6d9
--- /dev/null
76b6d9
+++ b/scripts/glibcextract.py
76b6d9
@@ -0,0 +1,162 @@
76b6d9
+#!/usr/bin/python3
76b6d9
+# Extract information from C headers.
76b6d9
+# Copyright (C) 2018 Free Software Foundation, Inc.
76b6d9
+# This file is part of the GNU C Library.
76b6d9
+#
76b6d9
+# The GNU C Library is free software; you can redistribute it and/or
76b6d9
+# modify it under the terms of the GNU Lesser General Public
76b6d9
+# License as published by the Free Software Foundation; either
76b6d9
+# version 2.1 of the License, or (at your option) any later version.
76b6d9
+#
76b6d9
+# The GNU C Library is distributed in the hope that it will be useful,
76b6d9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
76b6d9
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
76b6d9
+# Lesser General Public License for more details.
76b6d9
+#
76b6d9
+# You should have received a copy of the GNU Lesser General Public
76b6d9
+# License along with the GNU C Library; if not, see
76b6d9
+# <http://www.gnu.org/licenses/>.
76b6d9
+
76b6d9
+import os.path
76b6d9
+import re
76b6d9
+import subprocess
76b6d9
+import tempfile
76b6d9
+
76b6d9
+
76b6d9
+def compute_c_consts(sym_data, cc):
76b6d9
+    """Compute the values of some C constants.
76b6d9
+
76b6d9
+    The first argument is a list whose elements are either strings
76b6d9
+    (preprocessor directives, or the special string 'START' to
76b6d9
+    indicate this function should insert its initial boilerplate text
76b6d9
+    in the output there) or pairs of strings (a name and a C
76b6d9
+    expression for the corresponding value).  Preprocessor directives
76b6d9
+    in the middle of the list may be used to select which constants
76b6d9
+    end up being evaluated using which expressions.
76b6d9
+
76b6d9
+    """
76b6d9
+    out_lines = []
76b6d9
+    for arg in sym_data:
76b6d9
+        if isinstance(arg, str):
76b6d9
+            if arg == 'START':
76b6d9
+                out_lines.append('void\ndummy (void)\n{')
76b6d9
+            else:
76b6d9
+                out_lines.append(arg)
76b6d9
+            continue
76b6d9
+        name = arg[0]
76b6d9
+        value = arg[1]
76b6d9
+        out_lines.append('asm ("@@@name@@@%s@@@value@@@%%0@@@end@@@" '
76b6d9
+                         ': : \"i\" ((long int) (%s)));'
76b6d9
+                         % (name, value))
76b6d9
+    out_lines.append('}')
76b6d9
+    out_lines.append('')
76b6d9
+    out_text = '\n'.join(out_lines)
76b6d9
+    with tempfile.TemporaryDirectory() as temp_dir:
76b6d9
+        c_file_name = os.path.join(temp_dir, 'test.c')
76b6d9
+        s_file_name = os.path.join(temp_dir, 'test.s')
76b6d9
+        with open(c_file_name, 'w') as c_file:
76b6d9
+            c_file.write(out_text)
76b6d9
+        # Compilation has to be from stdin to avoid the temporary file
76b6d9
+        # name being written into the generated dependencies.
76b6d9
+        cmd = ('%s -S -o %s -x c - < %s' % (cc, s_file_name, c_file_name))
76b6d9
+        subprocess.check_call(cmd, shell=True)
76b6d9
+        consts = {}
76b6d9
+        with open(s_file_name, 'r') as s_file:
76b6d9
+            for line in s_file:
76b6d9
+                match = re.search('@@@name@@@([^@]*)'
76b6d9
+                                  '@@@value@@@[^0-9Xxa-fA-F-]*'
76b6d9
+                                  '([0-9Xxa-fA-F-]+).*@@@end@@@', line)
76b6d9
+                if match:
76b6d9
+                    if (match.group(1) in consts
76b6d9
+                        and match.group(2) != consts[match.group(1)]):
76b6d9
+                        raise ValueError('duplicate constant %s'
76b6d9
+                                         % match.group(1))
76b6d9
+                    consts[match.group(1)] = match.group(2)
76b6d9
+        return consts
76b6d9
+
76b6d9
+
76b6d9
+def list_macros(source_text, cc):
76b6d9
+    """List the preprocessor macros defined by the given source code.
76b6d9
+
76b6d9
+    The return value is a pair of dicts, the first one mapping macro
76b6d9
+    names to their expansions and the second one mapping macro names
76b6d9
+    to lists of their arguments, or to None for object-like macros.
76b6d9
+
76b6d9
+    """
76b6d9
+    with tempfile.TemporaryDirectory() as temp_dir:
76b6d9
+        c_file_name = os.path.join(temp_dir, 'test.c')
76b6d9
+        i_file_name = os.path.join(temp_dir, 'test.i')
76b6d9
+        with open(c_file_name, 'w') as c_file:
76b6d9
+            c_file.write(source_text)
76b6d9
+        cmd = ('%s -E -dM -o %s %s' % (cc, i_file_name, c_file_name))
76b6d9
+        subprocess.check_call(cmd, shell=True)
76b6d9
+        macros_exp = {}
76b6d9
+        macros_args = {}
76b6d9
+        with open(i_file_name, 'r') as i_file:
76b6d9
+            for line in i_file:
76b6d9
+                match = re.fullmatch('#define ([0-9A-Za-z_]+)(.*)\n', line)
76b6d9
+                if not match:
76b6d9
+                    raise ValueError('bad -dM output line: %s' % line)
76b6d9
+                name = match.group(1)
76b6d9
+                value = match.group(2)
76b6d9
+                if value.startswith(' '):
76b6d9
+                    value = value[1:]
76b6d9
+                    args = None
76b6d9
+                elif value.startswith('('):
76b6d9
+                    match = re.fullmatch(r'\((.*?)\) (.*)', value)
76b6d9
+                    if not match:
76b6d9
+                        raise ValueError('bad -dM output line: %s' % line)
76b6d9
+                    args = match.group(1).split(',')
76b6d9
+                    value = match.group(2)
76b6d9
+                else:
76b6d9
+                    raise ValueError('bad -dM output line: %s' % line)
76b6d9
+                if name in macros_exp:
76b6d9
+                    raise ValueError('duplicate macro: %s' % line)
76b6d9
+                macros_exp[name] = value
76b6d9
+                macros_args[name] = args
76b6d9
+    return macros_exp, macros_args
76b6d9
+
76b6d9
+
76b6d9
+def compute_macro_consts(source_text, cc, macro_re, exclude_re=None):
76b6d9
+    """Compute the integer constant values of macros defined by source_text.
76b6d9
+
76b6d9
+    Macros must match the regular expression macro_re, and if
76b6d9
+    exclude_re is defined they must not match exclude_re.  Values are
76b6d9
+    computed with compute_c_consts.
76b6d9
+
76b6d9
+    """
76b6d9
+    macros_exp, macros_args = list_macros(source_text, cc)
76b6d9
+    macros_set = {m for m in macros_exp
76b6d9
+                  if (macros_args[m] is None
76b6d9
+                      and re.fullmatch(macro_re, m)
76b6d9
+                      and (exclude_re is None
76b6d9
+                           or not re.fullmatch(exclude_re, m)))}
76b6d9
+    sym_data = [source_text, 'START']
76b6d9
+    sym_data.extend(sorted((m, m) for m in macros_set))
76b6d9
+    return compute_c_consts(sym_data, cc)
76b6d9
+
76b6d9
+
76b6d9
+def compare_macro_consts(source_1, source_2, cc, macro_re, exclude_re=None):
76b6d9
+    """Compare the values of macros defined by two different sources.
76b6d9
+
76b6d9
+    The sources would typically be includes of a glibc header and a
76b6d9
+    kernel header.  Return 1 if there were any differences, 0 if the
76b6d9
+    macro values were the same.
76b6d9
+
76b6d9
+    """
76b6d9
+    macros_1 = compute_macro_consts(source_1, cc, macro_re, exclude_re)
76b6d9
+    macros_2 = compute_macro_consts(source_2, cc, macro_re, exclude_re)
76b6d9
+    if macros_1 == macros_2:
76b6d9
+        return 0
76b6d9
+    print('First source:\n%s\n' % source_1)
76b6d9
+    print('Second source:\n%s\n' % source_2)
76b6d9
+    for name, value in sorted(macros_1.items()):
76b6d9
+        if name not in macros_2:
76b6d9
+            print('Only in first source: %s' % name)
76b6d9
+        elif macros_1[name] != macros_2[name]:
76b6d9
+            print('Different values for %s: %s != %s'
76b6d9
+                  % (name, macros_1[name], macros_2[name]))
76b6d9
+    for name in sorted(macros_2.keys()):
76b6d9
+        if name not in macros_1:
76b6d9
+            print('Only in second source: %s' % name)
76b6d9
+    return 1
76b6d9
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
76b6d9
index bb055f9d6b841ff5..9c10ee53b26e1b1b 100644
76b6d9
--- a/sysdeps/unix/sysv/linux/Makefile
76b6d9
+++ b/sysdeps/unix/sysv/linux/Makefile
76b6d9
@@ -113,11 +113,14 @@ tests-special += $(objpfx)tst-signal-numbers.out
76b6d9
 # in this context, but signal.c includes signal.h and not much else so it'll
76b6d9
 # be conservatively correct.
76b6d9
 $(objpfx)tst-signal-numbers.out: \
76b6d9
-		../sysdeps/unix/sysv/linux/tst-signal-numbers.sh \
76b6d9
+		../sysdeps/unix/sysv/linux/tst-signal-numbers.py \
76b6d9
 		$(objpfx)signal.o*
76b6d9
-	AWK=$(AWK) $(SHELL) ../sysdeps/unix/sysv/linux/tst-signal-numbers.sh \
76b6d9
-	$(CC) $(patsubst -DMODULE_NAME=%,-DMODULE_NAME=testsuite,$(CPPFLAGS)) \
76b6d9
-	< /dev/null > $@; $(evaluate-test)
76b6d9
+	PYTHONPATH=../scripts \
76b6d9
+	$(PYTHON) ../sysdeps/unix/sysv/linux/tst-signal-numbers.py \
76b6d9
+		   --cc="$(CC) $(patsubst -DMODULE_NAME=%, \
76b6d9
+					  -DMODULE_NAME=testsuite, \
76b6d9
+					  $(CPPFLAGS))" \
76b6d9
+	< /dev/null > $@ 2>&1; $(evaluate-test)
76b6d9
 endif
76b6d9
 
76b6d9
 ifeq ($(subdir),socket)
76b6d9
diff --git a/sysdeps/unix/sysv/linux/tst-signal-numbers.py b/sysdeps/unix/sysv/linux/tst-signal-numbers.py
76b6d9
new file mode 100644
76b6d9
index 0000000000000000..48c63d1218e8303d
76b6d9
--- /dev/null
76b6d9
+++ b/sysdeps/unix/sysv/linux/tst-signal-numbers.py
76b6d9
@@ -0,0 +1,48 @@
76b6d9
+#!/usr/bin/python3
76b6d9
+# Test that glibc's signal numbers match the kernel's.
76b6d9
+# Copyright (C) 2018 Free Software Foundation, Inc.
76b6d9
+# This file is part of the GNU C Library.
76b6d9
+#
76b6d9
+# The GNU C Library is free software; you can redistribute it and/or
76b6d9
+# modify it under the terms of the GNU Lesser General Public
76b6d9
+# License as published by the Free Software Foundation; either
76b6d9
+# version 2.1 of the License, or (at your option) any later version.
76b6d9
+#
76b6d9
+# The GNU C Library is distributed in the hope that it will be useful,
76b6d9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
76b6d9
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
76b6d9
+# Lesser General Public License for more details.
76b6d9
+#
76b6d9
+# You should have received a copy of the GNU Lesser General Public
76b6d9
+# License along with the GNU C Library; if not, see
76b6d9
+# <http://www.gnu.org/licenses/>.
76b6d9
+
76b6d9
+import argparse
76b6d9
+import sys
76b6d9
+
76b6d9
+import glibcextract
76b6d9
+
76b6d9
+
76b6d9
+def main():
76b6d9
+    """The main entry point."""
76b6d9
+    parser = argparse.ArgumentParser(
76b6d9
+        description="Test that glibc's signal numbers match the kernel's.")
76b6d9
+    parser.add_argument('--cc', metavar='CC',
76b6d9
+                        help='C compiler (including options) to use')
76b6d9
+    args = parser.parse_args()
76b6d9
+    sys.exit(glibcextract.compare_macro_consts(
76b6d9
+        '#define _GNU_SOURCE 1\n'
76b6d9
+        '#include <signal.h>\n',
76b6d9
+        '#define _GNU_SOURCE 1\n'
76b6d9
+        '#include <stddef.h>\n'
76b6d9
+        '#include <asm/signal.h>\n',
76b6d9
+        args.cc,
76b6d9
+        # Filter out constants that aren't signal numbers.
76b6d9
+        'SIG[A-Z]+',
76b6d9
+        # Discard obsolete signal numbers and unrelated constants:
76b6d9
+        #    SIGCLD, SIGIOT, SIGSWI, SIGUNUSED.
76b6d9
+        #    SIGSTKSZ, SIGRTMIN, SIGRTMAX.
76b6d9
+        'SIG(CLD|IOT|RT(MIN|MAX)|STKSZ|SWI|UNUSED)'))
76b6d9
+
76b6d9
+if __name__ == '__main__':
76b6d9
+    main()
76b6d9
diff --git a/sysdeps/unix/sysv/linux/tst-signal-numbers.sh b/sysdeps/unix/sysv/linux/tst-signal-numbers.sh
76b6d9
deleted file mode 100644
76b6d9
index e1f7be0337c720a6..0000000000000000
76b6d9
--- a/sysdeps/unix/sysv/linux/tst-signal-numbers.sh
76b6d9
+++ /dev/null
76b6d9
@@ -1,86 +0,0 @@
76b6d9
-#! /bin/sh
76b6d9
-# Test that glibc's signal numbers match the kernel's.
76b6d9
-# Copyright (C) 2017-2018 Free Software Foundation, Inc.
76b6d9
-# This file is part of the GNU C Library.
76b6d9
-
76b6d9
-# The GNU C Library is free software; you can redistribute it and/or
76b6d9
-# modify it under the terms of the GNU Lesser General Public
76b6d9
-# License as published by the Free Software Foundation; either
76b6d9
-# version 2.1 of the License, or (at your option) any later version.
76b6d9
-
76b6d9
-# The GNU C Library is distributed in the hope that it will be useful,
76b6d9
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
76b6d9
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
76b6d9
-# Lesser General Public License for more details.
76b6d9
-
76b6d9
-# You should have received a copy of the GNU Lesser General Public
76b6d9
-# License along with the GNU C Library; if not, see
76b6d9
-# <http://www.gnu.org/licenses/>.
76b6d9
-
76b6d9
-set -e
76b6d9
-if [ -n "$BASH_VERSION" ]; then set -o pipefail; fi
76b6d9
-LC_ALL=C; export LC_ALL
76b6d9
-
76b6d9
-# We cannot use Linux's asm/signal.h to define signal numbers, because
76b6d9
-# it isn't sufficiently namespace-clean.  Instead, this test checks
76b6d9
-# that our signal numbers match the kernel's.  This script expects
76b6d9
-# "$@" to be $(CC) $(CPPFLAGS) as set by glibc's Makefiles, and $AWK
76b6d9
-# to be set in the environment.
76b6d9
-
76b6d9
-# Before doing anything else, fail if the compiler doesn't work.
76b6d9
-"$@" -E -xc -dM - < /dev/null > /dev/null
76b6d9
-
76b6d9
-tmpG=`mktemp -t signums_glibc.XXXXXXXXX`
76b6d9
-tmpK=`mktemp -t signums_kernel.XXXXXXXXX`
76b6d9
-trap "rm -f '$tmpG' '$tmpK'" 0
76b6d9
-
76b6d9
-# Filter out constants that aren't signal numbers.
76b6d9
-# If SIGPOLL is defined as SIGIO, swap it around so SIGIO is defined as
76b6d9
-# SIGPOLL. Similarly for SIGABRT and SIGIOT.
76b6d9
-# Discard obsolete signal numbers and unrelated constants:
76b6d9
-#    SIGCLD, SIGIOT, SIGSWI, SIGUNUSED.
76b6d9
-#    SIGSTKSZ, SIGRTMIN, SIGRTMAX.
76b6d9
-# Then sort the list.
76b6d9
-filter_defines ()
76b6d9
-{
76b6d9
-    $AWK '
76b6d9
-/^#define SIG[A-Z]+ ([0-9]+|SIG[A-Z0-9]+)$/ { signals[$2] = $3 }
76b6d9
-END {
76b6d9
-  if ("SIGPOLL" in signals && "SIGIO" in signals &&
76b6d9
-      signals["SIGPOLL"] == "SIGIO") {
76b6d9
-    signals["SIGPOLL"] = signals["SIGIO"]
76b6d9
-    signals["SIGIO"] = "SIGPOLL"
76b6d9
-  }
76b6d9
-  if ("SIGABRT" in signals && "SIGIOT" in signals &&
76b6d9
-      signals["SIGABRT"] == "SIGIOT") {
76b6d9
-    signals["SIGABRT"] = signals["SIGIOT"]
76b6d9
-    signals["SIGIOT"] = "SIGABRT"
76b6d9
-  }
76b6d9
-  for (sig in signals) {
76b6d9
-    if (sig !~ /^SIG(CLD|IOT|RT(MIN|MAX)|STKSZ|SWI|UNUSED)$/) {
76b6d9
-      printf("#define %s %s\n", sig, signals[sig])
76b6d9
-    }
76b6d9
-  }
76b6d9
-}' | sort
76b6d9
-}
76b6d9
-
76b6d9
-# $CC may contain command-line switches, so it should be word-split.
76b6d9
-printf '%s' '#define _GNU_SOURCE 1
76b6d9
-#include <signal.h>
76b6d9
-' |
76b6d9
-    "$@" -E -xc -dM - |
76b6d9
-    filter_defines > "$tmpG"
76b6d9
-
76b6d9
-printf '%s' '#define _GNU_SOURCE 1
76b6d9
-#define __ASSEMBLER__ 1
76b6d9
-#include <asm/signal.h>
76b6d9
-' |
76b6d9
-    "$@" -E -xc -dM - |
76b6d9
-    filter_defines > "$tmpK"
76b6d9
-
76b6d9
-if cmp -s "$tmpG" "$tmpK"; then
76b6d9
-    exit 0
76b6d9
-else
76b6d9
-    diff -u "$tmpG" "$tmpK"
76b6d9
-    exit 1
76b6d9
-fi