lib{c,sys}: stop exposing errno symbol

Officially since C11 (and in reality FreeBSD since 3.0 with commit
1b46cb523d) errno has been defined to be a macro.  Rename the symbol
to __libsys_errno and move it to FBSDprivate_1.0 and confine it entierly
to libsys for use by libthr.  Add a FBSD_1.0 compat symbol for existing
binaries that were incorrectly linked to the errno symbol during
libc.so.7's lifetime.

This deliberately breaks linking software that directly links to errno.
Such software is broken and will fail in surprising ways if it becomes
threaded (e.g., if it triggers loading of a pam or nss module that
uses threads.)

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46780
This commit is contained in:
Brooks Davis 2024-09-27 20:27:46 +01:00
parent 0b325167f6
commit 1235d276b7
6 changed files with 13 additions and 13 deletions

View file

@ -25,6 +25,8 @@ MK_SSP= no
INCS= libsys.h _libsys.h
CFLAGS+=-DLIBSYS
CFLAGS+=-I${LIBSYS_SRCTOP}/include -I${LIBC_SRCTOP}/include
CFLAGS+=-I${LIBSYS_SRCTOP}/${LIBC_ARCH}
CFLAGS+=-I${LIBC_SRCTOP}/${LIBC_ARCH}

View file

@ -1,5 +1,6 @@
FBSDprivate_1.0 {
__elf_aux_vector;
__libsys_errno;
__getosreldate;
__libsys_interposing_slot;
__realpathat;

View file

@ -72,7 +72,6 @@ FBSD_1.0 {
extattr_set_file;
extattr_set_link;
extattrctl;
errno;
fchdir;
fchflags;
fchmod;

View file

@ -31,13 +31,15 @@
#include "libc_private.h"
int errno;
int __libsys_errno;
#ifdef LIBSYS
__sym_compat(errno, __libsys_errno, FBSD_1.0);
#endif
static int *
__error_unthreaded(void)
{
return (&errno);
return (&__libsys_errno);
}
static int *(*__error_selector)(void) = __error_unthreaded;
@ -45,13 +47,11 @@ static int *(*__error_selector)(void) = __error_unthreaded;
void
__set_error_selector(int *(*arg)(void))
{
__error_selector = arg;
}
int *
__error(void)
{
return (__error_selector());
}

View file

@ -39,8 +39,7 @@
#include "libc_private.h"
#include "thr_private.h"
#undef errno
extern int errno;
extern int __libsys_errno;
__weak_reference(__error_threaded, __error);
int *
@ -53,5 +52,5 @@ __error_threaded(void)
if (curthread != NULL && curthread != _thr_initial)
return (&curthread->error);
}
return (&errno);
return (&__libsys_errno);
}

View file

@ -39,8 +39,7 @@
#include "rtld_lock.h"
#include "thr_private.h"
#undef errno
extern int errno;
extern int __libsys_errno;
static int _thr_rtld_clr_flag(int);
static void *_thr_rtld_lock_create(void);
@ -96,14 +95,14 @@ _thr_rtld_lock_destroy(void *lock)
if (curthread != _thr_initial) \
errsave = curthread->error; \
else \
errsave = errno; \
errsave = __libsys_errno; \
}
#define RESTORE_ERRNO() { \
if (curthread != _thr_initial) \
curthread->error = errsave; \
else \
errno = errsave; \
__libsys_errno = errsave; \
}
static void