From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12612 invoked by alias); 17 Sep 2018 11:20:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 12251 invoked by uid 89); 17 Sep 2018 11:20:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=temp, wired, thumb X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Sep 2018 11:20:19 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 1DB6D8138E for ; Mon, 17 Sep 2018 13:20:16 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iti84ENx5irT for ; Mon, 17 Sep 2018 13:20:15 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id D63C281385 for ; Mon, 17 Sep 2018 13:20:15 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [ARM] Fix ICE during thunk generation with -mlong-calls Date: Mon, 17 Sep 2018 11:23:00 -0000 Message-ID: <1722777.YijAB52ccF@polaris> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart6174839.0dPLneIdAZ" Content-Transfer-Encoding: 7Bit X-SW-Source: 2018-09/txt/msg00860.txt.bz2 This is a multi-part message in MIME format. --nextPart6174839.0dPLneIdAZ Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Content-length: 1269 Hi, this is a regression present on mainline, 8 and 7 branches. The new, RTL implementation of arm32_output_mi_thunk breaks during the libstdc++ build if you configure the compiler with -mlong-calls by default: 0xdb57eb gen_reg_rtx(machine_mode) /home/eric/svn/gcc/gcc/emit-rtl.c:1155 0xde9ae7 force_reg(machine_mode, rtx_def*) /home/eric/svn/gcc/gcc/explow.c:654 0x1bf73bf gen_sibcall(rtx_def*, rtx_def*, rtx_def*) /home/eric/svn/gcc/gcc/config/arm/arm.md:8272 0x187d3b1 arm32_output_mi_thunk /home/eric/svn/gcc/gcc/config/arm/arm.c:26762 0x187d4af arm_output_mi_thunk /home/eric/svn/gcc/gcc/config/arm/arm.c:26783 0xcb9c94 cgraph_node::expand_thunk(bool, bool) /home/eric/svn/gcc/gcc/cgraphunit.c:1783 because the code is wired for a short call. Moreover, in PIC mode you need to work harder and fix up the minipool too with -mlong-calls. Tested on ARM/Linux, OK for mainline, 8 and 7 branches? 2018-09-17 Eric Botcazou * config/arm/arm.c (arm_reorg): Skip Thumb reorg pass for thunks. (arm32_output_mi_thunk): Deal with long calls. 2018-09-17 Eric Botcazou * g++.dg/other/thunk2a.C: New test. * g++.dg/other/thunk2b.C: Likewise. -- Eric Botcazou --nextPart6174839.0dPLneIdAZ Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="p.diff" Content-length: 1468 Index: config/arm/arm.c =================================================================== --- config/arm/arm.c (revision 264342) +++ config/arm/arm.c (working copy) @@ -17647,7 +17647,9 @@ arm_reorg (void) if (use_cmse) cmse_nonsecure_call_clear_caller_saved (); - if (TARGET_THUMB1) + if (cfun->is_thunk) + ; + else if (TARGET_THUMB1) thumb1_reorg (); else if (TARGET_THUMB2) thumb2_reorg (); @@ -26721,6 +26723,8 @@ static void arm32_output_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, tree function) { + const bool long_call_p = arm_is_long_call_p (function); + /* On ARM, this_regno is R0 or R1 depending on whether the function returns an aggregate or not. */ @@ -26758,9 +26762,22 @@ arm32_output_mi_thunk (FILE *file, tree, TREE_USED (function) = 1; } rtx funexp = XEXP (DECL_RTL (function), 0); + if (long_call_p) + { + emit_move_insn (temp, funexp); + funexp = temp; + } funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); - rtx_insn * insn = emit_call_insn (gen_sibcall (funexp, const0_rtx, NULL_RTX)); + rtx_insn *insn = emit_call_insn (gen_sibcall (funexp, const0_rtx, NULL_RTX)); SIBLING_CALL_P (insn) = 1; + emit_barrier (); + + /* Indirect calls require a bit of fixup in PIC mode. */ + if (long_call_p) + { + split_all_insns_noflow (); + arm_reorg (); + } insn = get_insns (); shorten_branches (insn); --nextPart6174839.0dPLneIdAZ Content-Disposition: attachment; filename="thunk2a.C" Content-Transfer-Encoding: 7Bit Content-Type: text/x-c++src; charset="UTF-8"; name="thunk2a.C" Content-length: 194 // { dg-do compile { target arm*-*-* } } // { dg-options "-mlong-calls -ffunction-sections } class a { public: virtual ~a(); }; class b : virtual a {}; class c : b { ~c(); }; c::~c() {} --nextPart6174839.0dPLneIdAZ Content-Disposition: attachment; filename="thunk2b.C" Content-Transfer-Encoding: 7Bit Content-Type: text/x-c++src; charset="UTF-8"; name="thunk2b.C" Content-length: 208 // { dg-do compile { target arm*-*-* && fpic } } // { dg-options "-mlong-calls -ffunction-sections -fPIC } class a { public: virtual ~a(); }; class b : virtual a {}; class c : b { ~c(); }; c::~c() {} --nextPart6174839.0dPLneIdAZ--