[libmudflap] more wrappers, warnings cleanup

Frank Ch. Eigler fche@redhat.com
Mon Oct 4 17:35:00 GMT 2004


Hi -

The following patch adds a few more wrapper functions to libmudflap,
as required by more server-flavoured tools like openssh.  It includes
some minor warning cleanups that finally allow the tool to compile
with "-Wall -Werror", at least on linux.


+ 2004-10-04  Frank Ch. Eigler  <fche@redhat.com>
+ 
+ 	* configure.ac: Look for more headers & functions.
+ 	* mf-hooks2.c (getmntent, inet_ntoa, getproto*): New wrapper functions.
+ 	* mf-runtime.h.in: Add new "#pragma redefine_extname"s for them.
+ 	* mf-runtime.c (options): Clean up integer signedness warnings.
+ 	(main): Add a declaration to fix a warning.
+ 	* mf-hooks3.c (pthread_exit): Add not-reached exit() to wrapper.
+ 	* configure, config.h.in: Regenerated.

Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/configure.ac,v
retrieving revision 1.4
diff -c -w -s -p -r1.4 configure.ac
*** configure.ac	7 Sep 2004 21:52:51 -0000	1.4
--- configure.ac	4 Oct 2004 17:32:04 -0000
*************** AC_TRY_COMPILE([
*** 60,81 ****
  enable_shared=no])
  
  AC_CHECK_HEADERS(stdint.h execinfo.h signal.h dlfcn.h dirent.h pwd.h grp.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
  AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64)
- 
- 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)
- 
- dnl Check for pwd.h / grp.h family of functions
  AC_CHECK_FUNCS(getlogin cuserid getpwnam getpwuid getpwent getgrnam getgrgid getgrent)
  AC_CHECK_FUNCS(getlogin_r getpwnam_r getpwuid_r getgrnam_r getgrgid_r)
  AC_CHECK_FUNCS(getservent getservbyname getservbyport getaddrinfo gai_strerror)
  
  AC_TRY_COMPILE([#include <sys/types.h>
  #include <sys/ipc.h>
--- 60,78 ----
  enable_shared=no])
  
  AC_CHECK_HEADERS(stdint.h execinfo.h signal.h dlfcn.h dirent.h pwd.h grp.h \
!   netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h sys/socket.h ctype.h mntent.h \
!   sys/socket.h netinet/in.h arpa/inet.h dlfcn.h)
  
! AC_CHECK_FUNCS(backtrace backtrace_symbols gettimeofday signal)
  AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64)
  AC_CHECK_FUNCS(strnlen memrchr strncpy memmem sethostname)
  AC_CHECK_FUNCS(__ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc)
  AC_CHECK_FUNCS(getlogin cuserid getpwnam getpwuid getpwent getgrnam getgrgid getgrent)
  AC_CHECK_FUNCS(getlogin_r getpwnam_r getpwuid_r getgrnam_r getgrgid_r)
  AC_CHECK_FUNCS(getservent getservbyname getservbyport getaddrinfo gai_strerror)
