This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC] improve tls access for tolower table and errno
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Cc: "H.J. Lu" <hjl dot tools at gmail dot com>
- Date: Sat, 6 Jun 2015 14:40:02 +0200
- Subject: [RFC] improve tls access for tolower table and errno
- Authentication-results: sourceware.org; auth=none
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())