public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] sim: nltvals: pull target errno out into a dedicated source file
@ 2021-10-31  8:41 Mike Frysinger
  2021-10-31  8:41 ` [PATCH 2/2] sim: nltvals: pull target signal " Mike Frysinger
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2021-10-31  8:41 UTC (permalink / raw)
  To: gdb-patches

The current system maintains a list of target errno constants in the
nltvals.def file, then runs a build-time tool to turn that into a C
file.  This list of errno values is the same for all arches, so we
don't need the arch-specific flexibility.  Further, these are only
for newlib/libgloss environments, which makes it confusing to support
other userland runtimes (like Linux).  Let's simplify to make this
easier to understand & build.  We don't namespace the variables yet,
but sets up the framework for it.

Create a new target-newlib-errno.c template file.  The template file
is hand written, but the inline map is still automatically generated.

This allows us to move it to the common set of objects so it's only
built once in a multi-target build.

Now we can remove the output from the gentmap build-time tool since
it's checked into the tree.

Then we stop including the errno lists in nltvals.def since nothing
uses it.
---
 sim/Makefile.in                  |  19 ++
 sim/common/Make-common.in        |   1 +
 sim/common/gennltvals.py         | 109 ++++++++----
 sim/common/gentmap.c             |  20 ---
 sim/common/local.mk              |   1 +
 sim/common/nltvals.def           |  92 ----------
 sim/common/target-newlib-errno.c | 289 +++++++++++++++++++++++++++++++
 7 files changed, 384 insertions(+), 147 deletions(-)
 create mode 100644 sim/common/target-newlib-errno.c

diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index cdad4a53d4bc..5db835713e7c 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -231,6 +231,7 @@ EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \
 COMMON_OBJS_NAMES = \
 	portability.o \
 	sim-load.o \
+	target-newlib-errno.o \
 	version.o
 COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/common_libcommon_a-%)
 
diff --git a/sim/common/gennltvals.py b/sim/common/gennltvals.py
index 955ace343110..3006f7f58fe4 100755
--- a/sim/common/gennltvals.py
+++ b/sim/common/gennltvals.py
@@ -63,8 +63,43 @@ FILE_HEADER = f"""\
 /* This file is machine generated by {PROG}.  */\
 """
 
+# Used to update sections of files.
+START_MARKER = 'gennltvals: START'
+END_MARKER = 'gennltvals: END'
 
-def gentvals(output: TextIO, cpp: str, srctype: str, srcdir: Path,
+
+def extract_syms(cpp: str, srcdir: Path,
+                 headers: Iterable[str],
+                 pattern: str,
+                 filter: str = r'^$') -> dict:
+    """Extract all the symbols from |headers| matching |pattern| using |cpp|."""
+    srcfile = ''.join(f'#include <{x}>\n' for x in headers)
+    syms = set()
+    define_pattern = re.compile(r'^#\s*define\s+(' + pattern + ')')
+    filter_pattern = re.compile(filter)
+    for header in headers:
+        with open(srcdir / header, 'r', encoding='utf-8') as fp:
+            data = fp.read()
+        for line in data.splitlines():
+            m = define_pattern.match(line)
+            if m and not filter_pattern.search(line):
+                syms.add(m.group(1))
+    for sym in syms:
+        srcfile += f'#ifdef {sym}\nDEFVAL "{sym}" {sym}\n#endif\n'
+
+    result = subprocess.run(
+        f'{cpp} -E -I"{srcdir}" -', shell=True, check=True, encoding='utf-8',
+        input=srcfile, capture_output=True)
+    ret = {}
+    for line in result.stdout.splitlines():
+        if line.startswith('DEFVAL '):
+            _, sym, val = line.split()
+            ret[sym.strip('"')] = val
+    return ret
+
+
+def gentvals(output_dir: Path, output: TextIO,
+             cpp: str, srctype: str, srcdir: Path,
              headers: Iterable[str],
              pattern: str,
              filter: str = r'^$',
@@ -80,6 +115,29 @@ def gentvals(output: TextIO, cpp: str, srctype: str, srcdir: Path,
         fullpath = srcdir / header
         assert fullpath.exists(), f'{fullpath} does not exist'
 
+    syms = extract_syms(cpp, srcdir, headers, pattern, filter)
+
+    # If we have a map file, use it directly.
+    target_map = output_dir / f'target-newlib-{srctype}.c'
+    if target_map.exists():
+        old_lines = target_map.read_text().splitlines()
+        start_i = end_i = None
+        for i, line in enumerate(old_lines):
+            if START_MARKER in line:
+                start_i = i
+            if END_MARKER in line:
+                end_i = i
+        assert start_i and end_i
+        new_lines = old_lines[0:start_i + 1]
+        new_lines.extend(
+            f'#ifdef {sym}\n'
+            f'  {{ "{sym}", {sym}, {val} }},\n'
+            f'#endif' for sym, val in sorted(syms.items()))
+        new_lines.extend(old_lines[end_i:])
+        target_map.write_text('\n'.join(new_lines) + '\n')
+        return
+
+    # Fallback to classic nltvals.def.
     if target is not None:
         print(f'#ifdef NL_TARGET_{target}', file=output)
     print(f'#ifdef {srctype}_defs', file=output)
@@ -91,27 +149,8 @@ def gentvals(output: TextIO, cpp: str, srctype: str, srcdir: Path,
     else:
         print(f'/* begin {target} {srctype} target macros */', file=output)
 
-    # Extract all the symbols.
-    srcfile = ''.join(f'#include <{x}>\n' for x in headers)
-    syms = set()
-    define_pattern = re.compile(r'^#\s*define\s+(' + pattern + ')')
-    filter_pattern = re.compile(filter)
-    for header in headers:
-        with open(srcdir / header, 'r', encoding='utf-8') as fp:
-            data = fp.read()
-        for line in data.splitlines():
-            m = define_pattern.match(line)
-            if m and not filter_pattern.search(line):
-                syms.add(m.group(1))
-    for sym in sorted(syms):
-        srcfile += f'#ifdef {sym}\nDEFVAL {{ "{sym}", {sym} }},\n#endif\n'
-
-    result = subprocess.run(
-        f'{cpp} -E -I"{srcdir}" -', shell=True, check=True, encoding='utf-8',
-        input=srcfile, capture_output=True)
-    for line in result.stdout.splitlines():
-        if line.startswith('DEFVAL '):
-            print(line[6:].rstrip(), file=output)
+    for sym, val in sorted(syms.items()):
+        print(f' {{ "{sym}", {val} }},', file=output)
 
     print(f'#undef {srctype}_defs', file=output)
     if target is None:
@@ -122,37 +161,37 @@ def gentvals(output: TextIO, cpp: str, srctype: str, srcdir: Path,
     print('#endif', file=output)
 
 
-def gen_common(output: TextIO, newlib: Path, cpp: str):
+def gen_common(output_dir: Path, output: TextIO, newlib: Path, cpp: str):
     """Generate the common C library constants.
 
     No arch should override these.
     """
-    gentvals(output, cpp, 'errno', newlib / 'newlib/libc/include',
+    gentvals(output_dir, output, cpp, 'errno', newlib / 'newlib/libc/include',
              ('errno.h', 'sys/errno.h'), 'E[A-Z0-9]*')
 
-    gentvals(output, cpp, 'signal', newlib / 'newlib/libc/include',
+    gentvals(output_dir, output, cpp, 'signal', newlib / 'newlib/libc/include',
              ('signal.h', 'sys/signal.h'), r'SIG[A-Z0-9]*', filter=r'SIGSTKSZ')
 
-    gentvals(output, cpp, 'open', newlib / 'newlib/libc/include',
+    gentvals(output_dir, output, cpp, 'open', newlib / 'newlib/libc/include',
              ('fcntl.h', 'sys/fcntl.h', 'sys/_default_fcntl.h'), r'O_[A-Z0-9]*')
 
 
-def gen_targets(output: TextIO, newlib: Path, cpp: str):
+def gen_targets(output_dir: Path, output: TextIO, newlib: Path, cpp: str):
     """Generate the target-specific lists."""
     for target, subdir in sorted(TARGET_DIRS.items()):
-        gentvals(output, cpp, 'sys', newlib / subdir, ('syscall.h',),
-                 r'SYS_[_a-zA-Z0-9]*', target=target)
+        gentvals(output_dir, output, cpp, 'sys', newlib / subdir,
+                 ('syscall.h',), r'SYS_[_a-zA-Z0-9]*', target=target)
 
     # Then output the common syscall targets.
-    gentvals(output, cpp, 'sys', newlib / 'libgloss', ('syscall.h',),
-             r'SYS_[_a-zA-Z0-9]*')
+    gentvals(output_dir, output, cpp, 'sys', newlib / 'libgloss',
+             ('syscall.h',), r'SYS_[_a-zA-Z0-9]*')
 
 
-def gen(output: TextIO, newlib: Path, cpp: str):
+def gen(output_dir: Path, output: TextIO, newlib: Path, cpp: str):
     """Generate all the things!"""
     print(FILE_HEADER, file=output)
-    gen_common(output, newlib, cpp)
-    gen_targets(output, newlib, cpp)
+    gen_common(output_dir, output, newlib, cpp)
+    gen_targets(output_dir, output, newlib, cpp)
 
 
 def get_parser() -> argparse.ArgumentParser:
@@ -212,7 +251,7 @@ def main(argv: List[str]) -> int:
 
     output = (opts.output / 'nltvals.def').open('w', encoding='utf-8')
 
-    gen(output, opts.newlib, opts.cpp)
+    gen(opts.output, output, opts.newlib, opts.cpp)
     return 0
 
 
diff --git a/sim/common/gentmap.c b/sim/common/gentmap.c
index 9f30e66e378b..8e6e3aeda325 100644
--- a/sim/common/gentmap.c
+++ b/sim/common/gentmap.c
@@ -16,13 +16,6 @@ static struct tdefs sys_tdefs[] = {
   { 0, 0 }
 };
 
-static struct tdefs errno_tdefs[] =  {
-#define errno_defs
-#include "nltvals.def"
-#undef errno_defs
-  { 0, 0 }
-};
-
 static struct tdefs signal_tdefs[] = {
 #define signal_defs
 #include "nltvals.def"
@@ -75,7 +68,6 @@ gen_targ_map_c (void)
   printf ("/* This file is machine generated by gentmap.c.  */\n\n");
 
   printf ("#include \"defs.h\"\n");
-  printf ("#include <errno.h>\n");
   printf ("#include <fcntl.h>\n");
   printf ("#include <signal.h>\n");
   printf ("#include \"ansidecl.h\"\n");
@@ -95,18 +87,6 @@ gen_targ_map_c (void)
   printf ("  { 0, -1, -1 }\n");
   printf ("};\n\n");
 
-  printf ("/* errno mapping table */\n");
-  printf ("CB_TARGET_DEFS_MAP cb_init_errno_map[] = {\n");
-  for (t = &errno_tdefs[0]; t->symbol; ++t)
-    {
-      printf ("#define TARGET_%s %d\n", t->symbol, t->value);
-      printf ("#ifdef %s\n", t->symbol);
-      printf ("  { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
-      printf ("#endif\n");
-    }
-  printf ("  { 0, 0, 0 }\n");
-  printf ("};\n\n");
-
   printf ("/* signals mapping table */\n");
   printf ("CB_TARGET_DEFS_MAP cb_init_signal_map[] = {\n");
   for (t = &signal_tdefs[0]; t->symbol; ++t)
diff --git a/sim/common/local.mk b/sim/common/local.mk
index 25c7e5beb1f9..71a931715c2d 100644
--- a/sim/common/local.mk
+++ b/sim/common/local.mk
@@ -36,6 +36,7 @@ noinst_LIBRARIES += %D%/libcommon.a
 %C%_libcommon_a_SOURCES = \
 	%D%/portability.c \
 	%D%/sim-load.c \
+	%D%/target-newlib-errno.c \
 	%D%/version.c
 
 %D%/version.c: %D%/version.c-stamp ; @true
diff --git a/sim/common/nltvals.def b/sim/common/nltvals.def
index 8bc6ae59026d..5e72e596ee80 100644
--- a/sim/common/nltvals.def
+++ b/sim/common/nltvals.def
@@ -1,97 +1,5 @@
 /* Newlib/libgloss macro values needed by remote target support.  */
 /* This file is machine generated by gennltvals.py.  */
-#ifdef errno_defs
-/* from errno.h */
-/* from sys/errno.h */
-/* begin errno target macros */
- { "E2BIG", 7 },
- { "EACCES", 13 },
- { "EADDRINUSE", 112 },
- { "EADDRNOTAVAIL", 125 },
- { "EAFNOSUPPORT", 106 },
- { "EAGAIN", 11 },
- { "EALREADY", 120 },
- { "EBADF", 9 },
- { "EBADMSG", 77 },
- { "EBUSY", 16 },
- { "ECANCELED", 140 },
- { "ECHILD", 10 },
- { "ECONNABORTED", 113 },
- { "ECONNREFUSED", 111 },
- { "ECONNRESET", 104 },
- { "EDEADLK", 45 },
- { "EDESTADDRREQ", 121 },
- { "EDOM", 33 },
- { "EDQUOT", 132 },
- { "EEXIST", 17 },
- { "EFAULT", 14 },
- { "EFBIG", 27 },
- { "EFTYPE", 79 },
- { "EHOSTDOWN", 117 },
- { "EHOSTUNREACH", 118 },
- { "EIDRM", 36 },
- { "EILSEQ", 138 },
- { "EINPROGRESS", 119 },
- { "EINTR", 4 },
- { "EINVAL", 22 },
- { "EIO", 5 },
- { "EISCONN", 127 },
- { "EISDIR", 21 },
- { "ELOOP", 92 },
- { "EMFILE", 24 },
- { "EMLINK", 31 },
- { "EMSGSIZE", 122 },
- { "EMULTIHOP", 74 },
- { "ENAMETOOLONG", 91 },
- { "ENETDOWN", 115 },
- { "ENETRESET", 126 },
- { "ENETUNREACH", 114 },
- { "ENFILE", 23 },
- { "ENOBUFS", 105 },
- { "ENODATA", 61 },
- { "ENODEV", 19 },
- { "ENOENT", 2 },
- { "ENOEXEC", 8 },
- { "ENOLCK", 46 },
- { "ENOLINK", 67 },
- { "ENOMEM", 12 },
- { "ENOMSG", 35 },
- { "ENOPROTOOPT", 109 },
- { "ENOSPC", 28 },
- { "ENOSR", 63 },
- { "ENOSTR", 60 },
- { "ENOSYS", 88 },
- { "ENOTCONN", 128 },
- { "ENOTDIR", 20 },
- { "ENOTEMPTY", 90 },
- { "ENOTRECOVERABLE", 141 },
- { "ENOTSOCK", 108 },
- { "ENOTSUP", 134 },
- { "ENOTTY", 25 },
- { "ENXIO", 6 },
- { "EOPNOTSUPP", 95 },
- { "EOVERFLOW", 139 },
- { "EOWNERDEAD", 142 },
- { "EPERM", 1 },
- { "EPFNOSUPPORT", 96 },
- { "EPIPE", 32 },
- { "EPROTO", 71 },
- { "EPROTONOSUPPORT", 123 },
- { "EPROTOTYPE", 107 },
- { "ERANGE", 34 },
- { "EROFS", 30 },
- { "ESPIPE", 29 },
- { "ESRCH", 3 },
- { "ESTALE", 133 },
- { "ETIME", 62 },
- { "ETIMEDOUT", 116 },
- { "ETOOMANYREFS", 129 },
- { "ETXTBSY", 26 },
- { "EWOULDBLOCK", 11 },
- { "EXDEV", 18 },
-#undef errno_defs
-/* end errno target macros */
-#endif
 #ifdef signal_defs
 /* from signal.h */
 /* from sys/signal.h */
diff --git a/sim/common/target-newlib-errno.c b/sim/common/target-newlib-errno.c
new file mode 100644
index 000000000000..af223afebefd
--- /dev/null
+++ b/sim/common/target-newlib-errno.c
@@ -0,0 +1,289 @@
+/* Target errno mappings for newlib/libgloss environment.
+   Copyright 1995-2021 Free Software Foundation, Inc.
+   Contributed by Mike Frysinger.
+
+   This file is part of simulators.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This must come before any other includes.  */
+#include "defs.h"
+
+#include <errno.h>
+
+#include "sim/callback.h"
+
+/* This file is kept up-to-date via the gennltvals.py script.  Do not edit
+   anything between the START & END comment blocks below.  */
+
+CB_TARGET_DEFS_MAP cb_init_errno_map[] = {
+  /* gennltvals: START */
+#ifdef E2BIG
+  { "E2BIG", E2BIG, 7 },
+#endif
+#ifdef EACCES
+  { "EACCES", EACCES, 13 },
+#endif
+#ifdef EADDRINUSE
+  { "EADDRINUSE", EADDRINUSE, 112 },
+#endif
+#ifdef EADDRNOTAVAIL
+  { "EADDRNOTAVAIL", EADDRNOTAVAIL, 125 },
+#endif
+#ifdef EAFNOSUPPORT
+  { "EAFNOSUPPORT", EAFNOSUPPORT, 106 },
+#endif
+#ifdef EAGAIN
+  { "EAGAIN", EAGAIN, 11 },
+#endif
+#ifdef EALREADY
+  { "EALREADY", EALREADY, 120 },
+#endif
+#ifdef EBADF
+  { "EBADF", EBADF, 9 },
+#endif
+#ifdef EBADMSG
+  { "EBADMSG", EBADMSG, 77 },
+#endif
+#ifdef EBUSY
+  { "EBUSY", EBUSY, 16 },
+#endif
+#ifdef ECANCELED
+  { "ECANCELED", ECANCELED, 140 },
+#endif
+#ifdef ECHILD
+  { "ECHILD", ECHILD, 10 },
+#endif
+#ifdef ECONNABORTED
+  { "ECONNABORTED", ECONNABORTED, 113 },
+#endif
+#ifdef ECONNREFUSED
+  { "ECONNREFUSED", ECONNREFUSED, 111 },
+#endif
+#ifdef ECONNRESET
+  { "ECONNRESET", ECONNRESET, 104 },
+#endif
+#ifdef EDEADLK
+  { "EDEADLK", EDEADLK, 45 },
+#endif
+#ifdef EDESTADDRREQ
+  { "EDESTADDRREQ", EDESTADDRREQ, 121 },
+#endif
+#ifdef EDOM
+  { "EDOM", EDOM, 33 },
+#endif
+#ifdef EDQUOT
+  { "EDQUOT", EDQUOT, 132 },
+#endif
+#ifdef EEXIST
+  { "EEXIST", EEXIST, 17 },
+#endif
+#ifdef EFAULT
+  { "EFAULT", EFAULT, 14 },
+#endif
+#ifdef EFBIG
+  { "EFBIG", EFBIG, 27 },
+#endif
+#ifdef EFTYPE
+  { "EFTYPE", EFTYPE, 79 },
+#endif
+#ifdef EHOSTDOWN
+  { "EHOSTDOWN", EHOSTDOWN, 117 },
+#endif
+#ifdef EHOSTUNREACH
+  { "EHOSTUNREACH", EHOSTUNREACH, 118 },
+#endif
+#ifdef EIDRM
+  { "EIDRM", EIDRM, 36 },
+#endif
+#ifdef EILSEQ
+  { "EILSEQ", EILSEQ, 138 },
+#endif
+#ifdef EINPROGRESS
+  { "EINPROGRESS", EINPROGRESS, 119 },
+#endif
+#ifdef EINTR
+  { "EINTR", EINTR, 4 },
+#endif
+#ifdef EINVAL
+  { "EINVAL", EINVAL, 22 },
+#endif
+#ifdef EIO
+  { "EIO", EIO, 5 },
+#endif
+#ifdef EISCONN
+  { "EISCONN", EISCONN, 127 },
+#endif
+#ifdef EISDIR
+  { "EISDIR", EISDIR, 21 },
+#endif
+#ifdef ELOOP
+  { "ELOOP", ELOOP, 92 },
+#endif
+#ifdef EMFILE
+  { "EMFILE", EMFILE, 24 },
+#endif
+#ifdef EMLINK
+  { "EMLINK", EMLINK, 31 },
+#endif
+#ifdef EMSGSIZE
+  { "EMSGSIZE", EMSGSIZE, 122 },
+#endif
+#ifdef EMULTIHOP
+  { "EMULTIHOP", EMULTIHOP, 74 },
+#endif
+#ifdef ENAMETOOLONG
+  { "ENAMETOOLONG", ENAMETOOLONG, 91 },
+#endif
+#ifdef ENETDOWN
+  { "ENETDOWN", ENETDOWN, 115 },
+#endif
+#ifdef ENETRESET
+  { "ENETRESET", ENETRESET, 126 },
+#endif
+#ifdef ENETUNREACH
+  { "ENETUNREACH", ENETUNREACH, 114 },
+#endif
+#ifdef ENFILE
+  { "ENFILE", ENFILE, 23 },
+#endif
+#ifdef ENOBUFS
+  { "ENOBUFS", ENOBUFS, 105 },
+#endif
+#ifdef ENODATA
+  { "ENODATA", ENODATA, 61 },
+#endif
+#ifdef ENODEV
+  { "ENODEV", ENODEV, 19 },
+#endif
+#ifdef ENOENT
+  { "ENOENT", ENOENT, 2 },
+#endif
+#ifdef ENOEXEC
+  { "ENOEXEC", ENOEXEC, 8 },
+#endif
+#ifdef ENOLCK
+  { "ENOLCK", ENOLCK, 46 },
+#endif
+#ifdef ENOLINK
+  { "ENOLINK", ENOLINK, 67 },
+#endif
+#ifdef ENOMEM
+  { "ENOMEM", ENOMEM, 12 },
+#endif
+#ifdef ENOMSG
+  { "ENOMSG", ENOMSG, 35 },
+#endif
+#ifdef ENOPROTOOPT
+  { "ENOPROTOOPT", ENOPROTOOPT, 109 },
+#endif
+#ifdef ENOSPC
+  { "ENOSPC", ENOSPC, 28 },
+#endif
+#ifdef ENOSR
+  { "ENOSR", ENOSR, 63 },
+#endif
+#ifdef ENOSTR
+  { "ENOSTR", ENOSTR, 60 },
+#endif
+#ifdef ENOSYS
+  { "ENOSYS", ENOSYS, 88 },
+#endif
+#ifdef ENOTCONN
+  { "ENOTCONN", ENOTCONN, 128 },
+#endif
+#ifdef ENOTDIR
+  { "ENOTDIR", ENOTDIR, 20 },
+#endif
+#ifdef ENOTEMPTY
+  { "ENOTEMPTY", ENOTEMPTY, 90 },
+#endif
+#ifdef ENOTRECOVERABLE
+  { "ENOTRECOVERABLE", ENOTRECOVERABLE, 141 },
+#endif
+#ifdef ENOTSOCK
+  { "ENOTSOCK", ENOTSOCK, 108 },
+#endif
+#ifdef ENOTSUP
+  { "ENOTSUP", ENOTSUP, 134 },
+#endif
+#ifdef ENOTTY
+  { "ENOTTY", ENOTTY, 25 },
+#endif
+#ifdef ENXIO
+  { "ENXIO", ENXIO, 6 },
+#endif
+#ifdef EOPNOTSUPP
+  { "EOPNOTSUPP", EOPNOTSUPP, 95 },
+#endif
+#ifdef EOVERFLOW
+  { "EOVERFLOW", EOVERFLOW, 139 },
+#endif
+#ifdef EOWNERDEAD
+  { "EOWNERDEAD", EOWNERDEAD, 142 },
+#endif
+#ifdef EPERM
+  { "EPERM", EPERM, 1 },
+#endif
+#ifdef EPFNOSUPPORT
+  { "EPFNOSUPPORT", EPFNOSUPPORT, 96 },
+#endif
+#ifdef EPIPE
+  { "EPIPE", EPIPE, 32 },
+#endif
+#ifdef EPROTO
+  { "EPROTO", EPROTO, 71 },
+#endif
+#ifdef EPROTONOSUPPORT
+  { "EPROTONOSUPPORT", EPROTONOSUPPORT, 123 },
+#endif
+#ifdef EPROTOTYPE
+  { "EPROTOTYPE", EPROTOTYPE, 107 },
+#endif
+#ifdef ERANGE
+  { "ERANGE", ERANGE, 34 },
+#endif
+#ifdef EROFS
+  { "EROFS", EROFS, 30 },
+#endif
+#ifdef ESPIPE
+  { "ESPIPE", ESPIPE, 29 },
+#endif
+#ifdef ESRCH
+  { "ESRCH", ESRCH, 3 },
+#endif
+#ifdef ESTALE
+  { "ESTALE", ESTALE, 133 },
+#endif
+#ifdef ETIME
+  { "ETIME", ETIME, 62 },
+#endif
+#ifdef ETIMEDOUT
+  { "ETIMEDOUT", ETIMEDOUT, 116 },
+#endif
+#ifdef ETOOMANYREFS
+  { "ETOOMANYREFS", ETOOMANYREFS, 129 },
+#endif
+#ifdef ETXTBSY
+  { "ETXTBSY", ETXTBSY, 26 },
+#endif
+#ifdef EWOULDBLOCK
+  { "EWOULDBLOCK", EWOULDBLOCK, 11 },
+#endif
+#ifdef EXDEV
+  { "EXDEV", EXDEV, 18 },
+#endif
+  /* gennltvals: END */
+  { NULL, -1, -1 },
+};
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] sim: nltvals: pull target signal out into a dedicated source file
  2021-10-31  8:41 [PATCH 1/2] sim: nltvals: pull target errno out into a dedicated source file Mike Frysinger
@ 2021-10-31  8:41 ` Mike Frysinger
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2021-10-31  8:41 UTC (permalink / raw)
  To: gdb-patches

