From patchwork Wed Jun 14 22:45:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1795135 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=TKpfOh3h; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QhLCL40D0z20Wy for ; Thu, 15 Jun 2023 08:47:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 835243858C39 for ; Wed, 14 Jun 2023 22:47:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 835243858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686782828; bh=ArfCasITZOJZWsb9CdxBY/zabqltYXnfhe6hDetFnjg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=TKpfOh3hP85+XpDj1khKAlAp4CvUKN/xXEFDItZ37Yxf5nalLaUqTz9TxZEyxV2en R8RH9f3lEfmeMRpGKjwut483V3L28iJ+Lk+mmFLt9l5A3tf0aSm+6tsTb8IfguJ+v+ H+0GJK4ZXQ1IFePznL4OnrKy6SkC+OJJi+/fIp6Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by sourceware.org (Postfix) with ESMTPS id 0B5DA3858C1F for ; Wed, 14 Jun 2023 22:46:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B5DA3858C1F Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-1a49716e9c5so5143334fac.1 for ; Wed, 14 Jun 2023 15:46:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686782773; x=1689374773; h=mime-version:user-agent:message-id:date:errors-to:organization :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ArfCasITZOJZWsb9CdxBY/zabqltYXnfhe6hDetFnjg=; b=GOmmnEfmLqE0JbAv6yhFL5AxbOX0POG/Op6K1R4oSXpoIEPtoSqB/7qLMxhsWa4mBh LlnSyHoOmjXvSZdn2YeoWRhYzejvzVJXX0U/zI0P8nLMV72sRajlaa8iZ6ajB8sXkRsa 46ysnIPOz3vC1hTFAomUOLXsyofH4xiWY49glA+nIfIxJ72kdJc6JekstnhfzwTwpxUo q3fx14oHWi/MDuwk5wSiF81P+NUMM2eyNhCWzO252MjiHw6sTHqmvWEnKxPdqB/BYnHd eXdVrM15LD3+G2j2KZbEfK6oel/GQ03+/AA0nzd0iMSEokRRNvgNn2QVGLXLdq3bQu8p DunQ== X-Gm-Message-State: AC+VfDyzRAC3c33avZsbd/twXO99bo9ND22bPgKg2EfyGQyepZvUNTCY 4p33egVzb2rLGpWAPml6uJjlmmvQlnU4h/UW0Uc= X-Google-Smtp-Source: ACHHUZ7H7ZSB1V5xGqogiSlDkEyapRTfttGgt7XpXoEdN0AS1ehJMWaNsF+6c2w4V7OMvL/IFyl1TQ== X-Received: by 2002:a05:6870:3a1d:b0:1a6:99bf:f455 with SMTP id du29-20020a0568703a1d00b001a699bff455mr7247210oab.21.1686782772771; Wed, 14 Jun 2023 15:46:12 -0700 (PDT) Received: from free.home ([2804:7f1:2080:2b05:3128:ead8:cd43:416f]) by smtp.gmail.com with ESMTPSA id ld10-20020a0568702b0a00b001762ce27f9asm9306372oab.23.2023.06.14.15.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 15:46:12 -0700 (PDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 35EMjxOa410898 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 14 Jun 2023 19:46:00 -0300 To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Cc: Joel Brobecker Subject: libstdc++-v3: do not duplicate some math functions when using newlib Organization: Free thinker, does not speak for AdaCore Date: Wed, 14 Jun 2023 19:45:59 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: , X-Patchwork-Original-From: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Contributing a patch by Joel Brobecker . Regstrapped on x86_64-linux-gnu just to be sure, also tested with aarch64-rtems6. I'm going to put this in later this week if there aren't any objections. When running the libstdc++ testsuite on AArch64 RTEMS, we noticed that about 25 tests are failing during the link, due to the "sqrtl" function being defined twice: - once inside RTEMS' libm; - once inside our libstdc++. One test that fails, for instance, would be 26_numerics/complex/13450.cc. In comparing libm and libstdc++, we found that libstc++ also duplicates "hypotf", and "hypotl". For "sqrtl" and "hypotl", the symbosl come a unit called from math_stubs_long_double.cc, while "hypotf" comes from the equivalent unit for the float version, called math_stubs_float.cc. Those units are always compiled in libstdc++ and provide our own version of various math routines when those are missing from the target system. The definition of those symbols is predicated on the existance of various macros provided by c++config.h, which themselves are predicated by the corresponding HAVE_xxx macros in config.h. One key element behind what's happening, here, is that the target uses newlib, and therefore GCC was configured --with-newlib. The section of libstdc++v3's configure script that handles which math functions are available has a newlib-specific section, and that section provides a hardcoded list of symbols. For "hypotf", this commit fixes the issue by doing the same as for the other routines already declared in that section. I verified by inspection in the newlib code that this function should always be present, so hardcoding it in our configure script should not be an issue. For the math routines handling doubles ("sqrtl" and "hypotl"), however, I do not believe we can assume that newlib's libm will always provide them. Therefore, this commit fixes that part of the issue by ading a compile-check for "sqrtl" and "hypotl". And while at it, we also include checks for all the other math functions that math_stubs_long_double.cc re-implements, allowing us to be resilient to future newlib enhancements adding support for more functions. libstdc++-v3/ChangeLog: * configure.ac ["x${with_newlib}" = "xyes"]: Define HAVE_HYPOTF. Add compile-checks for various long double math functions as well. * configure: Regenerate. --- libstdc++-v3/configure | 1179 +++++++++++++++++++++++++++++++++++++++++++++ libstdc++-v3/configure.ac | 9 2 files changed, 1188 insertions(+) diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 354c566b0055c..bda8053ecc279 100755 [omitted] diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 0abe54e7b9a21..9770c1787679f 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -349,6 +349,7 @@ else AC_DEFINE(HAVE_FLOORF) AC_DEFINE(HAVE_FMODF) AC_DEFINE(HAVE_FREXPF) + AC_DEFINE(HAVE_HYPOTF) AC_DEFINE(HAVE_LDEXPF) AC_DEFINE(HAVE_LOG10F) AC_DEFINE(HAVE_LOGF) @@ -360,6 +361,14 @@ else AC_DEFINE(HAVE_TANF) AC_DEFINE(HAVE_TANHF) +dnl # Support for the long version of some math libraries depends on +dnl # architecture and newlib version. So test for their availability +dnl # rather than hardcoding that information. + GLIBCXX_CHECK_MATH_DECLS([ + acosl asinl atan2l atanl ceill coshl cosl expl fabsl floorl fmodl + frexpl hypotl ldexpl log10l logl modfl powl sinhl sinl sqrtl + tanhl tanl]) + AC_DEFINE(HAVE_ICONV) AC_DEFINE(HAVE_MEMALIGN)