+ AC_CHECK_FUNCS(getprotoent getprotobyname getprotobynumber)
+ AC_CHECK_FUNCS(getmntent setmntent addmntent)
+ AC_CHECK_FUNCS(inet_ntoa)
  
  AC_TRY_COMPILE([#include <sys/types.h>
  #include <sys/ipc.h>
Index: mf-hooks2.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/mf-hooks2.c,v
retrieving revision 1.9
diff -c -w -s -p -r1.9 mf-hooks2.c
*** mf-hooks2.c	7 Sep 2004 21:52:51 -0000	1.9
--- mf-hooks2.c	4 Oct 2004 17:32:04 -0000
*************** Software Foundation, 59 Temple Place - S
*** 63,68 ****
--- 63,71 ----
  #include <limits.h>
  #include <time.h>
  #include <ctype.h>
+ #ifdef HAVE_DLFCN_H
+ #include <dlfcn.h>
+ #endif
  #ifdef HAVE_DIRENT_H
  #include <dirent.h>
  #endif
*************** Software Foundation, 59 Temple Place - S
*** 90,95 ****
--- 93,110 ----
  #ifdef HAVE_GRP_H
  #include <grp.h>
  #endif
+ #ifdef HAVE_MNTENT_H
+ #include <mntent.h>
+ #endif
+ #ifdef HAVE_SYS_SOCKET_H
+ #include <sys/socket.h>
+ #endif
+ #ifdef HAVE_NETINET_IN_H
+ #include <netinet/in.h>
+ #endif
+ #ifdef HAVE_ARPA_INET_H
+ #include <arpa/inet.h>
+ #endif
  
  #include "mf-runtime.h"
  #include "mf-impl.h"
*************** WRAPPER2(const char *, gai_strerror, int
*** 1871,1873 ****
--- 1886,1982 ----
    return buf;
  }
  #endif
+ 
+ 
+ #ifdef HAVE_GETMNTENT
+ WRAPPER2(struct mntent *, getmntent, FILE *filep)
+ {
+   struct mntent *m;
+   static struct mntent *last = NULL;
+ 
+   MF_VALIDATE_EXTENT (filep, sizeof (*filep), __MF_CHECK_WRITE,
+     "getmntent stream");
+ #define UR(field) __mf_unregister(last->field, strlen (last->field)+1, __MF_TYPE_STATIC)
+   if (last)
+     {
+       UR (mnt_fsname);
+       UR (mnt_dir);
+       UR (mnt_type);
+       UR (mnt_opts);
+       __mf_unregister (last, sizeof (*last), __MF_TYPE_STATIC);
+     }
+ #undef UR
+ 
+   m = getmntent (filep);
+   last = m;
+ 
+ #define R(field) __mf_register(last->field, strlen (last->field)+1, __MF_TYPE_STATIC, "mntent " #field)
+   if (m)
+     {
+       R (mnt_fsname);
+       R (mnt_dir);
+       R (mnt_type);
+       R (mnt_opts);
+       __mf_register (last, sizeof (*last), __MF_TYPE_STATIC, "getmntent result");
+     }
+ #undef R
+ 
+   return m;
+ }
+ #endif
+ 
+ 
+ #ifdef HAVE_INET_NTOA
+ WRAPPER2(char *, inet_ntoa, struct in_addr in)
+ {
+   static char *last_buf = NULL;
+   char *buf;
+   if (last_buf)
+     __mf_unregister (last_buf, strlen (last_buf)+1, __MF_TYPE_STATIC);
+   buf = inet_ntoa (in);
+   last_buf = buf;
+   if (buf)
+     __mf_register (last_buf, strlen (last_buf)+1, __MF_TYPE_STATIC, "inet_ntoa result");
+   return buf;
+ }
+ #endif
+ 
+ 
+ #ifdef HAVE_GETPROTOENT
+ WRAPPER2(struct protoent *, getprotoent, void)
+ {
+   struct protoent *buf;
+   buf = getprotoent ();
+   if (buf != NULL)
+     __mf_register (buf, sizeof(*buf), __MF_TYPE_STATIC, "getproto*() return");
+   return buf;
+ }
+ #endif
+ 
+ 
+ #ifdef HAVE_GETPROTOBYNAME
+ WRAPPER2(struct protoent *, getprotobyname, const char *name)
+ {
+   struct protoent *buf;
+   MF_VALIDATE_EXTENT(name, strlen(name)+1, __MF_CHECK_READ,
+                      "getprotobyname name");
+   buf = getprotobyname (name);
+   if (buf != NULL)
+     __mf_register (buf, sizeof(*buf), __MF_TYPE_STATIC,
+                    "getproto*() return");
+   return buf;
+ }
+ #endif
+ 
+ 
+ #ifdef HAVE_GETPROTOBYNUMBER
+ WRAPPER2(struct protoent *, getprotobynumber, int port)
+ {
+   struct protoent *buf;
+   buf = getprotobynumber (port);
+   if (buf != NULL)
+     __mf_register (buf, sizeof(*buf), __MF_TYPE_STATIC,
+                    "getproto*() return");
+   return buf;
+ }
+ #endif
Index: mf-hooks3.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/mf-hooks3.c,v
retrieving revision 1.5
diff -c -w -s -p -r1.5 mf-hooks3.c
*** mf-hooks3.c	21 Jul 2004 18:50:14 -0000	1.5
--- mf-hooks3.c	4 Oct 2004 17:32:04 -0000
*************** WRAPPER(void, pthread_exit, void *rc)
*** 597,600 ****
--- 597,601 ----
    /* __mf_state = reentrant; */
    CALL_REAL (pthread_exit, rc);
    /* NOTREACHED */
+   exit (0);  /* Satisfy noreturn attribute of pthread_exit.  */
  }
Index: mf-runtime.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/mf-runtime.c,v
retrieving revision 1.17
diff -c -w -s -p -r1.17 mf-runtime.c
*** mf-runtime.c	7 Sep 2004 21:52:51 -0000	1.17
--- mf-runtime.c	4 Oct 2004 17:32:04 -0000
*************** static struct option
*** 310,345 ****
        set_option,
        read_integer_option,
      } type;
