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