From patchwork Mon Dec 19 16:02:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 62153 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9E393852A4F for ; Mon, 19 Dec 2022 16:03:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 1B3F43857C48 for ; Mon, 19 Dec 2022 16:02:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1B3F43857C48 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1p7IbJ-0009pS-Tq for gcc-patches@gcc.gnu.org; Mon, 19 Dec 2022 17:02:50 +0100 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p7IbJ-000OB4-QU for gcc-patches@gcc.gnu.org; Mon, 19 Dec 2022 17:02:49 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 7CE7248007D for ; Mon, 19 Dec 2022 17:02:49 +0100 (CET) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Qq_STjLSKjKc for ; Mon, 19 Dec 2022 17:02:48 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 9F7B94801A3 for ; Mon, 19 Dec 2022 17:02:48 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id JgqBidoVlsSs for ; Mon, 19 Dec 2022 17:02:48 +0100 (CET) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 7D93448007D for ; Mon, 19 Dec 2022 17:02:48 +0100 (CET) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [PATCH] libatomic: Provide gthr.h default implementation Date: Mon, 19 Dec 2022 17:02:45 +0100 Message-Id: <20221219160245.55745-1-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.7/26755/Mon Dec 19 09:25:09 2022) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Build libatomic for all targets. Use gthr.h to provide a default implementation. If the thread model is "single", then this implementation will not work if for example atomic operations are used for thread/interrupt synchronization. libatomic/ChangeLog: * Makefile.am (BUILT_SOURCES): New. (gthr.h): Link from libgcc source file if USE_CONFIG_GTHR is enabled. (gthr-default.h): Likewise. * Makefile.in: Regenerate. * configure: Likewise. * configure.ac: Map thread model to thread header. (thread_header): New substitution. (USE_CONFIG_GTHR): New automake conditional. * configure.tgt (*-*-elf*): Delete. (UNSUPPORTED): Likewise. (USE_CONFIG_GTHR): Define as default. * testsuite/Makefile.in: Regenerate. * config/gthr/host-config.h: New file. * config/gthr/lock.c: Likewise. --- libatomic/Makefile.am | 12 +++ libatomic/Makefile.in | 40 +++++--- libatomic/config/gthr/host-config.h | 55 +++++++++++ libatomic/config/gthr/lock.c | 136 ++++++++++++++++++++++++++++ libatomic/configure | 40 +++++++- libatomic/configure.ac | 10 +- libatomic/configure.tgt | 16 +--- libatomic/testsuite/Makefile.in | 4 +- 8 files changed, 281 insertions(+), 32 deletions(-) create mode 100644 libatomic/config/gthr/host-config.h create mode 100644 libatomic/config/gthr/lock.c diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am index 41e5da28512..d56d553c9d5 100644 --- a/libatomic/Makefile.am +++ b/libatomic/Makefile.am @@ -34,6 +34,18 @@ search_path = $(addprefix $(top_srcdir)/config/, $(config_path)) \ vpath % $(strip $(search_path)) +BUILT_SOURCES = + +if USE_CONFIG_GTHR +gthr.h: $(top_srcdir)/../libgcc/gthr.h + -$(LN_S) $< $@ + +gthr-default.h: $(top_srcdir)/../libgcc/$(thread_header) + -$(LN_S) $< $@ + +BUILT_SOURCES += gthr.h gthr-default.h +endif + DEFAULT_INCLUDES = $(addprefix -I, $(search_path)) AM_CFLAGS = $(XCFLAGS) AM_CCASFLAGS = $(XCFLAGS) diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in index a0fa3dfc8cc..2e3ddd014f8 100644 --- a/libatomic/Makefile.in +++ b/libatomic/Makefile.in @@ -89,15 +89,16 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ -@ARCH_AARCH64_LINUX_TRUE@@HAVE_IFUNC_TRUE@am__append_1 = $(foreach s,$(SIZES),$(addsuffix _$(s)_1_.lo,$(SIZEOBJS))) -@ARCH_AARCH64_LINUX_TRUE@@HAVE_IFUNC_TRUE@am__append_2 = atomic_16.S -@ARCH_ARM_LINUX_TRUE@@HAVE_IFUNC_TRUE@am__append_3 = $(foreach \ +@USE_CONFIG_GTHR_TRUE@am__append_1 = gthr.h gthr-default.h +@ARCH_AARCH64_LINUX_TRUE@@HAVE_IFUNC_TRUE@am__append_2 = $(foreach s,$(SIZES),$(addsuffix _$(s)_1_.lo,$(SIZEOBJS))) +@ARCH_AARCH64_LINUX_TRUE@@HAVE_IFUNC_TRUE@am__append_3 = atomic_16.S +@ARCH_ARM_LINUX_TRUE@@HAVE_IFUNC_TRUE@am__append_4 = $(foreach \ @ARCH_ARM_LINUX_TRUE@@HAVE_IFUNC_TRUE@ s,$(SIZES),$(addsuffix \ @ARCH_ARM_LINUX_TRUE@@HAVE_IFUNC_TRUE@ _$(s)_1_.lo,$(SIZEOBJS))) \ @ARCH_ARM_LINUX_TRUE@@HAVE_IFUNC_TRUE@ $(addsuffix \ @ARCH_ARM_LINUX_TRUE@@HAVE_IFUNC_TRUE@ _8_2_.lo,$(SIZEOBJS)) -@ARCH_I386_TRUE@@HAVE_IFUNC_TRUE@am__append_4 = $(addsuffix _8_1_.lo,$(SIZEOBJS)) -@ARCH_X86_64_TRUE@@HAVE_IFUNC_TRUE@am__append_5 = $(addsuffix _16_1_.lo,$(SIZEOBJS)) \ +@ARCH_I386_TRUE@@HAVE_IFUNC_TRUE@am__append_5 = $(addsuffix _8_1_.lo,$(SIZEOBJS)) +@ARCH_X86_64_TRUE@@HAVE_IFUNC_TRUE@am__append_6 = $(addsuffix _16_1_.lo,$(SIZEOBJS)) \ @ARCH_X86_64_TRUE@@HAVE_IFUNC_TRUE@ $(addsuffix _16_2_.lo,$(SIZEOBJS)) subdir = . @@ -115,7 +116,8 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ $(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \ $(top_srcdir)/../config/enable.m4 \ - $(top_srcdir)/../config/cet.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/../config/cet.m4 $(top_srcdir)/../config/gthr.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ @@ -392,6 +394,7 @@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ +thread_header = @thread_header@ tmake_file = @tmake_file@ toolexecdir = @toolexecdir@ toolexeclibdir = @toolexeclibdir@ @@ -404,6 +407,7 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER) search_path = $(addprefix $(top_srcdir)/config/, $(config_path)) \ $(top_srcdir) $(top_builddir) +BUILT_SOURCES = $(am__append_1) DEFAULT_INCLUDES = $(addprefix -I, $(search_path)) AM_CFLAGS = $(XCFLAGS) AM_CCASFLAGS = $(XCFLAGS) @@ -419,7 +423,7 @@ noinst_LTLIBRARIES = libatomic_convenience.la libatomic_version_info = -version-info $(libtool_VERSION) libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) $(lt_host_flags) libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c \ - init.c fenv.c fence.c flag.c $(am__append_2) + init.c fenv.c fence.c flag.c $(am__append_3) SIZEOBJS = load store cas exch fadd fsub fand fior fxor fnand tas EXTRA_libatomic_la_SOURCES = $(addsuffix _n.c,$(SIZEOBJS)) libatomic_la_DEPENDENCIES = $(libatomic_la_LIBADD) $(libatomic_version_dep) @@ -445,8 +449,8 @@ all_c_files := $(foreach dir,$(search_path),$(wildcard $(dir)/*.c)) # Then sort through them to find the one we want, and select the first. M_SRC = $(firstword $(filter %/$(M_FILE), $(all_c_files))) libatomic_la_LIBADD = $(foreach s,$(SIZES),$(addsuffix \ - _$(s)_.lo,$(SIZEOBJS))) $(am__append_1) $(am__append_3) \ - $(am__append_4) $(am__append_5) + _$(s)_.lo,$(SIZEOBJS))) $(am__append_2) $(am__append_4) \ + $(am__append_5) $(am__append_6) @ARCH_AARCH64_LINUX_TRUE@@HAVE_IFUNC_TRUE@IFUNC_OPTIONS = -march=armv8-a+lse @ARCH_ARM_LINUX_TRUE@@HAVE_IFUNC_TRUE@IFUNC_OPTIONS = -march=armv7-a+fp -DHAVE_KERNEL64 @ARCH_I386_TRUE@@HAVE_IFUNC_TRUE@IFUNC_OPTIONS = -march=i586 @@ -459,7 +463,7 @@ MULTIDIRS = MULTISUBDIR = MULTIDO = true MULTICLEAN = true -all: auto-config.h +all: $(BUILT_SOURCES) auto-config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive .SUFFIXES: @@ -741,14 +745,16 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -rm -f cscope.out cscope.in.out cscope.po.out cscope.files check-am: all-am -check: check-recursive +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-recursive all-am: Makefile $(LTLIBRARIES) auto-config.h all-local installdirs: installdirs-recursive installdirs-am: for dir in "$(DESTDIR)$(toolexeclibdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-recursive +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-recursive install-exec: install-exec-recursive install-data: install-data-recursive uninstall: uninstall-recursive @@ -778,6 +784,7 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-recursive clean-am: clean-generic clean-libtool clean-local \ @@ -854,7 +861,8 @@ ps-am: uninstall-am: uninstall-toolexeclibLTLIBRARIES -.MAKE: $(am__recursive_targets) all install-am install-strip +.MAKE: $(am__recursive_targets) all check install install-am \ + install-strip .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am all-local \ am--refresh check check-am clean clean-cscope clean-generic \ @@ -878,6 +886,12 @@ uninstall-am: uninstall-toolexeclibLTLIBRARIES vpath % $(strip $(search_path)) + +@USE_CONFIG_GTHR_TRUE@gthr.h: $(top_srcdir)/../libgcc/gthr.h +@USE_CONFIG_GTHR_TRUE@ -$(LN_S) $< $@ + +@USE_CONFIG_GTHR_TRUE@gthr-default.h: $(top_srcdir)/../libgcc/$(thread_header) +@USE_CONFIG_GTHR_TRUE@ -$(LN_S) $< $@ @LIBAT_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic.map-sun : $(top_srcdir)/libatomic.map \ @LIBAT_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@ $(top_srcdir)/../contrib/make_sunver.pl \ @LIBAT_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@ $(libatomic_la_OBJECTS) $(libatomic_la_LIBADD) diff --git a/libatomic/config/gthr/host-config.h b/libatomic/config/gthr/host-config.h new file mode 100644 index 00000000000..5e529945eee --- /dev/null +++ b/libatomic/config/gthr/host-config.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2012-2022 Free Software Foundation, Inc. + Contributed by Richard Henderson . + + This file is part of the GNU Atomic Library (libatomic). + + Libatomic is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +/* Included after all more target-specific host-config.h. */ + + +#ifndef protect_start_end +# ifdef HAVE_ATTRIBUTE_VISIBILITY +# pragma GCC visibility push(hidden) +# endif + +void libat_lock_1 (void *ptr); +void libat_unlock_1 (void *ptr); + +static inline UWORD +protect_start (void *ptr) +{ + libat_lock_1 (ptr); + return 0; +} + +static inline void +protect_end (void *ptr, UWORD dummy UNUSED) +{ + libat_unlock_1 (ptr); +} + +# define protect_start_end 1 +# ifdef HAVE_ATTRIBUTE_VISIBILITY +# pragma GCC visibility pop +# endif +#endif /* protect_start_end */ + +#include_next diff --git a/libatomic/config/gthr/lock.c b/libatomic/config/gthr/lock.c new file mode 100644 index 00000000000..2d495ed3b56 --- /dev/null +++ b/libatomic/config/gthr/lock.c @@ -0,0 +1,136 @@ +/* Copyright (C) 2012-2022 Free Software Foundation, Inc. + Contributed by Richard Henderson . + + This file is part of the GNU Atomic Library (libatomic). + + Libatomic is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +#include "libatomic_i.h" +#include "gthr.h" + + +/* The target page size. Must be no larger than the runtime page size, + lest locking fail with virtual address aliasing (i.e. a page mmaped + at two locations). */ +#ifndef PAGE_SIZE +#define PAGE_SIZE 4096 +#endif + +/* The target cacheline size. This is an optimization; the padding that + should be applied to the locks to keep them from interfering. */ +#ifndef CACHLINE_SIZE +#define CACHLINE_SIZE 64 +#endif + +/* The granularity at which locks are applied. Almost certainly the + cachline size is the right thing to use here. */ +#ifndef WATCH_SIZE +#define WATCH_SIZE CACHLINE_SIZE +#endif + +struct lock +{ + __gthread_mutex_t mutex; + char pad[sizeof(__gthread_mutex_t) < CACHLINE_SIZE + ? CACHLINE_SIZE - sizeof(__gthread_mutex_t) + : 0]; +}; + +#define NLOCKS (PAGE_SIZE / WATCH_SIZE) +#ifdef __GTHREAD_MUTEX_INIT +static struct lock locks[NLOCKS] = { + [0 ... NLOCKS-1].mutex = __GTHREAD_MUTEX_INIT +}; +#else +static __gthread_once_t locks_once = __GTHREAD_ONCE_INIT; + +static struct lock locks[NLOCKS]; + +static void +locks_init (void) +{ + size_t i; + for (i = 0; i < NLOCKS; ++i) + __GTHREAD_MUTEX_INIT_FUNCTION (&locks[i].mutex); +} +#endif + +static inline uintptr_t +addr_hash (void *ptr) +{ + return ((uintptr_t)ptr / WATCH_SIZE) % NLOCKS; +} + +void +libat_lock_1 (void *ptr) +{ +#ifndef __GTHREAD_MUTEX_INIT + __gthread_once (&locks_once, locks_init); +#endif + __gthread_mutex_lock (&locks[addr_hash (ptr)].mutex); +} + +void +libat_unlock_1 (void *ptr) +{ + __gthread_mutex_unlock (&locks[addr_hash (ptr)].mutex); +} + +void +libat_lock_n (void *ptr, size_t n) +{ + uintptr_t h = addr_hash (ptr); + size_t i = 0; + + /* Don't lock more than all the locks we have. */ + if (n > PAGE_SIZE) + n = PAGE_SIZE; + + do + { +#ifndef __GTHREAD_MUTEX_INIT + __gthread_once (&locks_once, locks_init); +#endif + __gthread_mutex_lock (&locks[h].mutex); + if (++h == NLOCKS) + h = 0; + i += WATCH_SIZE; + } + while (i < n); +} + +void +libat_unlock_n (void *ptr, size_t n) +{ + uintptr_t h = addr_hash (ptr); + size_t i = 0; + + if (n > PAGE_SIZE) + n = PAGE_SIZE; + + do + { + __gthread_mutex_unlock (&locks[h].mutex); + if (++h == NLOCKS) + h = 0; + i += WATCH_SIZE; + } + while (i < n); +} diff --git a/libatomic/configure b/libatomic/configure index e47d2d7fb35..cec874ebabe 100755 --- a/libatomic/configure +++ b/libatomic/configure @@ -656,7 +656,10 @@ LIBAT_BUILD_VERSIONED_SHLIB_FALSE LIBAT_BUILD_VERSIONED_SHLIB_TRUE OPT_LDFLAGS SECTION_LDFLAGS +USE_CONFIG_GTHR_FALSE +USE_CONFIG_GTHR_TRUE enable_aarch64_lse +thread_header libtool_VERSION MAINT MAINTAINER_MODE_FALSE @@ -11406,7 +11409,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11409 "configure" +#line 11412 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11512,7 +11515,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11515 "configure" +#line 11518 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11808,6 +11811,26 @@ target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'` { $as_echo "$as_me:${as_lineno-$LINENO}: result: $target_thread_file" >&5 $as_echo "$target_thread_file" >&6; } +# Map from thread model to thread header. + +case $target_thread_file in + aix) thread_header=config/rs6000/gthr-aix.h ;; + dce) thread_header=config/pa/gthr-dce.h ;; + gcn) thread_header=config/gcn/gthr-gcn.h ;; + lynx) thread_header=config/gthr-lynx.h ;; + mipssde) thread_header=config/mips/gthr-mipssde.h ;; + posix) thread_header=gthr-posix.h ;; + rtems) thread_header=config/gthr-rtems.h ;; + single) thread_header=gthr-single.h ;; + tpf) thread_header=config/s390/gthr-tpf.h ;; + vxworks) thread_header=config/gthr-vxworks.h ;; + win32) thread_header=config/i386/gthr-win32.h ;; + mcf) thread_header=config/i386/gthr-mcf.h ;; +esac + + + + case "$target" in *aarch64*) ac_ext=c @@ -11872,10 +11895,15 @@ esac # Get target configury. . ${srcdir}/configure.tgt -if test -n "$UNSUPPORTED"; then - as_fn_error $? "Configuration ${target} is unsupported." "$LINENO" 5 + if test -n "$USE_CONFIG_GTHR"; then + USE_CONFIG_GTHR_TRUE= + USE_CONFIG_GTHR_FALSE='#' +else + USE_CONFIG_GTHR_TRUE='#' + USE_CONFIG_GTHR_FALSE= fi + # Write out the ifunc resolver arg type. cat >>confdefs.h <<_ACEOF @@ -15924,6 +15952,10 @@ if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${USE_CONFIG_GTHR_TRUE}" && test -z "${USE_CONFIG_GTHR_FALSE}"; then + as_fn_error $? "conditional \"USE_CONFIG_GTHR\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${LIBAT_BUILD_VERSIONED_SHLIB_TRUE}" && test -z "${LIBAT_BUILD_VERSIONED_SHLIB_FALSE}"; then as_fn_error $? "conditional \"LIBAT_BUILD_VERSIONED_SHLIB\" was never defined. diff --git a/libatomic/configure.ac b/libatomic/configure.ac index 5563551aaae..78a0b533c79 100644 --- a/libatomic/configure.ac +++ b/libatomic/configure.ac @@ -22,6 +22,8 @@ # see the files COPYING3 and COPYING.RUNTIME respectively. If not, see # . +sinclude(../config/gthr.m4) + AC_INIT([GNU Atomic Library], 1.0,,[libatomic]) AC_CONFIG_HEADER(auto-config.h) @@ -165,6 +167,10 @@ AC_MSG_CHECKING([for thread model used by GCC]) target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'` AC_MSG_RESULT([$target_thread_file]) +# Map from thread model to thread header. +GCC_AC_THREAD_HEADER([$target_thread_file]) +AC_SUBST(thread_header) + case "$target" in *aarch64*) ACX_PROG_CC_WARNING_OPTS([-march=armv8-a+lse],[enable_aarch64_lse]) @@ -173,9 +179,7 @@ esac # Get target configury. . ${srcdir}/configure.tgt -if test -n "$UNSUPPORTED"; then - AC_MSG_ERROR([Configuration ${target} is unsupported.]) -fi +AM_CONDITIONAL(USE_CONFIG_GTHR, test -n "$USE_CONFIG_GTHR") # Write out the ifunc resolver arg type. AC_DEFINE_UNQUOTED(IFUNC_RESOLVER_ARGS, $IFUNC_RESOLVER_ARGS, diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt index 57f093603bb..a4463c5a7cb 100644 --- a/libatomic/configure.tgt +++ b/libatomic/configure.tgt @@ -174,21 +174,15 @@ case "${target}" in config_path="rtems" ;; - *-*-elf*) - # ??? No target OS. We could be targeting bare-metal kernel-mode, - # or user-mode for some custom OS. If the target supports TAS, - # we can build our own spinlocks, given there are no signals. - # If the target supports disabling interrupts, we can work in - # kernel-mode, given the system is not multi-processor. - UNSUPPORTED=1 - ;; - nvptx*-*-*) ;; *) - # Who are you? - UNSUPPORTED=1 + # Use gthr.h by default. If the thread model is "single", then this + # implementation will not work if for example atomic operations are + # used for thread/interrupt synchronization. + config_path="${config_path} gthr" + USE_CONFIG_GTHR=1 ;; esac diff --git a/libatomic/testsuite/Makefile.in b/libatomic/testsuite/Makefile.in index 8bc70562e5b..80652d1ffb1 100644 --- a/libatomic/testsuite/Makefile.in +++ b/libatomic/testsuite/Makefile.in @@ -103,7 +103,8 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ $(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \ $(top_srcdir)/../config/enable.m4 \ - $(top_srcdir)/../config/cet.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/../config/cet.m4 $(top_srcdir)/../config/gthr.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am @@ -262,6 +263,7 @@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ +thread_header = @thread_header@ tmake_file = @tmake_file@ toolexecdir = @toolexecdir@ toolexeclibdir = @toolexeclibdir@