From patchwork Wed Nov 7 17:49:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihail Ionescu X-Patchwork-Id: 994400 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489274-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=foss.arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XjoZbaE3"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qv774C1Jz9sCw for ; Thu, 8 Nov 2018 04:49:23 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=HGswbMNLYlK4aCWAerUAf6IWiu4NHv/PQ9FVB+hJcasl6D20Ac RhcFJkVGxZzGF/Jr4BmfoWLYdSp4DPz7H4QKxfWo2zU3EGrqgIyQYWxnob/TtAPD dNXwTgrk55gU5Qt9DRHB+Xt6ikcmWpkhO13SM1Br0wh821lxnz7jPkMkg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=A+dkdFfCMDzVyEEZGjINQG8h/Do=; b=XjoZbaE3vJDhB0uM064k LPTrDiwVRBAXzubnQRbct+grXHd9QcNSJ5fOSGwnPm9G5iuDFT/om/RlkZClW6HM dZCBQBpoc9gbg3WcOUwauxLDANugluz4E32IijeJo9hjMmD1OSTIANF4DRK98BSW we89IE1njjPEdeG7ehniTAo= Received: (qmail 82083 invoked by alias); 7 Nov 2018 17:49:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 82007 invoked by uid 89); 7 Nov 2018 17:49:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH autolearn=ham version=3.3.2 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Nov 2018 17:49:11 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A35C8A78; Wed, 7 Nov 2018 09:49:09 -0800 (PST) Received: from [10.2.206.229] (e121093-lin.cambridge.arm.com [10.2.206.229]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D3CBE3F5C0; Wed, 7 Nov 2018 09:49:08 -0800 (PST) To: Ramana Radhakrishnan , Richard Earnshaw , Kyrylo Tkachov , "gcc-patches@gcc.gnu.org" From: Mihail Ionescu Subject: [PATCH, arm] Backport -- Fix ICE during thunk generation with -mlong-calls Message-ID: <23fcdf27-a6ee-79b1-4e5a-21ef0782ef99@foss.arm.com> Date: Wed, 7 Nov 2018 17:49:07 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi All, This is a backport from trunk for GCC 8 and 7. SVN revision: r264595. Regression tested on arm-none-eabi. gcc/ChangeLog 2018-11-02 Mihail Ionescu Backport from mainiline 2018-09-26 Eric Botcazou * config/arm/arm.c (arm_reorg): Skip Thumb reorg pass for thunks. (arm32_output_mi_thunk): Deal with long calls. gcc/testsuite/ChangeLog 2018-11-02 Mihail Ionescu Backport from mainiline 2018-09-17 Eric Botcazou * g++.dg/other/thunk2a.C: New test. * g++.dg/other/thunk2b.C: Likewise. If everything is ok, could someone commit it on my behalf? Best regards, Mihail diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 2ece668219f3ca34883cd882431b0a3c390d4d3c..c68311e0fa192c350d03eb2dd37eca92ae7b3cfa 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -17663,7 +17663,11 @@ arm_reorg (void) if (use_cmse) cmse_nonsecure_call_clear_caller_saved (); - if (TARGET_THUMB1) + + /* We cannot run the Thumb passes for thunks because there is no CFG. */ + if (cfun->is_thunk) + ; + else if (TARGET_THUMB1) thumb1_reorg (); else if (TARGET_THUMB2) thumb2_reorg (); @@ -26737,6 +26741,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. */ @@ -26774,9 +26780,22 @@ arm32_output_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta, 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); diff --git a/gcc/testsuite/g++.dg/other/thunk2a.C b/gcc/testsuite/g++.dg/other/thunk2a.C new file mode 100644 index 0000000000000000000000000000000000000000..8e5ebd4960df758fa77ff08b019e104870f36b45 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/thunk2a.C @@ -0,0 +1,15 @@ +// { 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() {} diff --git a/gcc/testsuite/g++.dg/other/thunk2b.C b/gcc/testsuite/g++.dg/other/thunk2b.C new file mode 100644 index 0000000000000000000000000000000000000000..c8f4570923d8bde71547dd343de45edc0efeb2c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/thunk2b.C @@ -0,0 +1,16 @@ +// { dg-do compile { target arm*-*-* } } +// { dg-options "-mlong-calls -ffunction-sections" } +// { dg-additional-options "-fPIC" { target fpic } } + +class a { +public: + virtual ~a(); +}; + +class b : virtual a {}; + +class c : b { + ~c(); +}; + +c::~c() {} diff --git a/gcc/testsuite/g++.dg/other/vthunk1.C b/gcc/testsuite/g++.dg/other/thunk1.C similarity index 100% rename from gcc/testsuite/g++.dg/other/vthunk1.C rename to gcc/testsuite/g++.dg/other/thunk1.C