From patchwork Mon Dec 12 12:00:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 18384 Received: (qmail 19595 invoked by alias); 12 Dec 2016 12:00:42 -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 19562 invoked by uid 89); 12 Dec 2016 12:00:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=sn, dijkstra, Dijkstra, Wilco X-HELO: EUR03-DB5-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: "libc-alpha@sourceware.org" CC: nd Subject: [GLIBC][PATCH] Remove strdup inlines Date: Mon, 12 Dec 2016 12:00:28 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-office365-filtering-correlation-id: 8f9bd461-3fea-4c59-ff92-08d422867704 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:AM5PR0802MB2610; x-microsoft-exchange-diagnostics: 1; AM5PR0802MB2610; 7:bOSoqf9E+RYXxclN7kRFPXulHBza04Tp9EXDPnNRV6zK+lXIfRJkTzFrWWxPZtQ1L+w/gaAjUj7SxwtYNNEIuFvyXuApDOw0yEY6/rR7MmfDN1/+quJcJ394Zkojq+T/hw4RNOTsoM3iDqlb6o22pAXmmn9HVMdo6qkVraVGmGDuv6kQNwL/LJTAck7bLvaDjCo8kveW5rHEVjuO6TTg0YbJSbcH7bYxBCLuBw96MTJPsPmeTWuF5Kg5M8pDYhmoSkfuYA2m1oe3wzbP2HXKMPqL6cxl0E0+8Neb0sv6NqGXpqvOUSj3qMIuXQBCDgL92LOC0j8ceCsTieT/ghwSHDJ17918kpBPSlcLItTS7G8wyKvokul4cjkJGI30o3n0xhKCdFxf80gzPbN8Qhu2zT2/6hvJIT0YalLpKa4C/xs9iSUeT7CJObDtamUiW2KkKeokcMzkkytVKPqi15ywIQ== 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)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123560025)(20161123558021)(20161123555025)(20161123564025)(6072148); SRVR:AM5PR0802MB2610; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2610; x-forefront-prvs: 0154C61618 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(39850400002)(39450400003)(39840400002)(39410400002)(189002)(54534003)(377424004)(199003)(97736004)(305945005)(3660700001)(9686002)(92566002)(106116001)(7736002)(68736007)(6506006)(5640700002)(2906002)(2900100001)(105586002)(4326007)(2351001)(76576001)(81156014)(81166006)(33656002)(106356001)(8676002)(8936002)(3280700002)(2501003)(101416001)(74316002)(450100001)(3846002)(122556002)(110136003)(6436002)(86362001)(575784001)(5660300001)(77096006)(7696004)(189998001)(6916009)(54356999)(66066001)(6116002)(4001150100001)(50986999)(102836003)(38730400001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0802MB2610; H:AM5PR0802MB2610.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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 12:00:28.2840 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2610 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. Avoid linknamespace and localplt failures by redirecting str(n)dup to GCC builtins. ChangeLog: 2015-12-12 Wilco Dijkstra * string/string.h (strdup): Use builtin. (strndup): Likewise. * string/bits/string2.h (__strdup): Remove define. (strdup): Likewise. (__strndup): Likewise. (strndup): Likewise. 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