This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

[PATCH] Replace __bzero with memset


Replace all internal uses of __bzero with memset.  This removes the need
to redirect it to a builtin and means memset is inlined whenever possible,
including with -Os.

ChangeLog:
2017-06-12  Wilco Dijkstra  <wdijkstr@arm.com>

        * string/bits/string2.h (__bzero): Remove define.
        * sunrpc/bindrsvprt.c (bindresvport): Change __bzero to memset.
        * sunrpc/clnt_gen.c (clnt_create): Likewise.
        * sunrpc/des_impl.c (_des_crypt): Likewise.
        * sunrpc/key_call.c (key_gendes): Likewise.
        * sunrpc/pmap_rmt.c (clnt_broadcast): Likewise.
        * sunrpc/svc_simple.c (universal): Likewise.
        * sunrpc/svc_tcp.c (svctcp_create): Likewise.
        * sunrpc/svc_udp.c (svcudp_bufcreate): Likewise.
        * sysdeps/arm/aeabi_memclr.c (__aeabi_memclr): Likewise.

--
diff --git a/string/bits/string2.h b/string/bits/string2.h
index 591533658dcef1dbde3d0579c795b72b8ef72f43..c3fc3eae592ecef5d2a0fdd94c0d65cd1407c9d6 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -52,9 +52,6 @@
 #define __string2_1bptr_p(__x) \
   ((size_t)(const void *)((__x) + 1) - (size_t)(const void *)(__x) == 1)
 
-/* Set N bytes of S to 0.  */
-#define __bzero(s, n) __builtin_memset (s, '\0', n)
-
 /* Copy SRC to DEST, returning pointer to final NUL byte.  */
 #ifndef __stpcpy
 # define __stpcpy(dest, src) __builtin_stpcpy (dest, src)
diff --git a/sunrpc/bindrsvprt.c b/sunrpc/bindrsvprt.c
index 13bcb27d4d5fdf26de7e95c3d4d4023b3af3d270..da33c05101d9430530461e4941ca7cdc81a0e46f 100644
--- a/sunrpc/bindrsvprt.c
+++ b/sunrpc/bindrsvprt.c
@@ -61,7 +61,7 @@ bindresvport (int sd, struct sockaddr_in *sin)
   if (sin == (struct sockaddr_in *) 0)
     {
       sin = &myaddr;
-      __bzero (sin, sizeof (*sin));
+      memset (sin, 0, sizeof (*sin));
       sin->sin_family = AF_INET;
     }
   else if (sin->sin_family != AF_INET)
diff --git a/sunrpc/clnt_gen.c b/sunrpc/clnt_gen.c
index 8dffaa9fa6b2e6cb1438c07a15f1831c92d5c810..62f56ea68c541806fd43d433aa5125c1a7449600 100644
--- a/sunrpc/clnt_gen.c
+++ b/sunrpc/clnt_gen.c
@@ -56,7 +56,7 @@ clnt_create (const char *hostname, u_long prog, u_long vers,
 
   if (strcmp (proto, "unix") == 0)
     {
-      __bzero ((char *)&sun, sizeof (sun));
+      memset ((char *)&sun, 0, sizeof (sun));
       sun.sun_family = AF_UNIX;
       strcpy (sun.sun_path, hostname);
       sock = RPC_ANYSOCK;
diff --git a/sunrpc/des_impl.c b/sunrpc/des_impl.c
index 1757dc1fb2c3f66514dae000a1aea67bccd6439c..da0b8cee1536392005b159b89ccb0823af1ee493 100644
--- a/sunrpc/des_impl.c
+++ b/sunrpc/des_impl.c
@@ -590,7 +590,7 @@ _des_crypt (char *buf, unsigned len, struct desparams *desp)
     }
   tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
   tbuf[0] = tbuf[1] = 0;
-  __bzero (schedule, sizeof (schedule));
+  memset (schedule, 0, sizeof (schedule));
 
   return (1);
 }
diff --git a/sunrpc/key_call.c b/sunrpc/key_call.c
index a0d9a2a0d157288a419b044a2d24816266d01417..70599761009aae481b667a2772842d5aed7df2ac 100644
--- a/sunrpc/key_call.c
+++ b/sunrpc/key_call.c
@@ -218,7 +218,7 @@ key_gendes (des_block *key)
   sin.sin_family = AF_INET;
   sin.sin_port = 0;
   sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-  __bzero (sin.sin_zero, sizeof (sin.sin_zero));
