This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Improving math function wrappers
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>, Szabolcs Nagy <Szabolcs dot Nagy at arm dot com>, "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>, nd <nd at arm dot com>
- Date: Thu, 16 Mar 2017 21:36:33 +0000
- Subject: Re: Improving math function wrappers
- Authentication-results: sourceware.org; auth=none
- References: <AM5PR0802MB2610AA7EDC518B39F6D7152683260@AM5PR0802MB2610.eurprd08.prod.outlook.com> <AM5PR0802MB261064538EBF55E8B7CF1F7783260@AM5PR0802MB2610.eurprd08.prod.outlook.com> <3623011d-1a3a-c499-6b42-1d5506c6a71a@redhat.com>
On Thu, 16 Mar 2017, Florian Weimer wrote:
> We have recently removed the PID cache from the TCB. We could store the errno
> value there, instead of going through __errno_location. (Code outside glibc
> would still use __errno_location, of course.)
Code in glibc's libraries should already be setting the TLS initial-exec
errno variable directly (that's how __set_errno is defined in
include/errno.h). But any case that sets errno should not be
performance-critical; the issue is the effects on performance of non-error
cases with finite arguments (which should just be checking if the result
is non-finite or zero, depending on the function - but the issue raised
here was consequent need to save the arguments for subsequent checks in
the unlikely case to see whether e.g. a NaN result was an error or from a
NaN argument, and it's possible the code in the error case might have
other prologue/epilogue effects that don't get shrink-wrapped away).
Most of the time the checks either duplicate ones already present in the
main function implementation, or could be localized to an unlikely case
within that implementation, hence the notion that setting errno in the
main function implementation makes sense (along with avoiding extra stack
frame setup etc.).
If we set errno in some main function implementations I think we should be
clear that adding a wrapper is still a fine way to fix one of the
remaining bugs about missing errno setting in cases where
architecture-specific implementations are involved, with the option of
optimizing later by moving away from that wrapper.
--
Joseph S. Myers
joseph@codesourcery.com