This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libmudflap] ctype support


Hi -

The following patch illustrates how ctype support for a specific platform
might be added to libmudflap.  I don't much like it, in that it is terribly
version sensitive and ugly, but short of another mechanism, that's all we
have.  Maybe one should resurrect an idea to use a script to extract
static data stats from uninstrumented libraries and generate a mass
registration function.


+2004-06-09  Frank Ch. Eigler  <fche@redhat.com>
+
+	ctype support.
+	* configure.in: Look for ctype header and glibc implementation.
+	* mf-hooks2.c (__ctype_{b,toupper,tolower}_loc): Sample ctype
+	array hooks for glibc 2.3.
+	* mf-runtime.h.in: Wrap them.
+	* mf-runtime.c (__mf_init): Leave marker regarding other ctype
+	implementations.
+	* testsuite/libmudflap.c/pass47-frag.c: New test.
+	* configure, config.h.in: Regenerated.

Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/configure.in,v
retrieving revision 1.5
diff -u -p -s -w -r1.5 configure.in
--- configure.in	4 Jun 2004 20:12:00 -0000	1.5
+++ configure.in	9 Jun 2004 18:59:52 -0000
@@ -63,7 +63,7 @@ AC_TRY_COMPILE([
 enable_shared=no])
 
 AC_CHECK_HEADERS(stdint.h execinfo.h signal.h dlfcn.h \
-  netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h sys/socket.h)
+  netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h sys/socket.h ctype.h)
 AC_CHECK_FUNCS(backtrace backtrace_symbols gettimeofday signal)
 
 dnl Check for 64-bit stdio calls related to Large File Support
