From nobody Fri Sep 27 19:33:00 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XFgbx1j4kz5X7Xb; Fri, 27 Sep 2024 19:33:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XFgbx0vx6z4T3W; Fri, 27 Sep 2024 19:33:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727465581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=USMn2k7+KZLJiJmBYSM9e2afK0Rfvr8nslxm6u2XwW8=; b=dhi01/gYnXhmgm9N/9WEc83t9/SQ7z7uYxRyMR5cSGPQJy1/Q05OGjN67qiWqIcVfOnt3W gAQwe8EZJSLBz/A3bbkopMgrP6ppeSApZRkmrK7igStQ/HqIXGS7BDtKX/BJLGVlBgy4Di 7lh2P5ivCLHzKp+gjvhVPJl6z3LHM2op8/ZYGyPkZIQStpJa5ARItvYajJiLjLFyIS9Vzk kg6Q+O+fTiC888KSyLNYaE2kebPOD+sp0V1fCg3wu0zoWahJuV+7/j8B3E95OzHXSLqq82 hIeT4O+uEAon8MTdF+0BIOVejUJq9b1MWccUzE1r/DpfzuUvLChS6Ylr7EWEMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727465581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=USMn2k7+KZLJiJmBYSM9e2afK0Rfvr8nslxm6u2XwW8=; b=VBzspu4Y6VBsc+pqkPmAsuy9HdKWzF9qWPlihR6ozzvJlRfpmcjVmcVSAtEGXcuN5/tiSw RYW1AVxM8IWKJ2mkNB0c/qwIpCm516dAwNboVcanzM24uw4FiLrNfc7r4n2ta2ylDrCQ46 AWSX/XWYMMozuBL08Y9qixgc0qaNYcJCL1vvy2Wn5RY4CHOqPtf84lBPMddie/DB5ZBzxe +UvePhZuzkML4xGNCVFTwGYPPJ1GUEpclb8cfoPhWeIIDn7ltcTDP8c987lMv/aucntHnz Nxtc31ZOBWMKebfCJ9WnNLUwJQmwoOLA1SNu0KnFrM4Dr0u3fKEKENLxldDldg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727465581; a=rsa-sha256; cv=none; b=L4kPBWmuXsEXE1o1GDuywxGUoOUZs9fNo0sFLgBy0brUXLb47GzEEK4PEXlVVCR+hPVSVF k7hruxKIQYcjOshnnZ/ud9uHbqF+B3ochl0qtIIstiDAMAFTZqZ62AvZMliCObJ0i5Xcu4 390broy11BdDIBaNHIRBatbjRbhl7RBsdGcy31wt8vZpGUW5BmYT4gvftVJ+YCmFwmJNvq 7oKpNByP7TfFY3PSNJtMh2b+YbBiaxaJI7hau2JOOquwjpCc9Ssp5FKoSzojnUkZ56FeX0 5cqZhsD4qsM3f6ytvEkDuOopSA7arBD3loxwnCu113fDINZn/HL/8ks83vzU8g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XFgbx0CPyztTS; Fri, 27 Sep 2024 19:33:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48RJX09W066671; Fri, 27 Sep 2024 19:33:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48RJX0dH066668; Fri, 27 Sep 2024 19:33:00 GMT (envelope-from git) Date: Fri, 27 Sep 2024 19:33:00 GMT Message-Id: <202409271933.48RJX0dH066668@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: 1235d276b78a - main - lib{c,sys}: stop exposing errno symbol List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1235d276b78a769bded01d51c9bf3cdc480db9fb Auto-Submitted: auto-generated The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=1235d276b78a769bded01d51c9bf3cdc480db9fb commit 1235d276b78a769bded01d51c9bf3cdc480db9fb Author: Brooks Davis AuthorDate: 2024-09-27 19:27:46 +0000 Commit: Brooks Davis CommitDate: 2024-09-27 19:27:46 +0000 lib{c,sys}: stop exposing errno symbol Officially since C11 (and in reality FreeBSD since 3.0 with commit 1b46cb523df3) 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 --- lib/libsys/Makefile | 2 ++ lib/libsys/Symbol.map | 1 + lib/libsys/Symbol.sys.map | 1 - lib/libsys/__error.c | 10 +++++----- lib/libthr/sys/thr_error.c | 5 ++--- lib/libthr/thread/thr_rtld.c | 7 +++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/libsys/Makefile b/lib/libsys/Makefile index b4c0e91e860c..b4b4662ae47f 100644 --- a/lib/libsys/Makefile +++ b/lib/libsys/Makefile @@ -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} diff --git a/lib/libsys/Symbol.map b/lib/libsys/Symbol.map index b2bc69108bbb..51ea1b5da231 100644 --- a/lib/libsys/Symbol.map +++ b/lib/libsys/Symbol.map @@ -1,5 +1,6 @@ FBSDprivate_1.0 { __elf_aux_vector; + __libsys_errno; __getosreldate; __libsys_interposing_slot; __realpathat; diff --git a/lib/libsys/Symbol.sys.map b/lib/libsys/Symbol.sys.map index 5a4e66baf3c4..85373b1f9cda 100644 --- a/lib/libsys/Symbol.sys.map +++ b/lib/libsys/Symbol.sys.map @@ -72,7 +72,6 @@ FBSD_1.0 { extattr_set_file; extattr_set_link; extattrctl; - errno; fchdir; fchflags; fchmod; diff --git a/lib/libsys/__error.c b/lib/libsys/__error.c index 1132bdba9c65..41016e9a1ed2 100644 --- a/lib/libsys/__error.c +++ b/lib/libsys/__error.c @@ -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()); } diff --git a/lib/libthr/sys/thr_error.c b/lib/libthr/sys/thr_error.c index 7ce3a84fab6b..ec7a57bf6610 100644 --- a/lib/libthr/sys/thr_error.c +++ b/lib/libthr/sys/thr_error.c @@ -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); } diff --git a/lib/libthr/thread/thr_rtld.c b/lib/libthr/thread/thr_rtld.c index 68a02e9aca1b..e5a7f86de288 100644 --- a/lib/libthr/thread/thr_rtld.c +++ b/lib/libthr/thread/thr_rtld.c @@ -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