errno/h_errno
H. Peter Anvin
hpa@zytor.com
Tue Jun 10 04:06:56 GMT 2025
On 2025-06-09 20:51, H. Peter Anvin wrote:
>
> Ok, I grok that back in 2016 the tools might not have been ready yet, but in 2025?
>
It is also perhaps worth noting that the errno TLS symbol is already
globally exported and visible. This code works exactly as expected when
linked against current glibc, either statically or dynamically:
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#undef errno
extern __thread int errno __attribute__((tls_model("initial-exec")));
int main(void)
{
errno = 0;
close(999);
/* errno should be EBADF now */
printf("errno = %d (%s), &errno = %p, __errno_location = %p\n",
errno, strerrorname_np(errno), &errno, __errno_location());
return 0;
}
More information about the Libc-alpha
mailing list