@@ -72,6 +72,9 @@ AC_CHECK_FUNCS(fopen64 fseeko64 ftello64
 dnl Check for nonstandard functions
 AC_CHECK_FUNCS(strnlen memrchr strncpy memmem sethostname)
 
+dnl Check for glibc ctype functions
+AC_CHECK_FUNCS(__ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc)
+
 AC_TRY_COMPILE([#include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/sem.h>],[union semun foo;], [mf_have_semun=1], [mf_have_semun=0])
Index: mf-hooks2.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/mf-hooks2.c,v
retrieving revision 1.4
diff -u -p -s -w -r1.4 mf-hooks2.c
--- mf-hooks2.c	4 Jun 2004 20:12:00 -0000	1.4
+++ mf-hooks2.c	9 Jun 2004 18:59:52 -0000
@@ -63,6 +63,7 @@ Software Foundation, 59 Temple Place - S
 #include <errno.h>
 #include <limits.h>
 #include <time.h>
+#include <ctype.h>
 #include <dirent.h>
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
@@ -1643,3 +1644,78 @@ WRAPPER2(int, shmdt, const void *shmaddr
 
 
 #endif /* HAVE_SYS_IPC/SEM/SHM_H */
+
+
+
+/* ctype stuff.  This is host-specific by necessity, as the arrays
+   that is used by most is*()/to*() macros are implementation-defined.  */
+
+/* GLIBC 2.3 */
+#ifdef HAVE___CTYPE_B_LOC
+WRAPPER2(unsigned short **, __ctype_b_loc, void)
+{
+  static unsigned short * last_buf = (void *) 0;
+  static unsigned short ** last_ptr = (void *) 0;
+  unsigned short ** ptr = (unsigned short **) __ctype_b_loc ();
+  unsigned short * buf = * ptr;
+  if (ptr != last_ptr)
+    {
+      /* XXX: unregister last_ptr? */
+      last_ptr = ptr;
+      __mf_register (last_ptr, sizeof(last_ptr), __MF_TYPE_STATIC, "ctype_b_loc **");
+    }
+  if (buf != last_buf)
+    {
+      last_buf = buf;
+      __mf_register ((void *) (last_buf - 128), 384 * sizeof(unsigned short), __MF_TYPE_STATIC,
+                     "ctype_b_loc []");
+    }
+  return ptr;
+}
+#endif
+
+#ifdef HAVE___CTYPE_TOUPPER_LOC
+WRAPPER2(int **, __ctype_toupper_loc, void)
+{
+  static int * last_buf = (void *) 0;
+  static int ** last_ptr = (void *) 0;
+  int ** ptr = (int **) __ctype_toupper_loc ();
+  int * buf = * ptr;
+  if (ptr != last_ptr)
+    {
+      /* XXX: unregister last_ptr? */
+      last_ptr = ptr;
+      __mf_register (last_ptr, sizeof(last_ptr), __MF_TYPE_STATIC, "ctype_toupper_loc **");
+    }
+  if (buf != last_buf)
+    {
+      last_buf = buf;
+      __mf_register ((void *) (last_buf - 128), 384 * sizeof(int), __MF_TYPE_STATIC,
+                     "ctype_toupper_loc []");
+    }
+  return ptr;
+}
+#endif
+
+#ifdef HAVE___CTYPE_TOLOWER_LOC
+WRAPPER2(int **, __ctype_tolower_loc, void)
+{
+  static int * last_buf = (void *) 0;
+  static int ** last_ptr = (void *) 0;
+  int ** ptr = (int **) __ctype_tolower_loc ();
+  int * buf = * ptr;
+  if (ptr != last_ptr)
+    {
+      /* XXX: unregister last_ptr? */
+      last_ptr = ptr;
+      __mf_register (last_ptr, sizeof(last_ptr), __MF_TYPE_STATIC, "ctype_tolower_loc **");
+    }
+  if (buf != last_buf)
+    {
+      last_buf = buf;
+      __mf_register ((void *) (last_buf - 128), 384 * sizeof(int), __MF_TYPE_STATIC,
+                     "ctype_tolower_loc []");
+    }
+  return ptr;
+}
+#endif
Index: mf-runtime.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/mf-runtime.c,v
retrieving revision 1.5
diff -u -p -s -w -r1.5 mf-runtime.c
--- mf-runtime.c	4 Jun 2004 20:12:00 -0000	1.5
+++ mf-runtime.c	9 Jun 2004 18:59:53 -0000
@@ -63,6 +63,7 @@ Software Foundation, 59 Temple Place - S
 #include <sys/types.h>
 #include <signal.h>
 #include <errno.h>
+#include <ctype.h>
 
 #include "mf-runtime.h"
 #include "mf-impl.h"
@@ -685,6 +686,11 @@ __wrap_main (int argc, char* argv[])
       __mf_register (stdin,  sizeof (*stdin),  __MF_TYPE_STATIC, "stdin");
       __mf_register (stdout, sizeof (*stdout), __MF_TYPE_STATIC, "stdout");
       __mf_register (stderr, sizeof (*stderr), __MF_TYPE_STATIC, "stderr");
+
+      /* Make some effort to register ctype.h static arrays.  */
+      /* XXX: e.g., on Solaris, may need to register __ctype, _ctype, __ctype_mask, __toupper, etc. */
+      /* On modern Linux GLIBC, these are thread-specific and changeable, and are dealt
+         with in mf-hooks2.c.  */
     }
 
 #ifdef PIC
Index: mf-runtime.h.in
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/mf-runtime.h.in,v
retrieving revision 1.2
diff -u -p -s -w -r1.2 mf-runtime.h.in
--- mf-runtime.h.in	13 May 2004 06:41:03 -0000	1.2
+++ mf-runtime.h.in	9 Jun 2004 18:59:53 -0000
@@ -177,6 +177,9 @@ extern int __mf_set_options (const char 
 #pragma redefine_extname shmctl __mfwrap_shmctl
 #pragma redefine_extname shmat __mfwrap_shmat
 #pragma redefine_extname shmdt __mfwrap_shmdt
+#pragma redefine_extname __ctype_b_loc __mfwrap___ctype_b_loc
+#pragma redefine_extname __ctype_toupper_loc __mfwrap___ctype_toupper_loc
+#pragma redefine_extname __ctype_tolower_loc __mfwrap___ctype_tolower_loc
 
 /* Disable glibc macros.  */
 #define __NO_STRING_INLINES
Index: testsuite/libmudflap.c/pass47-frag.c
===================================================================
RCS file: testsuite/libmudflap.c/pass47-frag.c
diff -N testsuite/libmudflap.c/pass47-frag.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/libmudflap.c/pass47-frag.c	9 Jun 2004 18:59:53 -0000
@@ -0,0 +1,10 @@
+#include <stdlib.h>
+#include <ctype.h>
+
+int main ()
+{
+  char* buf = "hello"; 
+  return ! ((toupper (buf[0]) == 'H' && toupper ('z') == 'Z' &&
+             tolower (buf[4]) == 'o' && tolower ('X') == 'x' &&
+             isdigit (buf[3])) == 0 && isalnum ('4'));
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]