From patchwork Tue Jan 13 19:14:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 4651 Received: (qmail 12906 invoked by alias); 13 Jan 2015 19:14:56 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 12850 invoked by uid 89); 13 Jan 2015 19:14:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "Wilco Dijkstra" Cc: Subject: RE: [PATCH] Improve strncpy performance further In-Reply-To: Wilco Dijkstra's message of Sunday, 11 January 2015 18:09:25 -0000 <001a01d02dc9$bd6f0370$384d0a50$@com> References: <001801d02b72$6ce0c3c0$46a24b40$@com> <20150108185812.285782C3BF6@topped-with-meat.com> <001901d02c0d$43cf9920$cb6ecb60$@com> <20150109191632.694692C3C1F@topped-with-meat.com> <001a01d02dc9$bd6f0370$384d0a50$@com> Message-Id: <20150113191449.AD91B2C39DC@topped-with-meat.com> Date: Tue, 13 Jan 2015 11:14:49 -0800 (PST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=8A7brI4kjU8C6ETGAX3PRdgeao0=:19 a=yGweBE1_6NYCPWx3sy8A:9 a=CjuIK1q_8ugA:10 > Well, bcopy and bzero are both used in several non-test sources in GLIBC, > but one is always defined as __bzero, and the other as bcopy. There are no uses of bcopy outside of tests, and portability macros in code (possibly, or once) shared with gnulib. There is a bcopy macro in locale/programs/simple-hash.c, but it's not used anywhere. I've removed that in the patch below. There are three uses of bzero outside of tests. I've changed those to memset in the patch below. In my build (x86_64-linux-gnu, GCC 4.8.3) this did not change the compiled code at all--so they were already being reduced to memset or inlined directly by the compiler. There are also two uses of bcmp outside of tests (both in old resolver code), which is a similar case (but even easier and less useful, since it is nothing but exactly an alias for memcmp). I've changed those to memcmp in the patch below. There is a handful of uses of __bzero, all in sunrpc/ (none even in tests). We're avoiding touching sunrpc/ when it's not thoroughly necessary, so we'll leave those alone. > It's unclear to me what the exact namespace rules are (or whether there is > even a concise description of them somewhere), however it is obvious that > this is not consistent. Note any rule that relies on whether a function is > called or not from within the same library is risky unless you have > automated checks to catch that. The rules per se can be described concisely, but they incorporate by reference the set of each symbols in each standard and the dependency graph of standards that are specified as supersets of others. However, the linknamespace tests should already be prepared to catch any concrete violations. Here's what I've just committed. As I mentioned above, it caused no changes to the compiled code on x86_64-linux-gnu with gcc-4.8.3, except for the expected s/bcmp/memcmp/ changes that are trivially provably harmless. Thanks, Roland 2015-01-13 Roland McGrath * login/logout.c (logout): Use memset rather than bzero. * nis/nss_compat/compat-pwd.c (getpwent_next_file): Likewise. * nis/nss_compat/compat-spwd.c (getspent_next_file): Likewise. * resolv/gethnamaddr.c (gethostbyaddr): Use memcmp rather than bcmp. (_gethtbyaddr): Likewise. * locale/programs/simple-hash.c (bcopy): Macro removed. --- a/locale/programs/simple-hash.c +++ b/locale/programs/simple-hash.c @@ -42,10 +42,6 @@ # define BITSPERBYTE 8 #endif -#ifndef bcopy -# define bcopy(s, d, n) memcpy ((d), (s), (n)) -#endif - #define hashval_t uint32_t #include "hashval.h" --- a/login/logout.c +++ b/login/logout.c @@ -45,9 +45,9 @@ logout (const char *line) if (getutline_r (&tmp, &utbuf, &ut) >= 0) { /* Clear information about who & from where. */ - bzero (ut->ut_name, sizeof ut->ut_name); + memset (ut->ut_name, '\0', sizeof ut->ut_name); #if _HAVE_UT_HOST - 0 - bzero (ut->ut_host, sizeof ut->ut_host); + memset (ut->ut_host, '\0', sizeof ut->ut_host); #endif #if _HAVE_UT_TV - 0 struct timeval tv; --- a/nis/nss_compat/compat-pwd.c +++ b/nis/nss_compat/compat-pwd.c @@ -578,7 +578,7 @@ getpwent_next_file (struct passwd *result, ent_t *ent, char *user, *host, *domain; struct __netgrent netgrdata; - bzero (&netgrdata, sizeof (struct __netgrent)); + memset (&netgrdata, 0, sizeof (struct __netgrent)); __internal_setnetgrent (&result->pw_name[2], &netgrdata); while (__internal_getnetgrent_r (&host, &user, &domain, &netgrdata, buf2, sizeof (buf2), errnop)) --- a/nis/nss_compat/compat-spwd.c +++ b/nis/nss_compat/compat-spwd.c @@ -532,7 +532,7 @@ getspent_next_file (struct spwd *result, ent_t *ent, char *user, *host, *domain; struct __netgrent netgrdata; - bzero (&netgrdata, sizeof (struct __netgrent)); + memset (&netgrdata, 0, sizeof (struct __netgrent)); __internal_setnetgrent (&result->sp_namp[2], &netgrdata); while (__internal_getnetgrent_r (&host, &user, &domain, &netgrdata, buf2, sizeof (buf2), --- a/resolv/gethnamaddr.c +++ b/resolv/gethnamaddr.c @@ -672,8 +672,8 @@ gethostbyaddr(addr, len, af) return (NULL); } if (af == AF_INET6 && len == IN6ADDRSZ && - (!bcmp(uaddr, mapped, sizeof mapped) || - !bcmp(uaddr, tunnelled, sizeof tunnelled))) { + (!memcmp(uaddr, mapped, sizeof mapped) || + !memcmp(uaddr, tunnelled, sizeof tunnelled))) { /* Unmap. */ addr += sizeof mapped; uaddr += sizeof mapped; @@ -922,7 +922,7 @@ _gethtbyaddr(addr, len, af) _sethtent(0); while ((p = _gethtent())) - if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len)) + if (p->h_addrtype == af && !memcmp(p->h_addr, addr, len)) break; _endhtent(); return (p);