mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
Require C11 Atomic Operations via <stdatomic.h>
Make the C11 Atomic Operations mandatory and drop the Gcc __atomic builtin shims.
This commit is contained in:
105
configure.ac
105
configure.ac
@@ -309,12 +309,48 @@ AC_CHECK_HEADERS([fcntl.h regex.h sys/time.h unistd.h sys/mman.h sys/sockio.h sy
|
||||
])
|
||||
|
||||
#
|
||||
# Check for thread local storage
|
||||
# Check for C11 thread local storage
|
||||
#
|
||||
# NOTE: OpenBSD doesn't ship <threads.h>, so we can't require it (yet).
|
||||
#
|
||||
AC_CHECK_HEADERS([threads.h])
|
||||
|
||||
#
|
||||
# C11 Atomic Operations
|
||||
#
|
||||
|
||||
AC_CHECK_HEADERS([stdatomic.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([C11 Atomic Operations required, update your toolchain to build BIND 9])])
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <stdatomic.h>]],
|
||||
[[atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
|
||||
)],
|
||||
[AC_MSG_CHECKING([whether -latomic is needed for 64-bit stdatomic.h functions])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <stdatomic.h>]],
|
||||
[[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
|
||||
)],
|
||||
[AC_MSG_RESULT([no])],
|
||||
[LIBS="$LIBS -latomic"
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <stdatomic.h>]],
|
||||
[[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
|
||||
)],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
|
||||
])
|
||||
],
|
||||
[AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])])
|
||||
|
||||
AC_CHECK_HEADERS([stdalign.h stdnoreturn.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([C11 standard headers not found, update your toolchain.])])
|
||||
|
||||
AC_C_CONST
|
||||
AC_C_INLINE
|
||||
AC_C_VOLATILE
|
||||
@@ -1099,73 +1135,6 @@ AC_COMPILE_IFELSE(
|
||||
#
|
||||
AC_CHECK_FUNCS([if_nametoindex])
|
||||
|
||||
ISC_ATOMIC_LIBS=""
|
||||
AC_CHECK_HEADERS(
|
||||
[stdatomic.h],
|
||||
[AC_MSG_CHECKING([for memory model aware atomic operations])
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <stdatomic.h>]],
|
||||
[[atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
|
||||
)],
|
||||
[AC_MSG_RESULT([stdatomic.h])
|
||||
AC_MSG_CHECKING([whether -latomic is needed for 64-bit stdatomic.h functions])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <stdatomic.h>]],
|
||||
[[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
|
||||
)],
|
||||
[AC_MSG_RESULT([no])],
|
||||
[ISC_ATOMIC_LIBS="-latomic"
|
||||
AX_SAVE_FLAGS([atomic])
|
||||
LIBS="$LIBS $ISC_ATOMIC_LIBS"
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <stdatomic.h>]],
|
||||
[[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
|
||||
)],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
|
||||
AX_RESTORE_FLAGS([atomic])
|
||||
])
|
||||
],
|
||||
[AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])]
|
||||
)],
|
||||
[AC_MSG_CHECKING([for memory model aware atomic operations])
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <inttypes.h>]],
|
||||
[[int32_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
|
||||
)],
|
||||
[AC_MSG_RESULT([__atomic builtins])
|
||||
AC_DEFINE([HAVE___ATOMIC], [1], [define if __atomic builtins are not available])
|
||||
AC_MSG_CHECKING([whether -latomic is needed for 64-bit __atomic builtins])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <inttypes.h>]],
|
||||
[[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
|
||||
)],
|
||||
[AC_MSG_RESULT([no])],
|
||||
[ISC_ATOMIC_LIBS="-latomic"
|
||||
AX_SAVE_FLAGS([atomic])
|
||||
LIBS="$LIBS $ISC_ATOMIC_LIBS"
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <inttypes.h>]],
|
||||
[[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
|
||||
)],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
|
||||
AX_RESTORE_FLAGS([atomic])
|
||||
])
|
||||
],
|
||||
[AC_MSG_FAILURE([not found])
|
||||
])
|
||||
])
|
||||
LIBS="$LIBS $ISC_ATOMIC_LIBS"
|
||||
|
||||
AC_CHECK_HEADERS([stdalign.h stdnoreturn.h])
|
||||
|
||||
AC_CHECK_HEADERS([uchar.h])
|
||||
|
||||
#
|
||||
|
@@ -86,7 +86,6 @@ libisc_la_HEADERS = \
|
||||
include/isc/sockaddr.h \
|
||||
include/isc/stat.h \
|
||||
include/isc/stats.h \
|
||||
include/isc/stdatomic.h \
|
||||
include/isc/stdio.h \
|
||||
include/isc/stdtime.h \
|
||||
include/isc/strerr.h \
|
||||
|
@@ -13,11 +13,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
|
||||
#include <stdatomic.h>
|
||||
#else
|
||||
#include <isc/stdatomic.h>
|
||||
#endif
|
||||
|
||||
#include <isc/util.h>
|
||||
|
||||
|
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#if HAVE_UCHAR_H
|
||||
#include <uchar.h>
|
||||
#endif /* HAVE_UCHAR_H */
|
||||
|
||||
/* GCC 4.7.0 introduced __atomic builtins, but not the __GNUC_ATOMICS define */
|
||||
#if !defined(__GNUC_ATOMICS) && __GNUC__ == 4 && __GNUC_MINOR__ >= 7
|
||||
#define __GNUC_ATOMICS
|
||||
#endif
|
||||
|
||||
#if !defined(__GNUC_ATOMICS)
|
||||
#error "isc/stdatomic.h does not support your compiler"
|
||||
#endif /* if !defined(__GNUC_ATOMICS) */
|
||||
|
||||
typedef enum memory_order {
|
||||
memory_order_relaxed = __ATOMIC_RELAXED,
|
||||
memory_order_consume = __ATOMIC_CONSUME,
|
||||
memory_order_acquire = __ATOMIC_ACQUIRE,
|
||||
memory_order_release = __ATOMIC_RELEASE,
|
||||
memory_order_acq_rel = __ATOMIC_ACQ_REL,
|
||||
memory_order_seq_cst = __ATOMIC_SEQ_CST
|
||||
} memory_order;
|
||||
|
||||
#ifndef HAVE_UCHAR_H
|
||||
typedef uint_least16_t char16_t;
|
||||
typedef uint_least32_t char32_t;
|
||||
#endif /* HAVE_UCHAR_H */
|
||||
|
||||
typedef bool atomic_bool;
|
||||
typedef char atomic_char;
|
||||
typedef signed char atomic_schar;
|
||||
typedef unsigned char atomic_uchar;
|
||||
typedef short atomic_short;
|
||||
typedef unsigned short atomic_ushort;
|
||||
typedef int atomic_int;
|
||||
typedef unsigned int atomic_uint;
|
||||
typedef long atomic_long;
|
||||
typedef unsigned long atomic_ulong;
|
||||
typedef long long atomic_llong;
|
||||
typedef unsigned long long atomic_ullong;
|
||||
typedef char16_t atomic_char16_t;
|
||||
typedef char32_t atomic_char32_t;
|
||||
typedef wchar_t atomic_wchar_t;
|
||||
typedef int_least8_t atomic_int_least8_t;
|
||||
typedef uint_least8_t atomic_uint_least8_t;
|
||||
typedef int_least16_t atomic_int_least16_t;
|
||||
typedef uint_least16_t atomic_uint_least16_t;
|
||||
typedef int_least32_t atomic_int_least32_t;
|
||||
typedef uint_least32_t atomic_uint_least32_t;
|
||||
typedef int_least64_t atomic_int_least64_t;
|
||||
typedef uint_least64_t atomic_uint_least64_t;
|
||||
typedef int_fast8_t atomic_int_fast8_t;
|
||||
typedef uint_fast8_t atomic_uint_fast8_t;
|
||||
typedef int_fast16_t atomic_int_fast16_t;
|
||||
typedef uint_fast16_t atomic_uint_fast16_t;
|
||||
typedef int_fast32_t atomic_int_fast32_t;
|
||||
typedef uint_fast32_t atomic_uint_fast32_t;
|
||||
typedef int_fast64_t atomic_int_fast64_t;
|
||||
typedef uint_fast64_t atomic_uint_fast64_t;
|
||||
typedef intptr_t atomic_intptr_t;
|
||||
typedef uintptr_t atomic_uintptr_t;
|
||||
typedef size_t atomic_size_t;
|
||||
typedef ptrdiff_t atomic_ptrdiff_t;
|
||||
typedef intmax_t atomic_intmax_t;
|
||||
typedef uintmax_t atomic_uintmax_t;
|
||||
|
||||
#define atomic_init(obj, desired) (*obj = desired)
|
||||
#define atomic_load_explicit(obj, order) __atomic_load_n(obj, order)
|
||||
#define atomic_store_explicit(obj, desired, order) \
|
||||
__atomic_store_n(obj, desired, order)
|
||||
#define atomic_fetch_add_explicit(obj, arg, order) \
|
||||
__atomic_fetch_add(obj, arg, order)
|
||||
#define atomic_fetch_sub_explicit(obj, arg, order) \
|
||||
__atomic_fetch_sub(obj, arg, order)
|
||||
#define atomic_fetch_and_explicit(obj, arg, order) \
|
||||
__atomic_fetch_and(obj, arg, order)
|
||||
#define atomic_fetch_or_explicit(obj, arg, order) \
|
||||
__atomic_fetch_or(obj, arg, order)
|
||||
#define atomic_compare_exchange_strong_explicit(obj, expected, desired, succ, \
|
||||
fail) \
|
||||
__atomic_compare_exchange_n(obj, expected, desired, 0, succ, fail)
|
||||
#define atomic_compare_exchange_weak_explicit(obj, expected, desired, succ, \
|
||||
fail) \
|
||||
__atomic_compare_exchange_n(obj, expected, desired, 1, succ, fail)
|
||||
#define atomic_exchange_explicit(obj, desired, order) \
|
||||
__atomic_exchange_n(obj, desired, order)
|
||||
|
||||
#define atomic_load(obj) atomic_load_explicit(obj, memory_order_seq_cst)
|
||||
#define atomic_store(obj, arg) \
|
||||
atomic_store_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_add(obj, arg) \
|
||||
atomic_fetch_add_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_sub(obj, arg) \
|
||||
atomic_fetch_sub_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_and(obj, arg) \
|
||||
atomic_fetch_and_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_or(obj, arg) \
|
||||
atomic_fetch_or_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_compare_exchange_strong(obj, expected, desired) \
|
||||
atomic_compare_exchange_strong_explicit(obj, expected, desired, \
|
||||
memory_order_seq_cst, \
|
||||
memory_order_seq_cst)
|
||||
#define atomic_compare_exchange_weak(obj, expected, desired) \
|
||||
atomic_compare_exchange_weak_explicit(obj, expected, desired, \
|
||||
memory_order_seq_cst, \
|
||||
memory_order_seq_cst)
|
||||
#define atomic_exchange(obj, desired) \
|
||||
atomic_exchange_explicit(obj, desired, memory_order_seq_cst)
|
Reference in New Issue
Block a user