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]

[libiberty patch]: Change strncmp test in the way it uses mmap


The libiberty configure test for the presence of strncmp (libiberty_AC_FUNC_STRNCMP) actually is trying to check, and I quote its comment, "Check whether strncmp reads past the end of its string parameters".  It does this by allocating space using a mmap over "file" /dev/zero.  If the mmap fails then it considers that strncmp must be generated in libiberty.  The problem here is that (a) on our OSX (and Darwin) systems a mmap over /dev/zero is not supported and (b) I could argue that basing a failing mmap for the presence of strncmp is not the correct way to determine whether strncmp is indeed in a system.

This patch doesn't address (b) but does make the mmap test more general so that it works on our system and should work on other systems as well.  Basically it will use a mmap on an anonymous chunk of memory.

Note, this patch as also been used to the libiberty in gdb so that should be changed as well.

Ira

                        -----------------------------

2001-12-28  Ira Ruben	<ira@apple.com>

	Modify strncmp test.
	* aclocal.m4 (libiberty_AC_FUNC_STRNCMP): Handle mmap differently.
	* configure: Regenerated.


Index: aclocal.m4
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/aclocal.m4,v
retrieving revision 1.4
diff -c -3 -p -r1.4 aclocal.m4
*** aclocal.m4	2001/03/06 09:52:35	1.4
--- aclocal.m4	2001/12/28 22:49:29
*************** AC_CACHE_CHECK([for working strncmp], ac
*** 18,29 ****
  #include <sys/mman.h>
  #endif
  
! #ifndef MAP_ANON
! #ifdef MAP_ANONYMOUS
! #define MAP_ANON MAP_ANONYMOUS
! #else
! #define MAP_ANON MAP_FILE
! #endif
  #endif
  
  #ifndef MAP_FILE
--- 18,25 ----
  #include <sys/mman.h>
  #endif
  
! #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
! #define MAP_ANONYMOUS MAP_ANON
  #endif
  
  #ifndef MAP_FILE
*************** main ()
*** 41,52 ****
    char *p;
    int dev_zero;
  
    dev_zero = open ("/dev/zero", O_RDONLY);
    if (dev_zero < 0)
      exit (1);
    
    p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
! 		     MAP_ANON|MAP_PRIVATE, dev_zero, 0);
    if (p == (char *)-1)
      exit (2);
    else
--- 37,54 ----
    char *p;
    int dev_zero;
  
+ #ifndef MAP_ANONYMOUS
    dev_zero = open ("/dev/zero", O_RDONLY);
    if (dev_zero < 0)
      exit (1);
    
+   p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
+ 		     MAP_FILE | MAP_PRIVATE, dev_zero, 0);
+ #else
    p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
! 		     MAP_ANON|MAP_PRIVATE, -1, 0);
! #endif
! 
    if (p == (char *)-1)
      exit (2);
    else
Index: configure
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/configure,v
retrieving revision 1.40
diff -c -3 -p -r1.40 configure
*** configure	2001/12/24 17:51:40	1.40
--- configure	2001/12/28 22:49:32
*************** else
*** 3121,3132 ****
  #include <sys/mman.h>
  #endif
  
! #ifndef MAP_ANON
! #ifdef MAP_ANONYMOUS
! #define MAP_ANON MAP_ANONYMOUS
! #else
! #define MAP_ANON MAP_FILE
! #endif
  #endif
  
  #ifndef MAP_FILE
--- 3121,3128 ----
  #include <sys/mman.h>
  #endif
  
! #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
! #define MAP_ANONYMOUS MAP_ANON
  #endif
  
  #ifndef MAP_FILE
*************** main ()
*** 3144,3155 ****
    char *p;
    int dev_zero;
  
    dev_zero = open ("/dev/zero", O_RDONLY);
    if (dev_zero < 0)
      exit (1);
    
    p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
! 		     MAP_ANON|MAP_PRIVATE, dev_zero, 0);
    if (p == (char *)-1)
      exit (2);
    else
--- 3140,3157 ----
    char *p;
    int dev_zero;
  
+ #ifndef MAP_ANONYMOUS
    dev_zero = open ("/dev/zero", O_RDONLY);
    if (dev_zero < 0)
      exit (1);
    
+   p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
+ 		     MAP_FILE | MAP_PRIVATE, dev_zero, 0);
+ #else
    p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
! 		     MAP_ANON|MAP_PRIVATE, -1, 0);
! #endif
! 
    if (p == (char *)-1)
      exit (2);
    else
*************** main ()
*** 3167,3173 ****
  }
  
  EOF
! if { (eval echo configure:3171: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
  then
    ac_cv_func_strncmp_works=yes
  else
--- 3169,3175 ----
  }
  
  EOF
! if { (eval echo configure:3173: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
  then
    ac_cv_func_strncmp_works=yes
  else


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