+  memset (sin.sin_zero, 0, sizeof (sin.sin_zero));
   socket = RPC_ANYSOCK;
   client = clntudp_bufcreate (&sin, (u_long) KEY_PROG, (u_long) KEY_VERS,
 			      trytimeout, &socket, RPCSMALLMSGSIZE,
diff --git a/sunrpc/pmap_rmt.c b/sunrpc/pmap_rmt.c
index e54fe1447004c6b12e2af7884d4174661988333c..9fec6c4d354b3b8c782c60bed6ea162662f39969 100644
--- a/sunrpc/pmap_rmt.c
+++ b/sunrpc/pmap_rmt.c
@@ -256,7 +256,7 @@ clnt_broadcast (/* program number */
   fd.fd = sock;
   fd.events = POLLIN;
   nets = getbroadcastnets (addrs, sizeof (addrs) / sizeof (addrs[0]));
-  __bzero ((char *) &baddr, sizeof (baddr));
+  memset ((char *) &baddr, 0, sizeof (baddr));
   baddr.sin_family = AF_INET;
   baddr.sin_port = htons (PMAPPORT);
   baddr.sin_addr.s_addr = htonl (INADDR_ANY);
diff --git a/sunrpc/svc_simple.c b/sunrpc/svc_simple.c
index acc9b9db14fa24b4b04e4ddca7d10980e661fe88..f12ed31441f8ca094ffebff3af973dea4a2413d7 100644
--- a/sunrpc/svc_simple.c
+++ b/sunrpc/svc_simple.c
@@ -154,7 +154,7 @@ universal (struct svc_req *rqstp, SVCXPRT *transp_l)
     if (pl->p_prognum == prog && pl->p_procnum == proc)
       {
 	/* decode arguments into a CLEAN buffer */
-	__bzero (xdrbuf, sizeof (xdrbuf));	/* required ! */
+	memset (xdrbuf, 0, sizeof (xdrbuf));	/* required ! */
 	if (!svc_getargs (transp_l, pl->p_inproc, xdrbuf))
 	  {
 	    svcerr_decode (transp_l);
diff --git a/sunrpc/svc_tcp.c b/sunrpc/svc_tcp.c
index db855a3f51e8195b3f6cc05d20c5c5b6741fd1bf..ac75d5c86c6c2cc8fc4e923c92eece2e60f41ac8 100644
--- a/sunrpc/svc_tcp.c
+++ b/sunrpc/svc_tcp.c
@@ -166,7 +166,7 @@ svctcp_create (int sock, u_int sendsize, u_int recvsize)
 	}
       madesock = TRUE;
     }
-  __bzero ((char *) &addr, sizeof (addr));
+  memset ((char *) &addr, 0, sizeof (addr));
   addr.sin_family = AF_INET;
   if (bindresvport (sock, &addr))
     {
diff --git a/sunrpc/svc_udp.c b/sunrpc/svc_udp.c
index 5f6219f91ceb3f094439b83aa964cd698bef9a57..122bad830b5d2ea9881b5bb71b4d78193ac07106 100644
--- a/sunrpc/svc_udp.c
+++ b/sunrpc/svc_udp.c
@@ -137,7 +137,7 @@ svcudp_bufcreate (int sock, u_int sendsz, u_int recvsz)
 	}
       madesock = TRUE;
     }
-  __bzero ((char *) &addr, sizeof (addr));
+  memset ((char *) &addr, 0, sizeof (addr));
   addr.sin_family = AF_INET;
   if (bindresvport (sock, &addr))
     {
diff --git a/sysdeps/arm/aeabi_memclr.c b/sysdeps/arm/aeabi_memclr.c
index 6687e49c9ee1891516643bd339ffc8ced3596f27..03263ea8037a7e542fde1b9f27e957fdb5d57f21 100644
--- a/sysdeps/arm/aeabi_memclr.c
+++ b/sysdeps/arm/aeabi_memclr.c
@@ -17,12 +17,12 @@
 
 #include <string.h>
 
-/* Clear memory.  Can't alias to bzero because it's not defined in the
-   same translation unit.  */
+/* Set memory like memset, but different argument order and no return
+   value required.  Also only integer caller-saves may be used.  */
 void
 __aeabi_memclr (void *dest, size_t n)
 {
-  __bzero (dest, n);
+  memset (dest, 0, n);
 }
 
 /* Versions of the above which may assume memory alignment.  */

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