From patchwork Fri Sep 29 16:46:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 23233 Received: (qmail 60026 invoked by alias); 29 Sep 2017 16:46:22 -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 60014 invoked by uid 89); 29 Sep 2017 16:46:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=redirects X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: "libc-alpha@sourceware.org" CC: nd Subject: [RFC] Using protected for math symbols Date: Fri, 29 Sep 2017 16:46:15 +0000 Message-ID: x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB2054; 6:MkCQW5tMz1e3M5Jsf31Ct/7F98/7k91K6sB2z82YzCZL9v7Z2HZjs1t1tOwaGPayHDZbIdmg7gRDbdgkMp9YfACTWIGScAhJYy+OOzWdluyQMvtNV769fpQGUtPOgB1uREVO7sJ0urBeZSlpEjIwn+r9YLAFS+aV4XMZAiEdprHQsMCoxwZZOiHR1Dw1RA00TtZnLTFKzLYMF13amt8rKX4FCSPND5MaiZjrRT8B55hJv+sDpy+O95mYFMoHL7u2u+8nVdimQY6EjkvaglJpGbi49l3tB/0OjANOoeNHFfN/SXSS1pESJ1wOcBEnhfUPXP2mpwoja6e0/PzhFJclOQ==; 5:cXb7IgLBweWWiBCx07Mz3+R9QuBMq5ua4HLgzQPg3wMZY+kG8kM+m+FaQs/b+7SYFdDrCfpzvmjH+bC9GfEVw7b+JZI2+1JkiGpeEzCAgz6OqnTBsnU+YcTn+3O+qPePc6QxpsjcWQY4QV46AzagYQ==; 24:93nqZs93V6jg9HuevGeciRzQSDwmq2oITCSELISaix7t+itap41wN1TQXqMbuk7laqvEvX7Snk9CgDXmKQWcD1KHkfm633IMS4UFVMuGUEM=; 7:KJsKl17/818BSZuyF0+I2MeJGslY8v7rsBHFKHlVgWR/EJPoCliAiBNPppt25Ld+p4TwLXuiPZ1mlTBfDgzp2so/354FOR/VB3U2I75Qtit+s3tkTeMxGsWbG0X0Ud6uZSItTwpaFhfdpJ76hx1dJkQDdAmM1DCH4k5F41fAHrCu7YvdfF24/BPSZLXcKChfeY0oDd7kdfNAGgZ3RhM4uut5qAnyUU5v/7tohHdP7Vk= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 7932cab8-2893-4393-adfd-08d5075999e1 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DB6PR0801MB2054; x-ms-traffictypediagnostic: DB6PR0801MB2054: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(250305191791016)(22074186197030); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123562025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0801MB2054; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0801MB2054; x-forefront-prvs: 0445A82F82 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(346002)(376002)(199003)(189002)(6436002)(86362001)(478600001)(6116002)(72206003)(5250100002)(2351001)(66066001)(25786009)(4326008)(102836003)(3846002)(105586002)(33656002)(5640700003)(9686003)(106356001)(99286003)(55016002)(6306002)(68736007)(6506006)(8676002)(53936002)(2906002)(3280700002)(81156014)(575784001)(101416001)(7696004)(8936002)(14454004)(2501003)(2900100001)(3660700001)(81166006)(6916009)(5660300001)(54356999)(50986999)(305945005)(316002)(74316002)(97736004)(189998001)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB2054; H:DB6PR0801MB2053.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) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Sep 2017 16:46:15.7199 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2054 GLIBC uses non-standard names internally for math calls. As a result even basic functions like sqrt and fabs are not inlined by default. I recently posted patches to inline sqrt and fabs. In order for this to work in cases GCC doesn't inline, asm redirects and conditional defines are needed. An alternative approach to this is to completely remove the __sqrt variants and use protected symbol visibility. This means math functions are defined using their real name, internal calls use the real name and don't generate PLT calls, and no more weak/redirect magic is needed. It seems much cleaner to do it this way, so my question is, are there any issues with this approach? The patch below shows how it might look like for sqrt as the difference between the current approach and the proposed one. Only generic code has been changed - target specific assembly code may need similar edits: diff --git a/include/math.h b/include/math.h index e176b090caa9f07c226aff0f9c6c5bf34740f2ec..e6be1ac349c75b2ddd16f17384bb9267e15984dd 100644 --- a/include/math.h +++ b/include/math.h @@ -55,14 +55,10 @@ libm_hidden_proto (__expf128) libm_hidden_proto (__expm1f128) # endif -# ifndef NO_SQRT_REDIRECT -/* Declare sqrt for use within GLIBC. Sqrt will typically inline into a - single instruction. Use an asm to avoid use of PLTs if it doesn't. */ -float sqrtf (float) asm ("__ieee754_sqrtf"); -double sqrt (double) asm ("__ieee754_sqrt"); -# ifndef __NO_LONG_DOUBLE_MATH -long double sqrtl (long double) asm ("__ieee754_sqrtl"); -# endif +float sqrtf (float) __attribute__ ((visibility ("protected"))); +double sqrt (double) __attribute__ ((visibility ("protected"))); +# ifndef __NO_LONG_DOUBLE_MATH +long double sqrtl (long double) __attribute__ ((visibility ("protected"))); # endif #endif diff --git a/math/w_sqrt_compat.c b/math/w_sqrt_compat.c index fe068af9597ffb0f15b32cd454b4c34ba8bc060e..560cab2eb813df3ee56a2f88a835068139be0ac9 100644 --- a/math/w_sqrt_compat.c +++ b/math/w_sqrt_compat.c @@ -16,7 +16,6 @@ License along with the GNU C Library; if not, see . */ -#define NO_SQRT_REDIRECT #include #include #include @@ -26,12 +25,11 @@ #if LIBM_SVID_COMPAT /* wrapper sqrt */ double -__sqrt (double x) +sqrt (double x) { if (__builtin_expect (isless (x, 0.0), 0) && _LIB_VERSION != _IEEE_) return __kernel_standard (x, x, 26); /* sqrt(negative) */ return __ieee754_sqrt (x); } -libm_alias_double (__sqrt, sqrt) #endif diff --git a/math/w_sqrt_template.c b/math/w_sqrt_template.c index 235c263e60c85422e41bca7c817148b66030438f..58b95d0f3751e05760d9841a37cef7217c0caccb 100644 --- a/math/w_sqrt_template.c +++ b/math/w_sqrt_template.c @@ -21,20 +21,18 @@ for each floating-point type. */ #if __USE_WRAPPER_TEMPLATE -#define NO_SQRT_REDIRECT # include # include # include # include FLOAT -M_DECL_FUNC (__sqrt) (FLOAT x) +M_DECL_FUNC (sqrt) (FLOAT x) { if (__glibc_unlikely (isless (x, M_LIT (0.0)))) /* Domain error: sqrt(x<-0). */ __set_errno (EDOM); return M_SUF (__ieee754_sqrt) (x); } -declare_mgen_alias (__sqrt, sqrt) #endif /* __USE_WRAPPER_TEMPLATE. */ diff --git a/math/w_sqrtf_compat.c b/math/w_sqrtf_compat.c index 880be0936d9a20f9aa75cf2d66000f0c621f090f..1ed54f1e522d0cf179aa2eed3e0870defc87d9e3 100644 --- a/math/w_sqrtf_compat.c +++ b/math/w_sqrtf_compat.c @@ -16,7 +16,6 @@ License along with the GNU C Library; if not, see . */ -#define NO_SQRT_REDIRECT #include #include #include @@ -26,12 +25,11 @@ #if LIBM_SVID_COMPAT /* wrapper sqrtf */ float