From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 6E2993858D3C; Thu, 15 Jun 2023 10:43:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E2993858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-977cf86aae5so243209466b.0; Thu, 15 Jun 2023 03:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686825830; x=1689417830; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fc78gHm3Hrczn0G9YNnBYBH1nXf/erGwKODNeDk2E9k=; b=bO7MBixWXNiRYutEqB7jJh9VNtTkyT4DHgbUYQ+S2kslq2QTDXfNk9jVHrzodxyyk8 VN1N388qJ3nf40vbgUfhXSiO72ZmYKypC+Gt3r5H7LnYd1AUZ/AIkAVJeT7hPy/ab/57 AAtC8r2vs9FUZPCDngPTgFGs+tiNtxIw4muGpSVgxP+31NcBEr0mvCc4hlZsZNRY95v5 X/gRViI62tVVSIiiCqlH1x0DPwJtDQn+x+RJKf9E2M3tejsp/H2jhBJXwl8HzyJA6j5e LgnujNCMFhOWduSOPSe02GUBbcLonbkAA5cFmoMkEYgsSRAjB0Uvv62/25X1C5NjaN52 EwNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686825830; x=1689417830; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fc78gHm3Hrczn0G9YNnBYBH1nXf/erGwKODNeDk2E9k=; b=SNW8+yIVCNTB7gi92mBUW30gcRf8Z8pqVjP+3Ebb1sllrjgA53eOisQTF/YQlK5KU1 kSd25KiTniTBOxI04uPUB6Cb7BuWLNJiHo4gdcUFRpdqxJu1nXqpB2ekShrXyZvL6X0D ynPG2jBVOXBGo1cDX5b0h/3PfYIhbHoj4/kYMi7eR8A2oXS49cpN/740S8k8iGWDvaiz TNW1gBgCJxu22+3/bvAqwMW+YbTfPVBeEAz0PHFTOHAgkOeADoXwlyPm7LzMsCcLzNJH jIZ9xhQfPXQ0smwPbZXB8W/OUftVg/kYRUEN7IhInvmsqVWt8zMHrWBGalLL6B80oLUi h4OQ== X-Gm-Message-State: AC+VfDww7PVuDx5rkxWvZg6XHOZgoB5AgcCWDItKomeEHe3VWlWcklTG DNhVpHxz+LfuMuP2lZqJITs1CGXSXZPQ7GQ3Ro8PQ2dGgS6RZg== X-Google-Smtp-Source: ACHHUZ5YTdCMNjKWakdOY2MU5UPsmzucxba62BS5w+NX1K2qZi53nKUjpDlrg3/ioS/fZ7NEiLIH0eK4/3Or2/eH/4k= X-Received: by 2002:a17:907:2cc2:b0:96f:8439:6143 with SMTP id hg2-20020a1709072cc200b0096f84396143mr18060090ejc.40.1686825829857; Thu, 15 Jun 2023 03:43:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 15 Jun 2023 13:43:37 +0300 Message-ID: Subject: Re: libstdc++-v3: do not duplicate some math functions when using newlib To: Alexandre Oliva Cc: gcc-patches , "libstdc++" , Joel Brobecker Content-Type: multipart/alternative; boundary="00000000000062ff3705fe28bed7" X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --00000000000062ff3705fe28bed7 Content-Type: text/plain; charset="UTF-8" On Thu, 15 Jun 2023, 01:46 Alexandre Oliva via Libstdc++, < libstdc++@gcc.gnu.org> wrote: > > 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. > Excellent, I've been looking at this area of our configury and the math stubs recently and this is a nice improvement. OK for trunk, thanks. > 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) > > > -- > Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ > Free Software Activist GNU Toolchain Engineer > Disinformation flourishes because many people care deeply about injustice > but very few check the facts. Ask me about > --00000000000062ff3705fe28bed7--