From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 24F7B393A41F; Tue, 11 Jan 2022 22:51:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24F7B393A41F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6505] libgfortran: Make sure glibc < 2.32 built powerpc64le-linux libgfortran doesn't use __*ieee128 APIs X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 4d0e778fe3d064e3896b7f5f7de78a479f27dc55 X-Git-Newrev: e79f6e61d5849408c3137dbfa5d49e7066f9df7b Message-Id: <20220111225151.24F7B393A41F@sourceware.org> Date: Tue, 11 Jan 2022 22:51:51 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jan 2022 22:51:51 -0000 https://gcc.gnu.org/g:e79f6e61d5849408c3137dbfa5d49e7066f9df7b commit r12-6505-ge79f6e61d5849408c3137dbfa5d49e7066f9df7b Author: Jakub Jelinek Date: Fri Jan 7 23:24:41 2022 +0100 libgfortran: Make sure glibc < 2.32 built powerpc64le-linux libgfortran doesn't use __*ieee128 APIs I've just tried to build libgfortran on an old glibc system (gcc112.fsffrance.org) and unfortunately we still have work to do: [jakub@gcc2-power8 obj38]$ LD_PRELOAD=/home/jakub/gcc/obj38/powerpc64le-unknown-linux-gnu/libgfortran/.libs/libgfortran.so.5.0.0 /bin/true [jakub@gcc2-power8 obj38]$ LD_BIND_NOW=1 LD_PRELOAD=/home/jakub/gcc/obj38/powerpc64le-unknown-linux-gnu/libgfortran/.libs/libgfortran.so.5.0.0 /bin/true /bin/true: symbol lookup error: /home/jakub/gcc/obj38/powerpc64le-unknown-linux-gnu/libgfortran/.libs/libgfortran.so.5.0.0: undefined symbol: __atan2ieee128 While we do use some libquadmath APIs: readelf -Wr /home/jakub/gcc/obj38/powerpc64le-unknown-linux-gnu/libgfortran/.libs/libgfortran.so.5.0.0 | grep QUADMATH 0000000000251268 000005e400000026 R_PPC64_ADDR64 0000000000000000 quadmath_snprintf@QUADMATH_1.0 + 0 0000000000251270 0000030600000026 R_PPC64_ADDR64 0000000000000000 strtoflt128@QUADMATH_1.0 + 0 00000000002502e0 0000011600000015 R_PPC64_JMP_SLOT 0000000000000000 ynq@QUADMATH_1.0 + 0 0000000000250390 0000016000000015 R_PPC64_JMP_SLOT 0000000000000000 sqrtq@QUADMATH_1.0 + 0 0000000000250508 000001fa00000015 R_PPC64_JMP_SLOT 0000000000000000 fmaq@QUADMATH_1.0 + 0 0000000000250530 0000021200000015 R_PPC64_JMP_SLOT 0000000000000000 fabsq@QUADMATH_1.0 + 0 0000000000250760 0000030600000015 R_PPC64_JMP_SLOT 0000000000000000 strtoflt128@QUADMATH_1.0 + 0 0000000000250990 000003df00000015 R_PPC64_JMP_SLOT 0000000000000000 cosq@QUADMATH_1.0 + 0 00000000002509f0 0000040a00000015 R_PPC64_JMP_SLOT 0000000000000000 expq@QUADMATH_1.0 + 0 0000000000250a88 0000045100000015 R_PPC64_JMP_SLOT 0000000000000000 erfcq@QUADMATH_1.0 + 0 0000000000250a98 0000045e00000015 R_PPC64_JMP_SLOT 0000000000000000 jnq@QUADMATH_1.0 + 0 0000000000250ac8 0000047e00000015 R_PPC64_JMP_SLOT 0000000000000000 sinq@QUADMATH_1.0 + 0 0000000000250e38 000005db00000015 R_PPC64_JMP_SLOT 0000000000000000 fmodq@QUADMATH_1.0 + 0 0000000000250e48 000005e000000015 R_PPC64_JMP_SLOT 0000000000000000 tanq@QUADMATH_1.0 + 0 0000000000250e58 000005e400000015 R_PPC64_JMP_SLOT 0000000000000000 quadmath_snprintf@QUADMATH_1.0 + 0 0000000000250f20 0000062900000015 R_PPC64_JMP_SLOT 0000000000000000 copysignq@QUADMATH_1.0 + 0 we don't do it consistently: readelf -Wr /home/jakub/gcc/obj38/powerpc64le-unknown-linux-gnu/libgfortran/.libs/libgfortran.so.5.0.0 | grep ieee128 0000000000250310 0000012800000015 R_PPC64_JMP_SLOT 0000000000000000 __atan2ieee128 + 0 0000000000250340 0000014200000015 R_PPC64_JMP_SLOT 0000000000000000 __clogieee128 + 0 0000000000250438 000001a300000015 R_PPC64_JMP_SLOT 0000000000000000 __acoshieee128 + 0 00000000002504b8 000001cc00000015 R_PPC64_JMP_SLOT 0000000000000000 __csinieee128 + 0 0000000000250500 000001f300000015 R_PPC64_JMP_SLOT 0000000000000000 __sinhieee128 + 0 0000000000250570 0000022a00000015 R_PPC64_JMP_SLOT 0000000000000000 __asinieee128 + 0 0000000000250580 0000022d00000015 R_PPC64_JMP_SLOT 0000000000000000 __roundieee128 + 0 00000000002505a0 0000023e00000015 R_PPC64_JMP_SLOT 0000000000000000 __logieee128 + 0 00000000002505c8 0000024900000015 R_PPC64_JMP_SLOT 0000000000000000 __tanieee128 + 0 0000000000250630 0000027500000015 R_PPC64_JMP_SLOT 0000000000000000 __ccosieee128 + 0 0000000000250670 0000028a00000015 R_PPC64_JMP_SLOT 0000000000000000 __log10ieee128 + 0 00000000002506c8 000002bd00000015 R_PPC64_JMP_SLOT 0000000000000000 __cexpieee128 + 0 00000000002506d8 000002c800000015 R_PPC64_JMP_SLOT 0000000000000000 __coshieee128 + 0 00000000002509b0 000003ef00000015 R_PPC64_JMP_SLOT 0000000000000000 __truncieee128 + 0 0000000000250af8 000004a600000015 R_PPC64_JMP_SLOT 0000000000000000 __expieee128 + 0 0000000000250b50 000004c600000015 R_PPC64_JMP_SLOT 0000000000000000 __fmodieee128 + 0 0000000000250bb0 000004e700000015 R_PPC64_JMP_SLOT 0000000000000000 __tanhieee128 + 0 0000000000250c38 0000051300000015 R_PPC64_JMP_SLOT 0000000000000000 __acosieee128 + 0 0000000000250ce0 0000055400000015 R_PPC64_JMP_SLOT 0000000000000000 __sinieee128 + 0 0000000000250d60 0000057e00000015 R_PPC64_JMP_SLOT 0000000000000000 __atanieee128 + 0 0000000000250dd8 000005b100000015 R_PPC64_JMP_SLOT 0000000000000000 __sqrtieee128 + 0 0000000000250e98 0000060200000015 R_PPC64_JMP_SLOT 0000000000000000 __cosieee128 + 0 0000000000250eb0 0000060a00000015 R_PPC64_JMP_SLOT 0000000000000000 __atanhieee128 + 0 0000000000250ef0 0000062000000015 R_PPC64_JMP_SLOT 0000000000000000 __asinhieee128 + 0 0000000000250fd8 0000067f00000015 R_PPC64_JMP_SLOT 0000000000000000 __csqrtieee128 + 0 0000000000251038 000006ad00000015 R_PPC64_JMP_SLOT 0000000000000000 __cabsieee128 + 0 All these should for POWER_IEEE128 use atan2q@QUADMATH_1.0 etc. It seems all these come from f951 compiled sources. For user code, I think the agreement was if you want to use successfully -mabi=ieeelongdouble, you need glibc 2.32 or later, which is why the Fortran FE doesn't conditionalize on whether glibc 2.32 is available or not and just emits __WHATEVERieee128 entrypoints. But for Fortran compiled sources in libgfortran, we need to use __WHATEVERieee128 only if glibc 2.32 or later and WHATEVERq (from libquadmath) otherwise. The following patch implements that, adds -fbuilding-libgfortran option similar to e.g. -fbuilding-libgcc used when building libgcc and if that option is set and the TARGET_GLIBC_{MAJOR,MINOR} macros indicate no glibc or glibc older than 2.32, it will use the libquadmath APIs rather than glibc 2.32 APIs. 2022-01-07 Jakub Jelinek gcc/fortran/ * trans-types.c (gfc_init_kinds): When setting abi_kind to 17, if not targetting glibc 2.32 or later and -fbuilding-libgfortran, set gfc_real16_is_float128 and c_float128 in gfc_real_kinds. (gfc_build_real_type): Don't set c_long_double if c_float128 is already set. * trans-intrinsic.c (builtin_decl_for_precision): Don't use long_double_built_in if gfc_real16_is_float128 and long_double_type_node == gfc_float128_type_node. * lang.opt (fbuilding-libgfortran): New undocumented option. libgfortran/ * Makefile.am (AM_FCFLAGS): Add -fbuilding-libgfortran after -fallow-leading-underscore. * Makefile.in: Regenerated. Diff: --- gcc/fortran/lang.opt | 3 +++ gcc/fortran/trans-intrinsic.c | 4 +++- gcc/fortran/trans-types.c | 13 +++++++++++-- libgfortran/Makefile.am | 6 +++--- libgfortran/Makefile.in | 6 +++--- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 09d043e5e9a..ab92e0e3686 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -413,6 +413,9 @@ fblas-matmul-limit= Fortran RejectNegative Joined UInteger Var(flag_blas_matmul_limit) Init(30) -fblas-matmul-limit= Size of the smallest matrix for which matmul will use BLAS. +fbuilding-libgfortran +Fortran Undocumented Var(flag_building_libgfortran) + fcheck-array-temporaries Fortran Produce a warning at runtime if a array temporary has been created for a procedure argument. diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index db1d87ac36d..dc72d994781 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -154,7 +154,9 @@ builtin_decl_for_precision (enum built_in_function base_built_in, i = m->float_built_in; else if (precision == TYPE_PRECISION (double_type_node)) i = m->double_built_in; - else if (precision == TYPE_PRECISION (long_double_type_node)) + else if (precision == TYPE_PRECISION (long_double_type_node) + && (!gfc_real16_is_float128 + || long_double_type_node != gfc_float128_type_node)) i = m->long_double_built_in; else if (precision == TYPE_PRECISION (gfc_float128_type_node)) { diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index 147e825bac9..5de43bb2784 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -516,7 +516,16 @@ gfc_init_kinds (void) { for (int i = 0; i < r_index; ++i) if (gfc_real_kinds[i].kind == 16) - gfc_real_kinds[i].abi_kind = 17; + { + gfc_real_kinds[i].abi_kind = 17; + if (flag_building_libgfortran + && (TARGET_GLIBC_MAJOR < 2 + || (TARGET_GLIBC_MAJOR == 2 && TARGET_GLIBC_MINOR < 32))) + { + gfc_real16_is_float128 = true; + gfc_real_kinds[i].c_float128 = 1; + } + } } /* Choose the default integer kind. We choose 4 unless the user directs us @@ -859,7 +868,7 @@ gfc_build_real_type (gfc_real_info *info) info->c_float = 1; if (mode_precision == DOUBLE_TYPE_SIZE) info->c_double = 1; - if (mode_precision == LONG_DOUBLE_TYPE_SIZE) + if (mode_precision == LONG_DOUBLE_TYPE_SIZE && !info->c_float128) info->c_long_double = 1; if (mode_precision != LONG_DOUBLE_TYPE_SIZE && mode_precision == 128) { diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index 9fb12ba3d7f..00745403bbb 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -1081,8 +1081,8 @@ endif $(patsubst %.c,%.lo,$(notdir $(i_matmull_c))): AM_CFLAGS += -funroll-loops # Add the -fallow-leading-underscore option when needed -$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore -selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore +$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore -fbuilding-libgfortran +selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore -fbuilding-libgfortran # Build *_r17.F90 and *_c17.F90 with additional -mabi=ieeelongdouble on powerpc64le-linux. @@ -1099,7 +1099,7 @@ endif if IEEE_SUPPORT # Add flags for IEEE modules -$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fsignaling-nans +$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fsignaling-nans -fbuilding-libgfortran # Add flags for IEEE helper code $(patsubst %.c,%.lo,$(notdir $(gfor_ieee_helper_src))): AM_CFLAGS += -fsignaling-nans diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index da0ad684d21..fa5e21578c8 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -7634,8 +7634,8 @@ $(patsubst %.c,%.lo,$(notdir $(i_matmul_c))): AM_CFLAGS += -ffast-math -ftree-ve $(patsubst %.c,%.lo,$(notdir $(i_matmull_c))): AM_CFLAGS += -funroll-loops # Add the -fallow-leading-underscore option when needed -$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore -selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore +$(patsubst %.F90,%.lo,$(patsubst %.f90,%.lo,$(notdir $(gfor_specific_src)))): AM_FCFLAGS += -fallow-leading-underscore -fbuilding-libgfortran +selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-underscore -fbuilding-libgfortran # Build *_r17.F90 and *_c17.F90 with additional -mabi=ieeelongdouble on powerpc64le-linux. @@ -7649,7 +7649,7 @@ selected_real_kind.lo selected_int_kind.lo: AM_FCFLAGS += -fallow-leading-unders @HAVE_REAL_17_TRUE@$(patsubst %_c17.c,%_c17.lo,$(notdir $(gfor_built_src))): AM_CFLAGS += -mabi=ieeelongdouble # Add flags for IEEE modules -@IEEE_SUPPORT_TRUE@$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fsignaling-nans +@IEEE_SUPPORT_TRUE@$(patsubst %.F90,%.lo,$(notdir $(gfor_ieee_src))): AM_FCFLAGS += -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fsignaling-nans -fbuilding-libgfortran # Add flags for IEEE helper code @IEEE_SUPPORT_TRUE@$(patsubst %.c,%.lo,$(notdir $(gfor_ieee_helper_src))): AM_CFLAGS += -fsignaling-nans