From patchwork Fri Dec 30 10:20:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 62488 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 306163858C53 for ; Fri, 30 Dec 2022 10:21:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 306163858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672395681; bh=8ur5rPU1W61Kb3VJydTlFOGfkr3OZ5GL1cKS3xuglug=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=H8RjzT3C0CkC8A30qSR45YjtixYc8Mnur018XohatHS7cZbXz7ZItNzGTp6xJxME4 vHxWBjIMOjydzcw15OZn2IaFThv8GJPdegF/qhuTm7V+qogxNKEnbw0y2oUGJILjaP TGR5MSqeV4d4FrZElf8+Vk12ZA9poHsCKRRe9zJ8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id C0BC43858D1E for ; Fri, 30 Dec 2022 10:20:49 +0000 (GMT) Received: by mail-wr1-x435.google.com with SMTP id z10so19498154wrh.10 for ; Fri, 30 Dec 2022 02:20:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8ur5rPU1W61Kb3VJydTlFOGfkr3OZ5GL1cKS3xuglug=; b=B5WrHyi2ojvDEHhSBbSkFDtP5GnrlaFoRXkIxh79JqIQefOjVpAMeO/4M9rxghXbTN SHMSOh6fs+/q56x8OglFhjSfELdM4oVoHmeItFT+CaZvEAdjyLSsTAsJbIlsvaKrkXMw Ol1vssICmZrLJtOGG90gKC+vO37FHP+7X2O/ei9fNW0NQd167H/SH1vOzo5NivnV4yfW 40uInvsU+w4qISra+CZvG7pJIk5HJYJK1DZQGntUZw1HMKL41LGafIkkixLotFl/X1qn L+jYjhcHVd9MLRO9rhqrNTKg19wFuLjTtaPuprIR63/Twxokn0HVtukwZcZ+WeGJdjBh malg== X-Gm-Message-State: AFqh2krFLZuy2ckP3nbfZI72S5EhcSkcCBCUhsTkCauvfpCVLwHGdMgv ThwDZvqWjHAqHVftoS7BCrnZiL+S0ME= X-Google-Smtp-Source: AMrXdXvyxtKUPAjobYLUYr6gszjNWguWSddJ8pckkQBIH0oirXK6lzfA38lIejHp8xuZThudk4uoxA== X-Received: by 2002:adf:ce86:0:b0:242:1cc2:b1eb with SMTP id r6-20020adfce86000000b002421cc2b1ebmr19406688wrn.5.1672395648145; Fri, 30 Dec 2022 02:20:48 -0800 (PST) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id l7-20020adfc787000000b002238ea5750csm24654415wrg.72.2022.12.30.02.20.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 30 Dec 2022 02:20:47 -0800 (PST) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] Darwin, crts: Provide scalb and significand as a crt [PR107631] Date: Fri, 30 Dec 2022 10:20:46 +0000 Message-Id: <20221230102046.8287-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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: , X-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe , joseph@codesourcery.com, ro@CeBiTec.Uni-Bielefeld.DE Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch is providing functions used by the modula-2 implementation. At present, I've used a crt rather than adding symbols to libgcc, since it is not clear if the modula-2 might alter the use of scalb to scalbn (although that will not solve the missing significand* symbols). I plan to apply the patch early next week (it is Darwin-specific) unless there are any comments on the implementation. tested on powerpc/i688-darwin9 .. x86_64-darwin10,17,21, the prototype aarch64-darwin branch on darwin21 and x86_64-linux-gnu. thanks Iain --- 8< --- The Darwin libc does not provide the obsolete scalb() functions, nor does it supply the glibc significand() functions. These are used via builtins that resolve to libcalls by modula-2 which leads to many link fails on all Darwin versions. We provide them here as a crt implemented as a convenience lib which means that they will only be linked when required. Signed-off-by: Iain Sandoe gcc/ChangeLog: * config/darwin.h (LINK_COMMAND_SPEC_A): Add link for float extra crt. libgcc/ChangeLog: * config.host (*-*_darwin*): Add libfltext.a. * config/t-darwin: Build libfltext.a. * config/darwin-scalb.c: New file. * config/darwin-significand.c: New file. Signed-off-by: Iain Sandoe --- gcc/config/darwin.h | 1 + libgcc/config.host | 2 +- libgcc/config/darwin-scalb.c | 58 ++++++++++++++++++++++++++++++ libgcc/config/darwin-significand.c | 39 ++++++++++++++++++++ libgcc/config/t-darwin | 10 ++++++ 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 libgcc/config/darwin-scalb.c create mode 100644 libgcc/config/darwin-significand.c diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index d1b4f277c2e..87b45b3d9d1 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -370,6 +370,7 @@ extern GTY(()) int darwin_ms_struct; %{%:sanitize(undefined): -lubsan } \ %(link_ssp) \ %:version-compare(>< 10.6 10.7 mmacosx-version-min= -ld10-uwfef) \ + -lfltext \ %(link_gcc_c_sequence) \ %{!nodefaultexport:%{dylib|dynamiclib|bundle: \ %:version-compare(>= 10.11 asm_macosx_version_min= -U) \ diff --git a/libgcc/config.host b/libgcc/config.host index d2087654c40..5ccce2726bc 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -233,7 +233,7 @@ case ${host} in ;; esac tmake_file="$tmake_file t-slibgcc-darwin" - extra_parts="crt3.o libd10-uwfef.a crttms.o crttme.o libemutls_w.a" + extra_parts="crt3.o libd10-uwfef.a crttms.o crttme.o libemutls_w.a libfltext.a" ;; *-*-dragonfly*) tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip" diff --git a/libgcc/config/darwin-scalb.c b/libgcc/config/darwin-scalb.c new file mode 100644 index 00000000000..d5d653c56bf --- /dev/null +++ b/libgcc/config/darwin-scalb.c @@ -0,0 +1,58 @@ +/* Implementation of the scalb functions for Darwin. + +Copyright The GNU Toolchain Authors. +Contributed by Iain Sandoe. + +This file is part of GCC. + +GCC 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, or (at your option) +any later version. + +GCC 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. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +/* These functions [scalb* (f, n)] are not provided by the system + As of IEEE Std 1003.1, 2004 Edition they are obsoleted. + As of IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008) they are + removed. + + Furthermore the informational in the 2004 edition documentation says: + + 1. Applications should use either scalbln(), scalblnf(), or scalblnl() in + preference to this function. + + 2. IEEE Std 1003.1-2001 only defines the behavior for the scalb() function + when the n argument is an integer, a NaN, or Inf. The + behavior of other values for the n argument is unspecified. + + IEEE Std 1003.1, 2004 does not provide any additional normative description + of the behaviour except 'When radix is 2, scalb() shall be equivalent to + ldexp()' which is also only specified for integer n; Darwin's float radix + is defined to be 2. + + These observations are used to justify a placeholder implementation of scalb + in terms of scalbln, since there is clear intent in the Posix documentation + to limit the functionality to integral values of n.*/ + +double scalb (double r, double n) +{ + return __builtin_scalbln (r, (long) n); +} + +float scalbf (float r, float n) +{ + return __builtin_scalblnf (r, (long) n); +} + +long double scalbl (long double r, long double n) +{ + return __builtin_scalblnl (r, (long) n); +} diff --git a/libgcc/config/darwin-significand.c b/libgcc/config/darwin-significand.c new file mode 100644 index 00000000000..19f59ef0b67 --- /dev/null +++ b/libgcc/config/darwin-significand.c @@ -0,0 +1,39 @@ +/* Implementation of the Glibc significand() functions for Darwin. + +Copyright The GNU Toolchain Authors. +Contributed by Iain Sandoe. + +This file is part of GCC. + +GCC 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, or (at your option) +any later version. + +GCC 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. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +/* These just implement the underlying definition. */ +double +significand (double r) +{ + return __builtin_scalbn (r, -__builtin_ilogb (r)); +} + +float +significandf (float r) +{ + return __builtin_scalbnf (r, -__builtin_ilogbf (r)); +} + +long double +significandl (long double r) +{ + return __builtin_scalbnl (r, -__builtin_ilogbl (r)); +} diff --git a/libgcc/config/t-darwin b/libgcc/config/t-darwin index 299d26c2c96..b9058ad7b27 100644 --- a/libgcc/config/t-darwin +++ b/libgcc/config/t-darwin @@ -11,6 +11,16 @@ crttms.o: $(srcdir)/config/darwin-crt-tm.c crttme.o: $(srcdir)/config/darwin-crt-tm.c $(crt_compile) -mmacosx-version-min=10.4 -DEND -c $< +darwin-scalb.o: $(srcdir)/config/darwin-scalb.c + $(crt_compile) -mmacosx-version-min=10.4 -DEND -c $< + +darwin-significand.o: $(srcdir)/config/darwin-significand.c + $(crt_compile) -mmacosx-version-min=10.4 -DEND -c $< + +libfltext.a: darwin-scalb.o darwin-significand.o + $(AR_CREATE_FOR_TARGET) $@ darwin-scalb.o darwin-significand.o + $(RANLIB_FOR_TARGET) $@ + # Make emutls weak so that we can deal with -static-libgcc, override the # hidden visibility when this is present in libgcc_eh. emutls.o: HOST_LIBGCC2_CFLAGS += \