libc: Define __atomic_is_lock_free.

Limited to architectures where it is actually needed by gcc for any
calls to stdatomic.h atomic_is_lock_free for now.

We should also add it to other architectures too, along with lockful
atomic r/m/w operations for sizes that can't be handled natively, but
that's a lot more work.  It is also necessary for -fno-inline-atomics
but we're missing a lot of other symbols for that too, to be fixed.
For now, this should enable the OpenSSL build to complete on these
architectures again after I reverted a local change.

XXX pullup-10
This commit is contained in:
riastradh 2023-03-30 15:03:35 +00:00
parent f9fd253c05
commit 4dbf8e0c85
7 changed files with 75 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.14 2019/02/28 02:35:37 isaki Exp $
# $NetBSD: Makefile.inc,v 1.15 2023/03/30 15:03:35 riastradh Exp $
.if defined(LIB)
@ -36,6 +36,7 @@ SRCS+= atomic_xor_32_cas.c atomic_xor_16_cas.c atomic_xor_8_cas.c \
atomic_cas_32_cas.c atomic_cas_16_cas.c atomic_cas_8_cas.c \
atomic_c11_compare_exchange_cas_32.c \
atomic_c11_compare_exchange_cas_16.c \
atomic_c11_compare_exchange_cas_8.c
atomic_c11_compare_exchange_cas_8.c \
atomic_is_lock_free.c
.endif
.endif

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.15 2019/02/28 02:35:37 isaki Exp $
# $NetBSD: Makefile.inc,v 1.16 2023/03/30 15:03:35 riastradh Exp $
#
# Note: The atomic operations here in these assembly files are atomic
@ -57,3 +57,7 @@ CPPFLAGS+= -D__HAVE_ASM_ATOMIC_CAS_UP -D__HAVE_ASM_ATOMIC_CAS_16_UP \
.endif
.endif
.if defined(LIB) && ${LIB} == "c"
SRCS+= atomic_is_lock_free.c
.endif

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.15 2021/04/25 22:45:16 christos Exp $
# $NetBSD: Makefile.inc,v 1.16 2023/03/30 15:03:36 riastradh Exp $
.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
|| ${LIB} == "rump")
@ -51,6 +51,9 @@ SRCS+= atomic_xor_32_cas.c atomic_xor_16_cas.c atomic_xor_8_cas.c \
atomic_c11_compare_exchange_cas_32.c \
atomic_c11_compare_exchange_cas_16.c \
atomic_c11_compare_exchange_cas_8.c
.if !${MACHINE_MIPS64}
SRCS+= atomic_is_lock_free.c
.endif
.endif
.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "rump")

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.8 2019/02/28 02:35:37 isaki Exp $
# $NetBSD: Makefile.inc,v 1.9 2023/03/30 15:03:36 riastradh Exp $
.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
|| ${LIB} == "rump")
@ -20,7 +20,8 @@ SRCS+= atomic_add_16_cas.c atomic_add_8_cas.c \
atomic_cas_32_cas.c atomic_cas_16_cas.c atomic_cas_8_cas.c \
atomic_c11_compare_exchange_cas_32.c \
atomic_c11_compare_exchange_cas_16.c \
atomic_c11_compare_exchange_cas_8.c
atomic_c11_compare_exchange_cas_8.c \
atomic_is_lock_free.c
.endif
.endif

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.23 2019/02/28 02:35:37 isaki Exp $
# $NetBSD: Makefile.inc,v 1.24 2023/03/30 15:03:36 riastradh Exp $
.include <bsd.own.mk>
@ -46,7 +46,8 @@ SRCS+= atomic_nand_16_cas.c atomic_nand_8_cas.c \
atomic_c11_compare_exchange_cas_32.c \
atomic_c11_compare_exchange_cas_16.c \
atomic_c11_compare_exchange_cas_8.c \
atomic_load.c atomic_store.c
atomic_load.c atomic_store.c \
atomic_is_lock_free.c
. endif
. if (${LIB} == "kern" || ${LIB} == "rump")

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.8 2019/02/28 02:35:38 isaki Exp $
# $NetBSD: Makefile.inc,v 1.9 2023/03/30 15:03:36 riastradh Exp $
.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
|| ${LIB} == "rump")
@ -20,7 +20,8 @@ SRCS+= atomic_add_16_cas.c atomic_add_8_cas.c \
atomic_swap_16_cas.c atomic_swap_8_cas.c \
atomic_c11_compare_exchange_cas_32.c \
atomic_c11_compare_exchange_cas_16.c \
atomic_c11_compare_exchange_cas_8.c
atomic_c11_compare_exchange_cas_8.c \
atomic_is_lock_free.c
.endif
.endif

View File

@ -0,0 +1,54 @@
/* $NetBSD: atomic_is_lock_free.c,v 1.1 2023/03/30 15:03:36 riastradh Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
* 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, 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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 <sys/cdefs.h>
__RCSID("$NetBSD: atomic_is_lock_free.c,v 1.1 2023/03/30 15:03:36 riastradh Exp $");
#include <sys/types.h>
#include <sys/stdbool.h>
bool
__atomic_is_lock_free(size_t n, const volatile void *p __unused)
{
switch (n) {
case 1:
return __atomic_always_lock_free(1, 0);
case 2:
return __atomic_always_lock_free(2, 0);
case 4:
return __atomic_always_lock_free(4, 0);
case 8:
return __atomic_always_lock_free(8, 0);
case 16:
return __atomic_always_lock_free(16, 0);
default:
return false;
}
}