From patchwork Thu Aug 6 13:04:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1341696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=XYPdywqk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BMpcT0B5Jz9sPB for ; Thu, 6 Aug 2020 23:04:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03E13384B009; Thu, 6 Aug 2020 13:04:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03E13384B009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596719093; bh=kFCWc5HD6sOq6i+ZxImzc+KZWS6EW9AqAWQXerNm77k=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=XYPdywqkwJGwSCM6IUOllzR4WO1ULnZWgMnR0MSR98TmtkaM/o87IHOurrQP/U/xM BpFfPse6NaaE1v0f2sy/80E7s7LneH5iKV3LsRfFuBCWzyj01/u/Flv87X6KSOBIuP H94Z6ajERc5f1Y9CnYSm3LUaH7t2EZ9MmtYK9ZfE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by sourceware.org (Postfix) with ESMTPS id 1B9A23857C6C for ; Thu, 6 Aug 2020 13:04:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1B9A23857C6C IronPort-SDR: f21IqO+rZ5lnHFw/t6fV8aDuOFu6RMFNsXqnenfEcjbAG2OTZZ4+omE370X5Ty0RkZobqnj0LQ 6+Dd0odO0X8pwxrwEDQl0j73pm928thkUZmOs1RbObnfjyrZNF9r9LiRAEuXrngdxk50amwzNO iWueGpnQbcTz+Bo5qLDzrWeTXylYjRNX+s2CGNH9NsW+HwZJ1Sp5ELY8VVF2fGFGO2AOQpHRAg Lt504cd5TU7//WXNFjVK6E/3yoKFB05vkp0fLx+Hh/FZ3pzD2Djc4UFRbGE0lQQo7Cd5+/G1hZ BoY= X-IronPort-AV: E=Sophos;i="5.75,441,1589212800"; d="scan'208";a="247403166" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 06 Aug 2020 21:04:42 +0800 IronPort-SDR: AxVb02ShxglqEqZZRkJv6nU28jO63/BAzC8Hhdp9TH95DkCMr/ATqQzFht0YQBAIakT9qFfTiV jWVh1JgQYlKg== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2020 05:51:57 -0700 IronPort-SDR: 8r+Mqhy7IOwEJUpZuvKClvzHdyBe7ENz50h8SNlMUlLe6Jh5NnAbpr+PtQjLJloVTdGfN8aoOO souLthcGXdBA== WDCIronportException: Internal Received: from unknown (HELO redsun52) ([10.149.66.28]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2020 06:04:37 -0700 Date: Thu, 6 Aug 2020 14:04:32 +0100 (BST) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] libgcc: Use `-fasynchronous-unwind-tables' for LIB2_DIVMOD_FUNCS Message-ID: User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "Maciej W. Rozycki via Gcc-patches" From: "Maciej W. Rozycki" Reply-To: "Maciej W. Rozycki" Cc: Andrew Waterman , Kito Cheng , Andreas Schwab , Richard Earnshaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Complement commit b932f770f70d ("x86_64 frame unwind info"), SVN r46374, , and replace `-fexceptions -fnon-call-exceptions' with `-fasynchronous-unwind-tables' in LIB2_DIVMOD_FUNCS compilation flags so as to provide unwind tables for the affected functions while not pulling the unwinder proper, which is not required here. Remove the ARM overrides accordingly, retaining the hook infrastructure however, and make the ARM test case a generic one. Beyond saving program space it fixes a RISC-V glibc build error due to unsatisfied `malloc' and `free' references from the unwinder causing link errors with `ld.so' where libgcc has been built at -O0. gcc/ * testsuite/gcc.target/arm/div64-unwinding.c: Rename to... * testsuite/gcc.dg/div64-unwinding.c: ... this. libgcc/ * Makefile.in [!LIB2_DIVMOD_EXCEPTION_FLAGS] (LIB2_DIVMOD_EXCEPTION_FLAGS): Replace `-fexceptions -fnon-call-exceptions' with `-fasynchronous-unwind-tables'. * config/arm/t-bpabi (LIB2_DIVMOD_EXCEPTION_FLAGS): Remove variable. * config/arm/t-netbsd-eabi (LIB2_DIVMOD_EXCEPTION_FLAGS): Likewise. --- Hi, I realised we still use handwritten ChangeLog entries (I got confused with now different policies each of the various pieces of the GNU toolchain has), so here's v2 of the change with a fix for that problem being the only update. Also I have since run verification with the `riscv64-linux-gnu' target and the ilp32d multilib as more representative for the change being made. No problems were observed, although the now enabled test case scored: UNSUPPORTED: gcc.dg/div64-unwinding.c of course with the target failing the `! *-*-linux*' condition. Given that for the `riscv64-linux-gnu' target and the ilp32d multilib glibc currently fails to link against libgcc.a built at -O0 I first ran reference testing with target libraries built at -O2, but comparing that to change-under-test -O2 results revealed another issue with GCC target libraries built at -O0 causing link failures across testsuites, namely libgcov.a referring atomic primitives where libatomic.a has not been linked in. I haven't figured out yet if the issue is in libgcov, the testsuite or the specs. Examples of failures: .../bin/riscv64-linux-gnu-ld: .../gcc/testsuite/g++/../../lib32/ilp32d/libgcov.a(_gcov_indirect_call_profiler_v4.o): in function `__gcov_topn_values_profiler_body': .../libgcc/libgcov-profiler.c:116: undefined reference to `__atomic_fetch_add_8' .../bin/riscv64-linux-gnu-ld: .../libgcc/libgcov-profiler.c:129: undefined reference to `__atomic_fetch_add_8' .../bin/riscv64-linux-gnu-ld: .../libgcc/libgcov-profiler.c:150: undefined reference to `__atomic_fetch_sub_8' collect2: error: ld returned 1 exit status compiler exited with status 1 FAIL: g++.dg/other/pr55650.C -std=gnu++98 (test for excess errors) There were some odd Fortran failures too, with test cases failing to link, making the results difficult to interpret. Therefore I decided to arrange for a special build with first stage GCC built with its target libraries at -O2, so that first stage glibc builds, and then second stage GCC built with its target libraries at -O0 and second stage glibc omitted. That removed the extra Fortran failures regardless of whether this change has been applied or not, but we may consider looking overall into why a full `riscv64-linux-gnu' build at -O0 has regressions against -O2 at least in the ilp32d multilib. Meanwhile, OK to apply? Maciej Changes from v1: - ChangeLog entries added. --- gcc/testsuite/gcc.dg/div64-unwinding.c | 25 +++++++++++++++++++++++++ gcc/testsuite/gcc.target/arm/div64-unwinding.c | 25 ------------------------- libgcc/Makefile.in | 2 +- libgcc/config/arm/t-bpabi | 5 ----- libgcc/config/arm/t-netbsd-eabi | 5 ----- 5 files changed, 26 insertions(+), 36 deletions(-) gcc-libgcc-divmod-asynchronous-unwind-tables.diff Index: gcc/gcc/testsuite/gcc.dg/div64-unwinding.c =================================================================== --- /dev/null +++ gcc/gcc/testsuite/gcc.dg/div64-unwinding.c @@ -0,0 +1,25 @@ +/* Performing a 64-bit division should not pull in the unwinder. */ + +/* { dg-do run { target { { ! *-*-linux* } && { ! *-*-uclinux* } } } } */ +/* { dg-skip-if "load causes weak symbol resolution" { vxworks_kernel } } */ +/* { dg-options "-O0" } */ + +#include + +long long +foo (long long c, long long d) +{ + return c/d; +} + +long long x = 0; +long long y = 1; + +extern int (*_Unwind_RaiseException) (void *) __attribute__((weak)); + +int main(void) +{ + if (&_Unwind_RaiseException != NULL) + abort ();; + return foo (x, y); +} Index: gcc/gcc/testsuite/gcc.target/arm/div64-unwinding.c =================================================================== --- gcc.orig/gcc/testsuite/gcc.target/arm/div64-unwinding.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Performing a 64-bit division should not pull in the unwinder. */ - -/* { dg-do run { target { { ! *-*-linux* } && { ! *-*-uclinux* } } } } */ -/* { dg-skip-if "load causes weak symbol resolution" { vxworks_kernel } } */ -/* { dg-options "-O0" } */ - -#include - -long long -foo (long long c, long long d) -{ - return c/d; -} - -long long x = 0; -long long y = 1; - -extern int (*_Unwind_RaiseException) (void *) __attribute__((weak)); - -int main(void) -{ - if (&_Unwind_RaiseException != NULL) - abort ();; - return foo (x, y); -} Index: gcc/libgcc/Makefile.in =================================================================== --- gcc.orig/libgcc/Makefile.in +++ gcc/libgcc/Makefile.in @@ -533,7 +533,7 @@ endif ifeq ($(LIB2_DIVMOD_EXCEPTION_FLAGS),) # Provide default flags for compiling divmod functions, if they haven't been # set already by a target-specific Makefile fragment. -LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions -fnon-call-exceptions +LIB2_DIVMOD_EXCEPTION_FLAGS := -fasynchronous-unwind-tables endif # Build LIB2_DIVMOD_FUNCS. Index: gcc/libgcc/config/arm/t-bpabi =================================================================== --- gcc.orig/libgcc/config/arm/t-bpabi +++ gcc/libgcc/config/arm/t-bpabi @@ -13,8 +13,3 @@ LIB2ADDEH = $(srcdir)/config/arm/unwind- # Add the BPABI names. SHLIB_MAPFILES += $(srcdir)/config/arm/libgcc-bpabi.ver - -# On ARM, specifying -fnon-call-exceptions will needlessly pull in -# the unwinder in simple programs which use 64-bit division. Omitting -# the option is safe. -LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions Index: gcc/libgcc/config/arm/t-netbsd-eabi =================================================================== --- gcc.orig/libgcc/config/arm/t-netbsd-eabi +++ gcc/libgcc/config/arm/t-netbsd-eabi @@ -11,8 +11,3 @@ LIB2ADDEH = # Add the BPABI names. SHLIB_MAPFILES += $(srcdir)/config/arm/libgcc-bpabi.ver - -# On ARM, specifying -fnon-call-exceptions will needlessly pull in -# the unwinder in simple programs which use 64-bit division. Omitting -# the option is safe. -LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions