Use sigsetjmp/siglongjmp in opcodes
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 2 May 2014 15:27:16 +0000 (08:27 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 2 May 2014 15:27:16 +0000 (08:27 -0700)
sigsetjmp/siglongjmp without saving the signal mask is faster than
setjmp/longjmp on systems where the signal mask is saved.  This patch
uses sigsetjmp/siglongjmp without saving the signal mask if possible.

PR binutils/16886
* config.in: Regenerated.
* configure: Likewise.
* configure.in: Check if sigsetjmp is available.
* h8500-dis.c (private): Replace jmp_buf with OPCODES_SIGJMP_BUF.
(fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
(print_insn_h8500): Replace setjmp with OPCODES_SIGSETJMP.
* i386-dis.c (dis_private): Replace jmp_buf with OPCODES_SIGJMP_BUF.
(fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
(print_insn): Replace setjmp with OPCODES_SIGSETJMP.
* ns32k-dis.c (private): Replace jmp_buf with OPCODES_SIGJMP_BUF.
(fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
(print_insn_ns32k): Replace setjmp with OPCODES_SIGSETJMP.
* sysdep.h (OPCODES_SIGJMP_BUF): New macro.
(OPCODES_SIGSETJMP): Likewise.
(OPCODES_SIGLONGJMP): Likewise.
* vax-dis.c (private): Replace jmp_buf with OPCODES_SIGJMP_BUF.
(fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
(print_insn_vax): Replace setjmp with OPCODES_SIGSETJMP.
* xtensa-dis.c (dis_private): Replace jmp_buf with
OPCODES_SIGJMP_BUF.
(fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
(print_insn_xtensa): Replace setjmp with OPCODES_SIGSETJMP.
* z8k-dis.c(instr_data_s): Replace jmp_buf with OPCODES_SIGJMP_BUF.
(fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
(print_insn_z8k): Replace setjmp with OPCODES_SIGSETJMP.

opcodes/ChangeLog
opcodes/config.in
opcodes/configure
opcodes/configure.in
opcodes/h8500-dis.c
opcodes/i386-dis.c
opcodes/ns32k-dis.c
opcodes/sysdep.h
opcodes/vax-dis.c
opcodes/xtensa-dis.c
opcodes/z8k-dis.c

index 747aa23..2e4affe 100644 (file)
@@ -1,3 +1,32 @@
+2014-05-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/16886
+       * config.in: Regenerated.
+       * configure: Likewise.
+       * configure.in: Check if sigsetjmp is available.
+       * h8500-dis.c (private): Replace jmp_buf with OPCODES_SIGJMP_BUF.
+       (fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
+       (print_insn_h8500): Replace setjmp with OPCODES_SIGSETJMP.
+       * i386-dis.c (dis_private): Replace jmp_buf with OPCODES_SIGJMP_BUF.
+       (fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
+       (print_insn): Replace setjmp with OPCODES_SIGSETJMP.
+       * ns32k-dis.c (private): Replace jmp_buf with OPCODES_SIGJMP_BUF.
+       (fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
+       (print_insn_ns32k): Replace setjmp with OPCODES_SIGSETJMP.
+       * sysdep.h (OPCODES_SIGJMP_BUF): New macro.
+       (OPCODES_SIGSETJMP): Likewise.
+       (OPCODES_SIGLONGJMP): Likewise.
+       * vax-dis.c (private): Replace jmp_buf with OPCODES_SIGJMP_BUF.
+       (fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
+       (print_insn_vax): Replace setjmp with OPCODES_SIGSETJMP.
+       * xtensa-dis.c (dis_private): Replace jmp_buf with
+       OPCODES_SIGJMP_BUF.
+       (fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
+       (print_insn_xtensa): Replace setjmp with OPCODES_SIGSETJMP.
+       * z8k-dis.c(instr_data_s): Replace jmp_buf with OPCODES_SIGJMP_BUF.
+       (fetch_data): Replace longjmp with OPCODES_SIGLONGJMP.
+       (print_insn_z8k): Replace setjmp with OPCODES_SIGSETJMP.
+
 2014-05-01  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR binutils/16891
index 9555f7d..ee1ddbb 100644 (file)
@@ -31,6 +31,9 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define if sigsetjmp is available. */
+#undef HAVE_SIGSETJMP
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
index afe0cd1..9379bbf 100755 (executable)
@@ -12207,6 +12207,41 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+# Check if sigsetjmp is available.  Using AC_CHECK_FUNCS won't do
+# since sigsetjmp might only be defined as a macro.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sigsetjmp" >&5
+$as_echo_n "checking for sigsetjmp... " >&6; }
+if test "${gdb_cv_func_sigsetjmp+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <setjmp.h>
+
+int
+main ()
+{
+sigjmp_buf env; while (! sigsetjmp (env, 1)) siglongjmp (env, 1);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  bfd_cv_func_sigsetjmp=yes
+else
+  bfd_cv_func_sigsetjmp=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_func_sigsetjmp" >&5
+$as_echo "$gdb_cv_func_sigsetjmp" >&6; }
+if test $bfd_cv_func_sigsetjmp = yes; then
+
+$as_echo "#define HAVE_SIGSETJMP 1" >>confdefs.h
+
+fi
+
 cgen_maint=no
 cgendir='$(srcdir)/../cgen'
 
index 00f9892..3ffcaa0 100644 (file)
@@ -98,6 +98,17 @@ ACX_HEADER_STRING
 
 AC_CHECK_DECLS([basename, stpcpy])
 
+# Check if sigsetjmp is available.  Using AC_CHECK_FUNCS won't do
+# since sigsetjmp might only be defined as a macro.
+AC_CACHE_CHECK([for sigsetjmp], gdb_cv_func_sigsetjmp,
+[AC_TRY_COMPILE([
+#include <setjmp.h>
+], [sigjmp_buf env; while (! sigsetjmp (env, 1)) siglongjmp (env, 1);],
+bfd_cv_func_sigsetjmp=yes, bfd_cv_func_sigsetjmp=no)])
+if test $bfd_cv_func_sigsetjmp = yes; then
+  AC_DEFINE(HAVE_SIGSETJMP, 1, [Define if sigsetjmp is available. ])
+fi
+
 cgen_maint=no
 cgendir='$(srcdir)/../cgen'
 
index c94091c..caa3020 100644 (file)
@@ -39,7 +39,7 @@ struct private
   bfd_byte *max_fetched;
   bfd_byte the_buffer[MAXLEN];
   bfd_vma insn_start;
-  jmp_buf bailout;
+  OPCODES_SIGJMP_BUF bailout;
 };
 
 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
@@ -63,7 +63,7 @@ fetch_data (struct disassemble_info *info, bfd_byte *addr)
   if (status != 0)
     {
       (*info->memory_error_func) (status, start, info);
-      longjmp (priv->bailout, 1);
+      OPCODES_SIGLONGJMP (priv->bailout, 1);
     }
   else
     priv->max_fetched = addr;
@@ -84,7 +84,7 @@ print_insn_h8500 (bfd_vma addr, disassemble_info *info)
   info->private_data = (PTR) & priv;
   priv.max_fetched = priv.the_buffer;
   priv.insn_start = addr;
-  if (setjmp (priv.bailout) != 0)
+  if (OPCODES_SIGSETJMP (priv.bailout) != 0)
     /* Error return.  */
     return -1;
 
index c36c632..99bb482 100644 (file)
@@ -131,7 +131,7 @@ struct dis_private {
   bfd_byte the_buffer[MAX_MNEM_SIZE];
   bfd_vma insn_start;
   int orig_sizeflag;
-  jmp_buf bailout;
+  OPCODES_SIGJMP_BUF bailout;
 };
 
 enum address_mode
@@ -214,7 +214,7 @@ fetch_data (struct disassemble_info *info, bfd_byte *addr)
         STATUS.  */
       if (priv->max_fetched == priv->the_buffer)
        (*info->memory_error_func) (status, start, info);
-      longjmp (priv->bailout, 1);
+      OPCODES_SIGLONGJMP (priv->bailout, 1);
     }
   else
     priv->max_fetched = addr;
@@ -12500,7 +12500,7 @@ print_insn (bfd_vma pc, disassemble_info *info)
   start_codep = priv.the_buffer;
   codep = priv.the_buffer;
 
-  if (setjmp (priv.bailout) != 0)
+  if (OPCODES_SIGSETJMP (priv.bailout) != 0)
     {
       const char *name;
 
index b29eccc..c6a42df 100644 (file)
@@ -57,7 +57,7 @@ struct private
   bfd_byte *max_fetched;
   bfd_byte the_buffer[MAXLEN];
   bfd_vma insn_start;
-  jmp_buf bailout;
+  OPCODES_SIGJMP_BUF bailout;
 };
 
 
@@ -82,7 +82,7 @@ fetch_data (struct disassemble_info *info, bfd_byte *addr)
   if (status != 0)
     {
       (*info->memory_error_func) (status, start, info);
-      longjmp (priv->bailout, 1);
+      OPCODES_SIGLONGJMP (priv->bailout, 1);
     }
   else
     priv->max_fetched = addr;
@@ -745,7 +745,7 @@ print_insn_ns32k (bfd_vma memaddr, disassemble_info *info)
   info->private_data = & priv;
   priv.max_fetched = priv.the_buffer;
   priv.insn_start = memaddr;
-  if (setjmp (priv.bailout) != 0)
+  if (OPCODES_SIGSETJMP (priv.bailout) != 0)
     /* Error return.  */
     return -1;
 
index cdd0fc0..84811f1 100644 (file)
 #if !HAVE_DECL_STPCPY
 extern char *stpcpy (char *__dest, const char *__src);
 #endif
+
+/* Use sigsetjmp/siglongjmp without saving the signal mask if possible.
+   It is faster than setjmp/longjmp on systems where the signal mask is
+   saved.  */
+
+#if defined(HAVE_SIGSETJMP)
+#define OPCODES_SIGJMP_BUF             sigjmp_buf
+#define OPCODES_SIGSETJMP(buf)         sigsetjmp((buf), 0)
+#define OPCODES_SIGLONGJMP(buf,val)    siglongjmp((buf), (val))
+#else
+#define OPCODES_SIGJMP_BUF             jmp_buf
+#define OPCODES_SIGSETJMP(buf)         setjmp(buf)
+#define OPCODES_SIGLONGJMP(buf,val)    longjmp((buf), (val))
+#endif
index 0b98687..5f9f1e9 100644 (file)
@@ -75,7 +75,7 @@ struct private
   bfd_byte * max_fetched;
   bfd_byte   the_buffer[MAXLEN];
   bfd_vma    insn_start;
-  jmp_buf    bailout;
+  OPCODES_SIGJMP_BUF    bailout;
 };
 
 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
@@ -99,7 +99,7 @@ fetch_data (struct disassemble_info *info, bfd_byte *addr)
   if (status != 0)
     {
       (*info->memory_error_func) (status, start, info);
-      longjmp (priv->bailout, 1);
+      OPCODES_SIGLONGJMP (priv->bailout, 1);
     }
   else
     priv->max_fetched = addr;
@@ -395,7 +395,7 @@ print_insn_vax (bfd_vma memaddr, disassemble_info *info)
       parsed_disassembler_options = TRUE;
     }
 
-  if (setjmp (priv.bailout) != 0)
+  if (OPCODES_SIGSETJMP (priv.bailout) != 0)
     /* Error return.  */
     return -1;
 
index 705c1ca..338b810 100644 (file)
@@ -42,7 +42,7 @@ int show_raw_fields;
 struct dis_private
 {
   bfd_byte *byte_buf;
-  jmp_buf bailout;
+  OPCODES_SIGJMP_BUF bailout;
 };
 
 
@@ -66,7 +66,7 @@ fetch_data (struct disassemble_info *info, bfd_vma memaddr)
        return length;
     }
   (*info->memory_error_func) (status, memaddr, info);
-  longjmp (priv->bailout, 1);
+  OPCODES_SIGLONGJMP (priv->bailout, 1);
   /*NOTREACHED*/
 }
 
@@ -175,7 +175,7 @@ print_insn_xtensa (bfd_vma memaddr, struct disassemble_info *info)
   priv.byte_buf = byte_buf;
 
   info->private_data = (void *) &priv;
-  if (setjmp (priv.bailout) != 0)
+  if (OPCODES_SIGSETJMP (priv.bailout) != 0)
       /* Error return.  */
       return -1;
 
index cc54fb5..ea7fd3b 100644 (file)
@@ -37,7 +37,7 @@ typedef struct
   /* Nibble number of first word not yet fetched.  */
   int max_fetched;
   bfd_vma insn_start;
-  jmp_buf bailout;
+  OPCODES_SIGJMP_BUF bailout;
 
   int tabl_index;
   char instr_asmsrc[80];
@@ -76,7 +76,7 @@ fetch_data (struct disassemble_info *info, int nibble)
   if (status != 0)
     {
       (*info->memory_error_func) (status, priv->insn_start, info);
-      longjmp (priv->bailout, 1);
+      OPCODES_SIGLONGJMP (priv->bailout, 1);
     }
 
   {
@@ -149,7 +149,7 @@ print_insn_z8k (bfd_vma addr, disassemble_info *info, int is_segmented)
   info->private_data = (PTR) &instr_data;
   instr_data.max_fetched = 0;
   instr_data.insn_start = addr;
-  if (setjmp (instr_data.bailout) != 0)
+  if (OPCODES_SIGSETJMP (instr_data.bailout) != 0)
     /* Error return.  */
     return -1;