From patchwork Mon Dec 12 13:02:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 18404 Received: (qmail 118125 invoked by alias); 12 Dec 2016 13:02:54 -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 118113 invoked by uid 89); 12 Dec 2016 13:02:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 spammy=431, 6, __END_DECLS, __end_decls, 4316 X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: Zack Weinberg CC: "libc-alpha@sourceware.org" , nd Subject: Re: [GLIBC][PATCH v2] Remove strdup inlines Date: Mon, 12 Dec 2016 13:02:40 +0000 Message-ID: References: , In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-office365-filtering-correlation-id: 30b5c532-f89b-4cdc-ba4c-08d4228f2777 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:AM5PR0802MB2611; x-microsoft-exchange-diagnostics: 1; AM5PR0802MB2611; 7:2n4u0KR9ilMmxE7VYddTZWGRKmozz6qzwcmZpsZPoCkmsIGcg0aT8IH3XBoPQXHYduHmTWDQJmZgLpoQp0JM/PiAOzd6fUIQ3ZooRKV3YnenQ2qlrv4QRkgy579F3wM5bn1I/dLyjZN+B1JVulyldZAoElV5yc/yydgKqOeW0BtbomAIQ6q+Ndj2Hu2N+iuRu9uxU/sIZhZlcOJPmreVkwHbc1gYY/ANeOjg1hmLed4F2KRTJPaPIE03xNnQ8xZDmukF0UV/qefiXs+a0o6pRIkGIZmyUHYeJyAULMeVAys8V3LjgWv0wmxiMvjg8fzJ5782gfrUekiWvtfUzfJjzGmc7wrlSpbWPO3L6C6nyt8pmqzkCi6KP7FzGSXKvxcYO2k4TkKVzxChKzFJh0fCc+/9pZOyBIqcl+2n9IaIFUpSssyzeRMon5FDHcdKu77LK5oc3PYVDIkKzvEz/dmtGg== nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(211171220733660); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(6072148); SRVR:AM5PR0802MB2611; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2611; x-forefront-prvs: 0154C61618 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(39450400003)(39860400002)(39840400002)(39410400002)(39850400002)(199003)(189002)(377424004)(54534003)(24454002)(377454003)(189998001)(7696004)(76576001)(81156014)(8676002)(4326007)(81166006)(8936002)(5660300001)(575784001)(6436002)(2950100002)(86362001)(6116002)(3660700001)(74316002)(68736007)(7736002)(9686002)(3846002)(305945005)(33656002)(102836003)(2906002)(6916009)(101416001)(110136003)(76176999)(97736004)(50986999)(2900100001)(38730400001)(122556002)(92566002)(229853002)(66066001)(6506006)(3280700002)(106116001)(4001150100001)(54356999)(106356001)(105586002)(77096006); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0802MB2611; H:AM5PR0802MB2610.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Dec 2016 13:02:40.2316 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2611 Zack Weinberg wrote: > On Mon, Dec 12, 2016 at 7:00 AM, Wilco Dijkstra wrote: > > Remove the str(n)dup inlines from string/bits/string2.h.  Although inlining > > calls with constant strings shows a small (~10%) performance gain, strdup is > > typically used in error reporting code, so not performance critical. > > Looks good to me. > > This is the sole user of __need_malloc_and_calloc, so please also remove the > logic implementing that from {include,stdlib}/stdlib.h. Good point, I've removed those defines too in v2: Remove the str(n)dup inlines from string/bits/string2.h. Although inlining calls with constant strings shows a small (~10%) performance gain, strdup is typically used in error reporting code, so not performance critical. Remove the now unused __need_malloc_and_calloc related defines from stdlib.h. Avoid linknamespace and localplt failures by redirecting str(n)dup to GCC builtins. ChangeLog: 2015-12-12 Wilco Dijkstra * include/stdlib.h (__need_malloc_and_calloc): Remove uses. (__Need_M_And_C) Remove define/undef. * stdlib/stdlib.h (__need_malloc_and_calloc): Remove uses. (__malloc_and_calloc_defined): Remove define. * string/string.h (strdup): Use builtin. (strndup): Likewise. * string/bits/string2.h (__strdup): Remove define. (strdup): Likewise. (__strndup): Likewise. (strndup): Likewise. diff --git a/include/stdlib.h b/include/stdlib.h index 352339e8595eb8229018cb27f7d2decf63f511c7..929cead59ae10afe03ae1286b72d8321f0ab2d90 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -1,16 +1,12 @@ #ifndef _STDLIB_H -#ifdef __need_malloc_and_calloc -#define __Need_M_And_C -#endif - #ifndef _ISOMAC # include #endif #include /* Now define the internal interfaces. */ -#if !defined __Need_M_And_C && !defined _ISOMAC +#if !defined _ISOMAC # include __BEGIN_DECLS @@ -269,6 +265,4 @@ __END_DECLS #endif -#undef __Need_M_And_C - #endif /* include/stdlib.h */ diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h index 48f9a9500e736a5d85e5eca2e511cff374e43226..b1696c7a8d82145f76760a49909e24c288c51263 100644 --- a/stdlib/stdlib.h +++ b/stdlib/stdlib.h @@ -26,15 +26,12 @@ /* Get size_t, wchar_t and NULL from . */ #define __need_size_t -#ifndef __need_malloc_and_calloc -# define __need_wchar_t -# define __need_NULL -#endif +#define __need_wchar_t +#define __need_NULL #include __BEGIN_DECLS -#ifndef __need_malloc_and_calloc #define _STDLIB_H 1 #if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H @@ -434,10 +431,6 @@ extern int lcong48_r (unsigned short int __param[7], # endif /* Use misc. */ #endif /* Use misc or X/Open. */ -#endif /* don't just need malloc and calloc */ - -#ifndef __malloc_and_calloc_defined -# define __malloc_and_calloc_defined __BEGIN_NAMESPACE_STD /* Allocate SIZE bytes of memory. */ extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur; @@ -445,9 +438,7 @@ extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur; extern void *calloc (size_t __nmemb, size_t __size) __THROW __attribute_malloc__ __wur; __END_NAMESPACE_STD -#endif -#ifndef __need_malloc_and_calloc __BEGIN_NAMESPACE_STD /* Re-allocate the previously allocated block in PTR, making the new block SIZE bytes long. */ @@ -944,9 +935,6 @@ extern int ttyslot (void) __THROW; # include #endif -#endif /* don't just need malloc and calloc */ -#undef __need_malloc_and_calloc - __END_DECLS #endif /* stdlib.h */ diff --git a/string/bits/string2.h b/string/bits/string2.h index 03af22cc27a33c81f36d56ddc52fce0a5ea81ece..b0be5f6a49024a0bedfc37e9ec2c0356e0e4fa09 100644 --- a/string/bits/string2.h +++ b/string/bits/string2.h @@ -118,58 +118,6 @@ #endif -/* We need the memory allocation functions for inline strdup(). - Referring to stdlib.h (even minimally) is not allowed - in any of the tight standards compliant modes. */ -#ifdef __USE_MISC - -# define __need_malloc_and_calloc -# include - -extern char *__strdup (const char *__string) __THROW __attribute_malloc__; -# define __strdup(s) \ - (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \ - ? (((const char *) (s))[0] == '\0' \ - ? (char *) calloc ((size_t) 1, (size_t) 1) \ - : ({ size_t __len = strlen (s) + 1; \ - char *__retval = (char *) malloc (__len); \ - if (__retval != NULL) \ - __retval = (char *) memcpy (__retval, s, __len); \ - __retval; })) \ - : __strdup (s))) - -# if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 -# define strdup(s) __strdup (s) -# endif - - -extern char *__strndup (const char *__string, size_t __n) - __THROW __attribute_malloc__; -# define __strndup(s, n) \ - (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \ - ? (((const char *) (s))[0] == '\0' \ - ? (char *) calloc ((size_t) 1, (size_t) 1) \ - : ({ size_t __len = strlen (s) + 1; \ - size_t __n = (n); \ - char *__retval; \ - if (__n < __len) \ - __len = __n + 1; \ - __retval = (char *) malloc (__len); \ - if (__retval != NULL) \ - { \ - __retval[__len - 1] = '\0'; \ - __retval = (char *) memcpy (__retval, s, \ - __len - 1); \ - } \ - __retval; })) \ - : __strndup (s, n))) - -# ifdef __USE_XOPEN2K8 -# define strndup(s, n) __strndup (s, n) -# endif - -#endif /* Use misc. or use GNU. */ - #ifndef _FORCE_INLINES # undef __STRING_INLINE #endif diff --git a/string/string.h b/string/string.h index b103e64912fe1904098e229ccb845bb2c5c10835..c251cc603a1dbb5bef469d4b71f90037612d36f0 100644 --- a/string/string.h +++ b/string/string.h @@ -636,6 +636,15 @@ extern char *basename (const char *__filename) __THROW __nonnull ((1)); # endif #endif +#if (defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 \ + || __GLIBC_USE (LIB_EXT2)) +# define strdup(s) __builtin_strdup (s) +#endif + +#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2) +#define strndup(s,n) __builtin_strndup (s, n) +#endif + #if defined __USE_GNU && defined __OPTIMIZE__ \ && defined __extern_always_inline && __GNUC_PREREQ (3,2) # if !defined _FORCE_INLINES && !defined _HAVE_STRING_ARCH_mempcpy