!   int value;
!   int *target;
  } 
  options [] =
    {
      {"mode-nop", 
       "mudflaps do nothing", 
!      set_option, (int)mode_nop, (int *)&__mf_opts.mudflap_mode},    
      {"mode-populate", 
       "mudflaps populate object tree", 
!      set_option, (int)mode_populate, (int *)&__mf_opts.mudflap_mode},    
      {"mode-check", 
       "mudflaps check for memory violations",
!      set_option, (int)mode_check, (int *)&__mf_opts.mudflap_mode},
      {"mode-violate", 
       "mudflaps always cause violations (diagnostic)",
!      set_option, (int)mode_violate, (int *)&__mf_opts.mudflap_mode},
     
      {"viol-nop", 
       "violations do not change program execution",
!      set_option, (int)viol_nop, (int *)&__mf_opts.violation_mode},
      {"viol-abort", 
       "violations cause a call to abort()",
!      set_option, (int)viol_abort, (int *)&__mf_opts.violation_mode},
      {"viol-segv", 
       "violations are promoted to SIGSEGV signals",
!      set_option, (int)viol_segv, (int *)&__mf_opts.violation_mode},
      {"viol-gdb", 
       "violations fork a gdb process attached to current program",
!      set_option, (int)viol_gdb, (int *)&__mf_opts.violation_mode},
      {"trace-calls", 
       "trace calls to mudflap runtime library",
       set_option, 1, &__mf_opts.trace_mf_calls},
--- 310,345 ----
        set_option,
        read_integer_option,
      } type;
!   unsigned value;
!   unsigned *target;
  } 
  options [] =
    {
      {"mode-nop", 
       "mudflaps do nothing", 
!      set_option, (unsigned)mode_nop, (unsigned *)&__mf_opts.mudflap_mode},    
      {"mode-populate", 
       "mudflaps populate object tree", 
!      set_option, (unsigned)mode_populate, (unsigned *)&__mf_opts.mudflap_mode},    
      {"mode-check", 
       "mudflaps check for memory violations",
!      set_option, (unsigned)mode_check, (unsigned *)&__mf_opts.mudflap_mode},
      {"mode-violate", 
       "mudflaps always cause violations (diagnostic)",
!      set_option, (unsigned)mode_violate, (unsigned *)&__mf_opts.mudflap_mode},
     
      {"viol-nop", 
       "violations do not change program execution",
!      set_option, (unsigned)viol_nop, (unsigned *)&__mf_opts.violation_mode},
      {"viol-abort", 
       "violations cause a call to abort()",
!      set_option, (unsigned)viol_abort, (unsigned *)&__mf_opts.violation_mode},
      {"viol-segv", 
       "violations are promoted to SIGSEGV signals",
!      set_option, (unsigned)viol_segv, (unsigned *)&__mf_opts.violation_mode},
      {"viol-gdb", 
       "violations fork a gdb process attached to current program",
!      set_option, (unsigned)viol_gdb, (unsigned *)&__mf_opts.violation_mode},
      {"trace-calls", 
       "trace calls to mudflap runtime library",
       set_option, 1, &__mf_opts.trace_mf_calls},
*************** __wrap_main (int argc, char* argv[])
*** 728,733 ****
--- 728,734 ----
  {
    extern char **environ;
    extern int main ();
+   extern int __real_main ();
    static int been_here = 0;
  
    if (__mf_opts.heur_std_data && ! been_here)
Index: mf-runtime.h.in
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/mf-runtime.h.in,v
retrieving revision 1.6
diff -c -w -s -p -r1.6 mf-runtime.h.in
*** mf-runtime.h.in	7 Sep 2004 21:52:51 -0000	1.6
--- mf-runtime.h.in	4 Oct 2004 17:32:04 -0000
*************** extern int __mf_set_options (const char 
*** 197,202 ****
--- 197,207 ----
  #pragma redefine_extname getservbyname __mfwrap_getservbyname
  #pragma redefine_extname getservbyport __mfwrap_getservbyport
  #pragma redefine_extname gai_strerror __mfwrap_gai_strerror
+ #pragma redefine_extname getmntent __mfwrap_getmntent
+ #pragma redefine_extname inet_ntoa __mfwrap_inet_ntoa
+ #pragma redefine_extname getprotoent __mfwrap_getprotoent
+ #pragma redefine_extname getprotobyname __mfwrap_getprotobyname
+ #pragma redefine_extname getprotobynumber __mfwrap_getprotobynumber
  
  /* Disable glibc macros.  */
  #define __NO_STRING_INLINES



More information about the Gcc-patches mailing list