Like we just did for pulling out the errno map, pull out the signal
map into a dedicated common file.  All newlib ports are using the
same signal map which makes it easy.
---
 sim/Makefile.in                   |  19 +++++
 sim/common/Make-common.in         |   1 +
 sim/common/gentmap.c              |  24 ------
 sim/common/local.mk               |   1 +
 sim/common/nltvals.def            |  41 ---------
 sim/common/target-newlib-signal.c | 136 ++++++++++++++++++++++++++++++
 6 files changed, 157 insertions(+), 65 deletions(-)
 create mode 100644 sim/common/target-newlib-signal.c

diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index 5db835713e7c..d6b34d521229 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -232,6 +232,7 @@ COMMON_OBJS_NAMES = \
 	portability.o \
 	sim-load.o \
 	target-newlib-errno.o \
+	target-newlib-signal.o \
 	version.o
 COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/common_libcommon_a-%)
 
diff --git a/sim/common/gentmap.c b/sim/common/gentmap.c
index 8e6e3aeda325..fbc290185b52 100644
--- a/sim/common/gentmap.c
+++ b/sim/common/gentmap.c
@@ -16,13 +16,6 @@ static struct tdefs sys_tdefs[] = {
   { 0, 0 }
 };
 
-static struct tdefs signal_tdefs[] = {
-#define signal_defs
-#include "nltvals.def"
-#undef signal_defs
-  { 0, 0 }
-};
-
 static struct tdefs open_tdefs[] = {
 #define open_defs
 #include "nltvals.def"
@@ -46,11 +39,6 @@ gen_targ_vals_h (void)
     printf ("#define TARGET_%s %d\n", t->symbol, t->value);
   printf ("\n");
 
-  printf ("/* signal values */\n");
-  for (t = &signal_tdefs[0]; t->symbol; ++t)
-    printf ("#define TARGET_%s %d\n", t->symbol, t->value);
-  printf ("\n");
-
   printf ("/* open flag values */\n");
   for (t = &open_tdefs[0]; t->symbol; ++t)
     printf ("#define TARGET_%s 0x%x\n", t->symbol, t->value);
@@ -69,7 +57,6 @@ gen_targ_map_c (void)
 
   printf ("#include \"defs.h\"\n");
   printf ("#include <fcntl.h>\n");
-  printf ("#include <signal.h>\n");
   printf ("#include \"ansidecl.h\"\n");
   printf ("#include \"sim/callback.h\"\n");
   printf ("#include \"targ-vals.h\"\n");
@@ -87,17 +74,6 @@ gen_targ_map_c (void)
   printf ("  { 0, -1, -1 }\n");
   printf ("};\n\n");
 
-  printf ("/* signals mapping table */\n");
-  printf ("CB_TARGET_DEFS_MAP cb_init_signal_map[] = {\n");
-  for (t = &signal_tdefs[0]; t->symbol; ++t)
-    {
-      printf ("#ifdef %s\n", t->symbol);
-      printf ("  { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
-      printf ("#endif\n");
-    }
-  printf ("  { 0, -1, -1 }\n");
-  printf ("};\n\n");
-
   printf ("/* open flags mapping table */\n");
   printf ("CB_TARGET_DEFS_MAP cb_init_open_map[] = {\n");
   for (t = &open_tdefs[0]; t->symbol; ++t)
diff --git a/sim/common/local.mk b/sim/common/local.mk
index 71a931715c2d..bf5eda0b0d3b 100644
--- a/sim/common/local.mk
+++ b/sim/common/local.mk
@@ -37,6 +37,7 @@ noinst_LIBRARIES += %D%/libcommon.a
 	%D%/portability.c \
 	%D%/sim-load.c \
 	%D%/target-newlib-errno.c \
+	%D%/target-newlib-signal.c \
 	%D%/version.c
 
 %D%/version.c: %D%/version.c-stamp ; @true
diff --git a/sim/common/nltvals.def b/sim/common/nltvals.def
index 5e72e596ee80..6d44d03ea5b4 100644
--- a/sim/common/nltvals.def
+++ b/sim/common/nltvals.def
@@ -1,46 +1,5 @@
 /* Newlib/libgloss macro values needed by remote target support.  */
 /* This file is machine generated by gennltvals.py.  */
-#ifdef signal_defs
-/* from signal.h */
-/* from sys/signal.h */
-/* begin signal target macros */
- { "SIGABRT", 6 },
- { "SIGALRM", 14 },
- { "SIGBUS", 10 },
- { "SIGCHLD", 20 },
- { "SIGCLD", 20 },
- { "SIGCONT", 19 },
- { "SIGEMT", 7 },
- { "SIGFPE", 8 },
- { "SIGHUP", 1 },
- { "SIGILL", 4 },
- { "SIGINT", 2 },
- { "SIGIO", 23 },
- { "SIGIOT", 6 },
- { "SIGKILL", 9 },
- { "SIGLOST", 29 },
- { "SIGPIPE", 13 },
- { "SIGPOLL", 23 },
- { "SIGPROF", 27 },
- { "SIGQUIT", 3 },
- { "SIGSEGV", 11 },
- { "SIGSTOP", 17 },
- { "SIGSYS", 12 },
- { "SIGTERM", 15 },
- { "SIGTRAP", 5 },
- { "SIGTSTP", 18 },
- { "SIGTTIN", 21 },
- { "SIGTTOU", 22 },
- { "SIGURG", 16 },
- { "SIGUSR1", 30 },
- { "SIGUSR2", 31 },
- { "SIGVTALRM", 26 },
- { "SIGWINCH", 28 },
- { "SIGXCPU", 24 },
- { "SIGXFSZ", 25 },
-#undef signal_defs
-/* end signal target macros */
-#endif
 #ifdef open_defs
 /* from fcntl.h */
 /* from sys/fcntl.h */
diff --git a/sim/common/target-newlib-signal.c b/sim/common/target-newlib-signal.c
new file mode 100644
index 000000000000..b886bfa93b9f
--- /dev/null
+++ b/sim/common/target-newlib-signal.c
@@ -0,0 +1,136 @@
+/* Target errno mappings for newlib/libgloss environment.
+   Copyright 1995-2021 Free Software Foundation, Inc.
+   Contributed by Mike Frysinger.
+
+   This file is part of simulators.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This must come before any other includes.  */
+#include "defs.h"
+
+#include <signal.h>
+
+#include "sim/callback.h"
+
+/* This file is kept up-to-date via the gennltvals.py script.  Do not edit
+   anything between the START & END comment blocks below.  */
+
+CB_TARGET_DEFS_MAP cb_init_signal_map[] = {
+  /* gennltvals: START */
+#ifdef SIGABRT
+  { "SIGABRT", SIGABRT, 6 },
+#endif
+#ifdef SIGALRM
+  { "SIGALRM", SIGALRM, 14 },
+#endif
+#ifdef SIGBUS
+  { "SIGBUS", SIGBUS, 10 },
+#endif
+#ifdef SIGCHLD
+  { "SIGCHLD", SIGCHLD, 20 },
+#endif
+#ifdef SIGCLD
+  { "SIGCLD", SIGCLD, 20 },
+#endif
+#ifdef SIGCONT
+  { "SIGCONT", SIGCONT, 19 },
+#endif
+#ifdef SIGEMT
+  { "SIGEMT", SIGEMT, 7 },
+#endif
+#ifdef SIGFPE
+  { "SIGFPE", SIGFPE, 8 },
+#endif
+#ifdef SIGHUP
+  { "SIGHUP", SIGHUP, 1 },
+#endif
+#ifdef SIGILL
+  { "SIGILL", SIGILL, 4 },
+#endif
+#ifdef SIGINT
+  { "SIGINT", SIGINT, 2 },
+#endif
+#ifdef SIGIO
+  { "SIGIO", SIGIO, 23 },
+#endif
+#ifdef SIGIOT
+  { "SIGIOT", SIGIOT, 6 },
+#endif
+#ifdef SIGKILL
+  { "SIGKILL", SIGKILL, 9 },
+#endif
+#ifdef SIGLOST
+  { "SIGLOST", SIGLOST, 29 },
+#endif
+#ifdef SIGPIPE
+  { "SIGPIPE", SIGPIPE, 13 },
+#endif
+#ifdef SIGPOLL
+  { "SIGPOLL", SIGPOLL, 23 },
+#endif
+#ifdef SIGPROF
+  { "SIGPROF", SIGPROF, 27 },
+#endif
+#ifdef SIGQUIT
+  { "SIGQUIT", SIGQUIT, 3 },
+#endif
+#ifdef SIGSEGV
+  { "SIGSEGV", SIGSEGV, 11 },
+#endif
+#ifdef SIGSTOP
+  { "SIGSTOP", SIGSTOP, 17 },
+#endif
+#ifdef SIGSYS
+  { "SIGSYS", SIGSYS, 12 },
+#endif
+#ifdef SIGTERM
+  { "SIGTERM", SIGTERM, 15 },
+#endif
+#ifdef SIGTRAP
+  { "SIGTRAP", SIGTRAP, 5 },
+#endif
+#ifdef SIGTSTP
+  { "SIGTSTP", SIGTSTP, 18 },
+#endif
+#ifdef SIGTTIN
+  { "SIGTTIN", SIGTTIN, 21 },
+#endif
+#ifdef SIGTTOU
+  { "SIGTTOU", SIGTTOU, 22 },
+#endif
+#ifdef SIGURG
+  { "SIGURG", SIGURG, 16 },
+#endif
+#ifdef SIGUSR1
+  { "SIGUSR1", SIGUSR1, 30 },
+#endif
+#ifdef SIGUSR2
+  { "SIGUSR2", SIGUSR2, 31 },
+#endif
+#ifdef SIGVTALRM
+  { "SIGVTALRM", SIGVTALRM, 26 },
+#endif
+#ifdef SIGWINCH
+  { "SIGWINCH", SIGWINCH, 28 },
+#endif
+#ifdef SIGXCPU
+  { "SIGXCPU", SIGXCPU, 24 },
+#endif
+#ifdef SIGXFSZ
+  { "SIGXFSZ", SIGXFSZ, 25 },
+#endif
+  /* gennltvals: END */
+  { NULL, -1, -1 },
+};
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-31  8:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-31  8:41 [PATCH 1/2] sim: nltvals: pull target errno out into a dedicated source file Mike Frysinger
2021-10-31  8:41 ` [PATCH 2/2] sim: nltvals: pull target signal " Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).