From patchwork Tue Nov 29 09:09:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 84525 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1510051qgi; Tue, 29 Nov 2016 01:10:07 -0800 (PST) X-Received: by 10.98.166.136 with SMTP id r8mr26560905pfl.113.1480410607241; Tue, 29 Nov 2016 01:10:07 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e186si27941024pgc.45.2016.11.29.01.10.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Nov 2016 01:10:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-442855-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-442855-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-442855-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=NLKpzD+AATJF/95T0ckUeykN+erty1QE0GjmkAdsMY0 zZDNurp0B189DYzJKdmyMG/LmQ97R8au9qcxZZ9ikfpPwxmzaovXM2UzQhg13Yvi GKimMKHCEWmjVTcTyvBKbJq1QQv7HFpsfGQF/9x0jegxWti+sGXnpO7O5TrZREqE = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=+ZTYJBSSFDIs2wn8II9cwh6KTnM=; b=EWrNXOKfp9ThG756B krY29JBeXTRtsb+dp0gk94jb7VxHu9c4M51OqwPytye1XXS6sqM9UeNU/LOBkAxx 47lP3KkSWrGH5+ve+sIMo24NnPv9ZkafhOYPwezBQ6qohqXyB/RnO56C77zjMo6T zDQ3FLjcJKTrXkGeWrbwfxAmHE= Received: (qmail 30184 invoked by alias); 29 Nov 2016 09:09:51 -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 30157 invoked by uid 89); 29 Nov 2016 09:09:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, KAM_STOCKGEN, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=dbs, gen_lowpart, pmode, 2016-11-29 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; Tue, 29 Nov 2016 09:09:40 +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 7EF78AD7; Tue, 29 Nov 2016 01:09:38 -0800 (PST) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BDB7E3F445; Tue, 29 Nov 2016 01:09:37 -0800 (PST) Message-ID: <583D45D0.5000201@foss.arm.com> Date: Tue, 29 Nov 2016 09:09:36 +0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches CC: Marcus Shawcroft , Richard Earnshaw , James Greenhalgh Subject: [PATCH][AArch64] PR target/71112: Properly create lowpart of pic_offset_table_rtx with -fpie Hi all, This ICE only occurs on big-endian ILP32 -fpie code. The expansion code generates the invalid load: (insn 6 5 7 (set (reg/f:SI 76) (unspec:SI [ (mem/u/c:SI (lo_sum:SI (nil) (symbol_ref:SI ("dbs") [flags 0x40] )) [0 S4 A8]) ] UNSPEC_GOTSMALLPIC28K)) (expr_list:REG_EQUAL (symbol_ref:SI ("dbs") [flags 0x40] ) (nil))) to load the symbol. Note the (nil) argument to lo_sum. The buggy hunk meant to take the lowpart of the pic_offset_table_rtx register but it did so by explicitly constructing a subreg, for which the offset is wrong for big-endian. The right way is to use gen_lowpart which knows what exactly to do, with this patch we emit: (insn 6 5 7 (set (reg/f:SI 76) (unspec:SI [ (mem/u/c:SI (lo_sum:SI (subreg:SI (reg:DI 73) 4) (symbol_ref:SI ("dbs") [flags 0x40] )) [0 S4 A8]) ] UNSPEC_GOTSMALLPIC28K)) (expr_list:REG_EQUAL (symbol_ref:SI ("dbs") [flags 0x40] ) (nil))) and everything works fine. Bootstrapped and tested on aarch64-none-linux-gnu. Also tested on aarch64_be-none-elf. Ok for trunk? Thanks, Kyrill 2016-11-29 Kyrylo Tkachov PR target/71112 * config/aarch64/aarch64.c (aarch64_load_symref_appropriately, case SYMBOL_SMALL_GOT_28K): Use gen_lowpart rather than constructing subreg directly. 2016-11-29 Kyrylo Tkachov PR target/71112 * gcc.c-torture/compile/pr71112.c: New test. commit 99052634535958a776a2e7b7c9c6169cb656f5a8 Author: Kyrylo Tkachov Date: Mon Nov 28 12:26:57 2016 +0000 [AArch64] PR target/71112: Properly create lowpart of pic_offset_table_rtx with -fpie diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 686a8e92..aa833c8 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -1299,7 +1299,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, emit_move_insn (gp_rtx, gen_rtx_HIGH (Pmode, s)); if (mode != GET_MODE (gp_rtx)) - gp_rtx = simplify_gen_subreg (mode, gp_rtx, GET_MODE (gp_rtx), 0); + gp_rtx = gen_lowpart (mode, gp_rtx); } if (mode == ptr_mode) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr71112.c b/gcc/testsuite/gcc.c-torture/compile/pr71112.c new file mode 100644 index 0000000..69e2df6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr71112.c @@ -0,0 +1,10 @@ +/* PR target/71112. */ +/* { dg-additional-options "-fpie" { target pie } } */ + +extern int dbs[100]; +void f (int *); +int nscd_init (void) +{ + f (dbs); + return 0; +}