From ef9871c6205c158b16ee23702d2b8c043debc51a Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Wed, 17 Jan 2024 20:26:52 +0000 Subject: [PATCH] libthr: move _umtx_op_err() to libsys Declare in sys/umtx.h and implement in libsys. Explicitly link libthr with libsys. When building libthr static include _umtx_op_err so we don't break static linkage with -lpthread. Reviewed by: kib, emaste, imp Pull Request: https://github.com/freebsd/freebsd-src/pull/908 --- lib/libsys/Makefile | 7 ++++ lib/libsys/Symbol.thr.map | 3 ++ lib/libsys/_umtx_op_err.c | 39 +++++++++++++++++++ lib/libsys/amd64/Makefile.thr | 1 + .../amd64 => libsys}/amd64/_umtx_op_err.S | 0 lib/libsys/i386/Makefile.thr | 1 + .../arch/i386 => libsys}/i386/_umtx_op_err.S | 0 lib/libsys/powerpc/Makefile.thr | 1 + .../powerpc => libsys}/powerpc/_umtx_op_err.S | 0 lib/libthr/Makefile | 11 ++++++ lib/libthr/arch/amd64/Makefile.inc | 3 -- lib/libthr/arch/amd64/include/pthread_md.h | 2 - lib/libthr/arch/i386/Makefile.inc | 3 -- lib/libthr/arch/i386/include/pthread_md.h | 2 - lib/libthr/arch/powerpc/Makefile.inc | 2 - lib/libthr/arch/powerpc/include/pthread_md.h | 2 - lib/libthr/thread/thr_umtx.c | 10 ----- lib/libthr/thread/thr_umtx.h | 1 - rescue/rescue/Makefile | 4 +- sys/sys/umtx.h | 1 + 20 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 lib/libsys/Symbol.thr.map create mode 100644 lib/libsys/_umtx_op_err.c create mode 100644 lib/libsys/amd64/Makefile.thr rename lib/{libthr/arch/amd64 => libsys}/amd64/_umtx_op_err.S (100%) create mode 100644 lib/libsys/i386/Makefile.thr rename lib/{libthr/arch/i386 => libsys}/i386/_umtx_op_err.S (100%) create mode 100644 lib/libsys/powerpc/Makefile.thr rename lib/{libthr/arch/powerpc => libsys}/powerpc/_umtx_op_err.S (100%) delete mode 100644 lib/libthr/arch/powerpc/Makefile.inc diff --git a/lib/libsys/Makefile b/lib/libsys/Makefile index 45d3fec14300..b51f44025748 100644 --- a/lib/libsys/Makefile +++ b/lib/libsys/Makefile @@ -59,6 +59,13 @@ NOASM= .include "${LIBSYS_SRCTOP}/Makefile.sys" +SYM_MAPS+= ${LIBSYS_SRCTOP}/Symbol.thr.map +.PATH: ${LIBSYS_SRCTOP}/${MACHINE_CPUARCH} +.sinclude "${LIBSYS_SRCTOP}/${MACHINE_CPUARCH}/Makefile.thr" +.if !${SRCS:M_umtx_op_err.S} +SRCS+=_umtx_op_err.c +.endif + VERSION_DEF=${LIBC_SRCTOP}/Versions.def SYMBOL_MAPS=${SYM_MAPS} diff --git a/lib/libsys/Symbol.thr.map b/lib/libsys/Symbol.thr.map new file mode 100644 index 000000000000..a245de2e547a --- /dev/null +++ b/lib/libsys/Symbol.thr.map @@ -0,0 +1,3 @@ +FBSDprivate_1.0 { + _umtx_op_err; +}; diff --git a/lib/libsys/_umtx_op_err.c b/lib/libsys/_umtx_op_err.c new file mode 100644 index 000000000000..8281b8af7110 --- /dev/null +++ b/lib/libsys/_umtx_op_err.c @@ -0,0 +1,39 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2005 David Xu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +int +_umtx_op_err(void *obj, int op, u_long val, void *uaddr, void *uaddr2) +{ + if (_umtx_op(obj, op, val, uaddr, uaddr2) == -1) + return (errno); + return (0); +} diff --git a/lib/libsys/amd64/Makefile.thr b/lib/libsys/amd64/Makefile.thr new file mode 100644 index 000000000000..52e861709faf --- /dev/null +++ b/lib/libsys/amd64/Makefile.thr @@ -0,0 +1 @@ +SRCS+= _umtx_op_err.S diff --git a/lib/libthr/arch/amd64/amd64/_umtx_op_err.S b/lib/libsys/amd64/_umtx_op_err.S similarity index 100% rename from lib/libthr/arch/amd64/amd64/_umtx_op_err.S rename to lib/libsys/amd64/_umtx_op_err.S diff --git a/lib/libsys/i386/Makefile.thr b/lib/libsys/i386/Makefile.thr new file mode 100644 index 000000000000..52e861709faf --- /dev/null +++ b/lib/libsys/i386/Makefile.thr @@ -0,0 +1 @@ +SRCS+= _umtx_op_err.S diff --git a/lib/libthr/arch/i386/i386/_umtx_op_err.S b/lib/libsys/i386/_umtx_op_err.S similarity index 100% rename from lib/libthr/arch/i386/i386/_umtx_op_err.S rename to lib/libsys/i386/_umtx_op_err.S diff --git a/lib/libsys/powerpc/Makefile.thr b/lib/libsys/powerpc/Makefile.thr new file mode 100644 index 000000000000..52e861709faf --- /dev/null +++ b/lib/libsys/powerpc/Makefile.thr @@ -0,0 +1 @@ +SRCS+= _umtx_op_err.S diff --git a/lib/libthr/arch/powerpc/powerpc/_umtx_op_err.S b/lib/libsys/powerpc/_umtx_op_err.S similarity index 100% rename from lib/libthr/arch/powerpc/powerpc/_umtx_op_err.S rename to lib/libsys/powerpc/_umtx_op_err.S diff --git a/lib/libthr/Makefile b/lib/libthr/Makefile index dde2a9dce94e..1d34f5cb5f09 100644 --- a/lib/libthr/Makefile +++ b/lib/libthr/Makefile @@ -12,6 +12,9 @@ MK_SSP= no LIB=thr SHLIB_MAJOR= 3 + +LIBADD= sys + NO_WTHREAD_SAFETY=1 NO_WCAST_ALIGN.gcc=1 # for gcc 4.2 CFLAGS+=-DPTHREAD_KERNEL @@ -67,6 +70,14 @@ PRECIOUSLIB= .include "${.CURDIR}/thread/Makefile.inc" SRCS+= rtld_malloc.c +LIBSYS_SRCTOP= ${.CURDIR:H}/libsys +.if exists(${LIBSYS_SRCTOP}/${MACHINE_CPUARCH}/_umtx_op_err.S) +.PATH: ${LIBSYS_SRCTOP}/${MACHINE_CPUARCH} +.else +.PATH: ${LIBSYS_SRCTOP} +.endif +STATICOBJS+= _umtx_op_err.o + .if ${MK_INSTALLLIB} != "no" SYMLINKS+=lib${LIB}.a ${LIBDIR}/libpthread.a .endif diff --git a/lib/libthr/arch/amd64/Makefile.inc b/lib/libthr/arch/amd64/Makefile.inc index 24e5dd7c9b03..f8013ea914ed 100644 --- a/lib/libthr/arch/amd64/Makefile.inc +++ b/lib/libthr/arch/amd64/Makefile.inc @@ -1,6 +1,3 @@ - -SRCS+= _umtx_op_err.S - # With the current compiler and libthr code, using SSE in libthr # does not provide enough performance improvement to outweigh # the extra context switch cost. This can measurably impact diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h index fa0802e64ebb..f43578a8241a 100644 --- a/lib/libthr/arch/amd64/include/pthread_md.h +++ b/lib/libthr/arch/amd64/include/pthread_md.h @@ -52,6 +52,4 @@ _get_curthread(void) return (thr); } -#define HAS__UMTX_OP_ERR 1 - #endif diff --git a/lib/libthr/arch/i386/Makefile.inc b/lib/libthr/arch/i386/Makefile.inc index 24e5dd7c9b03..f8013ea914ed 100644 --- a/lib/libthr/arch/i386/Makefile.inc +++ b/lib/libthr/arch/i386/Makefile.inc @@ -1,6 +1,3 @@ - -SRCS+= _umtx_op_err.S - # With the current compiler and libthr code, using SSE in libthr # does not provide enough performance improvement to outweigh # the extra context switch cost. This can measurably impact diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h index 2a396abe3824..021ce8126909 100644 --- a/lib/libthr/arch/i386/include/pthread_md.h +++ b/lib/libthr/arch/i386/include/pthread_md.h @@ -52,6 +52,4 @@ _get_curthread(void) return (thr); } -#define HAS__UMTX_OP_ERR 1 - #endif diff --git a/lib/libthr/arch/powerpc/Makefile.inc b/lib/libthr/arch/powerpc/Makefile.inc deleted file mode 100644 index 663706b1b364..000000000000 --- a/lib/libthr/arch/powerpc/Makefile.inc +++ /dev/null @@ -1,2 +0,0 @@ - -SRCS+= _umtx_op_err.S diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h index 14f1703b5460..89fae48328cb 100644 --- a/lib/libthr/arch/powerpc/include/pthread_md.h +++ b/lib/libthr/arch/powerpc/include/pthread_md.h @@ -49,6 +49,4 @@ _get_curthread(void) return (NULL); } -#define HAS__UMTX_OP_ERR 1 - #endif /* _PTHREAD_MD_H_ */ diff --git a/lib/libthr/thread/thr_umtx.c b/lib/libthr/thread/thr_umtx.c index 37b378e74405..c6a032c773db 100644 --- a/lib/libthr/thread/thr_umtx.c +++ b/lib/libthr/thread/thr_umtx.c @@ -30,16 +30,6 @@ #include "thr_private.h" #include "thr_umtx.h" -#ifndef HAS__UMTX_OP_ERR -int _umtx_op_err(void *obj, int op, u_long val, void *uaddr, void *uaddr2) -{ - - if (_umtx_op(obj, op, val, uaddr, uaddr2) == -1) - return (errno); - return (0); -} -#endif - void _thr_umutex_init(struct umutex *mtx) { diff --git a/lib/libthr/thread/thr_umtx.h b/lib/libthr/thread/thr_umtx.h index a56997871ed1..89f70e4ab14f 100644 --- a/lib/libthr/thread/thr_umtx.h +++ b/lib/libthr/thread/thr_umtx.h @@ -39,7 +39,6 @@ #endif #define DEFAULT_URWLOCK {0,0,0,0,{0,0,0,0}} -int _umtx_op_err(void *, int op, u_long, void *, void *) __hidden; int __thr_umutex_lock(struct umutex *mtx, uint32_t id) __hidden; int __thr_umutex_lock_spin(struct umutex *mtx, uint32_t id) __hidden; int __thr_umutex_timedlock(struct umutex *mtx, uint32_t id, diff --git a/rescue/rescue/Makefile b/rescue/rescue/Makefile index 7bf3299f4d48..76810a903856 100644 --- a/rescue/rescue/Makefile +++ b/rescue/rescue/Makefile @@ -142,7 +142,7 @@ CRUNCH_PROGS_usr.sbin+= zdb CRUNCH_LIBS+= -l80211 -lalias -lcam -lncursesw -ldevstat -lipsec -llzma .if ${MK_ZFS} != "no" -CRUNCH_LIBS+= -lavl -lpthread -luutil -lumem -ltpool -lspl -lrt +CRUNCH_LIBS+= -lavl -lpthread -lsys -luutil -lumem -ltpool -lspl -lrt CRUNCH_LIBS_zfs+= ${LIBBE} \ ${LIBZPOOL} \ ${LIBZFS} \ @@ -156,7 +156,7 @@ CRUNCH_LIBS_zpool+= ${CRUNCH_LIBS_zfs} CRUNCH_LIBS_zdb+= ${CRUNCH_LIBS_zfs} .else # liblzma needs pthread -CRUNCH_LIBS+= -lpthread +CRUNCH_LIBS+= -lpthread -lsys .endif CRUNCH_LIBS+= -lgeom -lbsdxml -lkiconv .if ${MK_OPENSSL} == "no" diff --git a/sys/sys/umtx.h b/sys/sys/umtx.h index 0bc2e3efe594..f7a69ae772c3 100644 --- a/sys/sys/umtx.h +++ b/sys/sys/umtx.h @@ -135,6 +135,7 @@ struct umtx_robust_lists_params { __BEGIN_DECLS int _umtx_op(void *obj, int op, u_long val, void *uaddr, void *uaddr2); +int _umtx_op_err(void *obj, int op, u_long val, void *uaddr, void *uaddr2); __END_DECLS