From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oYuXO8ZphmlwyiwAWB0awg (envelope-from ) for ; Fri, 06 Feb 2026 17:23:03 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=SQ1geP65; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DAD841E08D; Fri, 06 Feb 2026 17:23:02 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 59A5D1E08D for ; Fri, 06 Feb 2026 17:23:01 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id B2A724BAD14B for ; Fri, 6 Feb 2026 22:23:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2A724BAD14B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=SQ1geP65 Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 63C304BA23E8 for ; Fri, 6 Feb 2026 22:22:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63C304BA23E8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 63C304BA23E8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770416555; cv=none; b=fxSpMVgiGbEkD3OALsMJgxYLZhO8LJI03kxuqYexzfd6j2JrdTemjXN//BcPmFa4cVrtwa5QrQcVDgwlv9szC5fuzz6QSDdvuxr54aHNtXuZsASTYSOgDj73kgpfLp7I7jxlpoHeFkKw/smcoFJ2kAlF7Ucd19tdhEDN+P53v68= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770416555; c=relaxed/simple; bh=qPcGOyIdjLFSaXpF/HNteNOluKJZ7B9YyGkEhXgkn1o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aOMo0eeB/PQLEIZTvCaJt23A/tTFkYKMiquAHsD3DChOjFb9cb2p8yaLGqg5qKHg8ZB/lw4zI0H4jW67PoJwafWcYcmxwV2qfoAgaLt1uDAMzUpqFFduCspM1W1/SFPSKEuVBlvb5vR/iilrwL02+hQ9BkJNdeYVv6GAv4gQ3+E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63C304BA23E8 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 616MMSGn146991 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 6 Feb 2026 17:22:33 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 616MMSGn146991 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1770416553; bh=bVpbjY2Ae6l0qkuolr8PhNfL4LLq5X8jqm6gNMkjeUc=; h=From:To:Cc:Subject:Date:From; b=SQ1geP656+W8oUst8o8QPg3fJrEXvKo4+IJamHSCniomIlB+wBNAAmvg85IcLZ1uo Fkd/FFzkQrab7cWb6DUuSKTXaNO9BFZPtej8uJdCpGR7XhCMTJBXRcaWar1lTCG9gj v1iIirxdgWYYdqfrGvLDb8mYAN9gXXqpDRYn3FQdWlt0LpqZ8g/jq6eP9AIc5JFMgz JxaYq/P8rBCuVVuE0xwxkFV02dPxvCICdt+ql1gZJfBnjKnMffZCOyXZLmmsdhv8zH WMDv0Stx14YWHxdzDaiYwlk12Zyqy5CVlBCoev4FuPfnC0L6ovCwd01hojZWGLPCGe usPDZ/O1qfivQ== Received: by simark.ca (Postfix) id 743011E08D; Fri, 06 Feb 2026 17:22:28 -0500 (EST) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: link with libatomic when it exists Date: Fri, 6 Feb 2026 17:22:14 -0500 Message-ID: <20260206222227.2847503-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 6 Feb 2026 22:22:28 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi Since commit 329a53a6d5 (Some cleanups to "pretend language" handling), building with clang fails with: $ ~/src/binutils-gdb/configure CC=clang CFLAGS=-O0 CXX=clang++ CXXFLAGS=-O0 LDFLAGS=-fuse-ld=mold CXXLD gdb mold: error: undefined symbol: __atomic_compare_exchange >>> referenced by read.c >>> dwarf2/read.o:(std::atomic >::compare_exchange_strong(packed&, packed, std::memory_order, std::memory_order)) ... It's not necessary to link with mold nor to build with -O0 to reproduce the error, but it makes the error message more informative regarding which use of std::atomic requires the __atomic_compare_exchange symbol. For some reason, the compare_exchange_strong calls on `std::atomic>` added in 329a53a6d5 make clang generate a call into libatomic, whereas gcc implements it using only the generated assembly. I'm no compiler expert, but this seems like a choice that each compiler is free to make. The solution is to use the -latomic flag when linking in clang builds. We (the ROCgdb team) considered writing a targeted configure check to determine if -latomic was needed for this specific edge case, for the toolchain in use. But we ended up thinking it would be simpler to just always link with libatomic, when it is present. We think there is no real downside to it. If libatomic is not really needed, since most toolchains now default to using --as-needed, libatomic won't be DT_NEEDED if it's not truly needed. Plus, if things change (either our code or the compilers) in the future and more things end up requiring libatomic, we'll be covered. Bug 33879 is about the error shown above. Bug 29455 appears to be the same, but about symbol __atomic_load. Change-Id: I6778ae8f35acc99ffb8955479bb57766eecf4556 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33879 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29455 --- gdb/config.in | 3 +++ gdb/configure | 44 ++++++++++++++++++++++++++++++++++++++++++++ gdb/configure.ac | 6 ++++++ 3 files changed, 53 insertions(+) diff --git a/gdb/config.in b/gdb/config.in index 3c3d33c9accc..b11fcf183726 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -262,6 +262,9 @@ /* Define if your file defines LC_MESSAGES. */ #undef HAVE_LC_MESSAGES +/* Define to 1 if you have the `atomic' library (-latomic). */ +#undef HAVE_LIBATOMIC + /* Define if you have the babeltrace library. */ #undef HAVE_LIBBABELTRACE diff --git a/gdb/configure b/gdb/configure index ddc25568ccd4..12c54521682a 100755 --- a/gdb/configure +++ b/gdb/configure @@ -26672,6 +26672,50 @@ _ACEOF fi +# GDB uses std::atomic, which sometimes (depending on the arch, compiler, types, +# etc) generates some calls into libatomic. Always link with libatomic when +# it exists, there shouldn't be any downsides in linking with it even if not +# needed. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -latomic" >&5 +$as_echo_n "checking for main in -latomic... " >&6; } +if ${ac_cv_lib_atomic_main+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-latomic $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +int +main () +{ +return main (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_atomic_main=yes +else + ac_cv_lib_atomic_main=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_atomic_main" >&5 +$as_echo "$ac_cv_lib_atomic_main" >&6; } +if test "x$ac_cv_lib_atomic_main" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBATOMIC 1 +_ACEOF + + LIBS="-latomic $LIBS" + +fi + + # Some systems (e.g. Solaris) have `gethostbyname' in libnsl. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing gethostbyname" >&5 $as_echo_n "checking for library containing gethostbyname... " >&6; } diff --git a/gdb/configure.ac b/gdb/configure.ac index bd1a091aabf2..cf8078e1d89b 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -556,6 +556,12 @@ esac # We might need to link with -lm; most simulators need it. AC_CHECK_LIB(m, main) +# GDB uses std::atomic, which sometimes (depending on the arch, compiler, types, +# etc) generates some calls into libatomic. Always link with libatomic when +# it exists, there shouldn't be any downsides in linking with it even if not +# needed. +AC_CHECK_LIB(atomic, main) + # Some systems (e.g. Solaris) have `gethostbyname' in libnsl. AC_SEARCH_LIBS(gethostbyname, nsl) base-commit: 7aed4728e4d266f8e3c82f4689d90e53e9231f91 -- 2.53.0