[RFC] improve tls access for tolower table and errno
Ondřej Bílka
neleai@seznam.cz
Sat Jun 6 18:44:00 GMT 2015
Hi, as I mentioned before that inline strcasecmp would be problematic as
it needs to get call to tolower which is suboptimal.
On architectures with tls register you don't need to do call call for tls
access but start small.
For x64 and other architectures as these variables are statically
allocated would could just save offset at register. Linker would at
initialization fill it with correct value and applications would just
need to access a normal variable.
A sample implementation would be following, where should I add
initializer and is there other way to get %fs than assembly?
#include <errno.h>
#include <stdio.h>
static long __errno_offset;
__attribute__((constructor))
void get_offset ()
{
char *offset;
char *location = &errno;
__asm__ ("mov %%fs:0, %0" : "=r" (offset));
__errno_offset = location - offset;
}
static __always_inline
int *
__ep()
{
char *__offset;
__asm__ ("mov %%fs:0, %0" : "=r" (__offset));
return (int *)(__offset + __errno_offset);
}
#define errno2 (*__ep())
More information about the Libc-alpha
mailing list