From patchwork Tue Aug 23 14:10:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 661881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3sJXRL6FGJz9t0w for ; Wed, 24 Aug 2016 00:11:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=WzCTbLdr; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Oi4amDOScwNCEdks GyKX6lafFYWPVt9Q5R7oqjz3lv85T9fqObivZ59GBX6cEidgFF+glRCDnryR0d6V +9nAAX1kEm8NIrGNWzWNEYH/xXaMQRAxuavM2jkUlq+xOULyqCkXOSIvv7mS3o2f RDm6Yjaziz2LEPd/OMwL+pDck5I= 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:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=2GFcv1746wsmTJrUIioBqn ZCGX8=; b=WzCTbLdrQc0bzkdNrIWbAdb8OuzsYd3UpJI/zXR4D+D0s+4KZCQ8NG 2x2gvUQoSE+dRmW0oqbGfii8xKJvqtfAlFwnHgEmCIRpiVXYA4EfBdDcDg9GAabN kH91B54N4B3bKgS9t38WoIirN6LdTwN4Qu4TYQNg0A2IhVaZ+jDHc= Received: (qmail 12364 invoked by alias); 23 Aug 2016 14:11:00 -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 11830 invoked by uid 89); 23 Aug 2016 14:10:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=BAYES_00, KAM_LOTSOFHASH, KAM_STOCKGEN, SPF_PASS autolearn=no version=3.3.2 spammy=HContent-Language:en-GB, H*RU:sk:mail-he, Hx-spam-relays-external:sk:mail-he, 1gb X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Aug 2016 14:10:45 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-he1eur02lp0182.outbound.protection.outlook.com [213.199.180.182]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-54-CmziInykPDa8MumQcU4HnA-1; Tue, 23 Aug 2016 15:10:41 +0100 Received: from AM5PR0802MB2610.eurprd08.prod.outlook.com (10.175.46.18) by AM5PR0802MB2612.eurprd08.prod.outlook.com (10.175.46.20) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.21; Tue, 23 Aug 2016 14:10:39 +0000 Received: from AM5PR0802MB2610.eurprd08.prod.outlook.com ([10.175.46.18]) by AM5PR0802MB2610.eurprd08.prod.outlook.com ([10.175.46.18]) with mapi id 15.01.0557.027; Tue, 23 Aug 2016 14:10:39 +0000 From: Wilco Dijkstra To: GCC Patches CC: nd Subject: [PATCH][AArch64] Fix symbol offset limit Date: Tue, 23 Aug 2016 14:10:39 +0000 Message-ID: x-ms-office365-filtering-correlation-id: cb9296cb-bef1-4465-e153-08d3cb5f42d8 x-microsoft-exchange-diagnostics: 1; AM5PR0802MB2612; 20:1hXE97gI2ShOWwkD8Pc7lVa2qaoFD8f3kZHMmRgAqHuwBcw0MGA0xlsnHyTYMIPvcGYPmdVXyd/bcinw8VjsfRl+QDjdg/dWjVHzsK/AO82n575Xy/Fi33JdRrgC9tzX45HuLjNtrP+ZPMwOonhtd/MziGp89qhBqAiSqhh6VR8= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2612; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:AM5PR0802MB2612; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2612; x-forefront-prvs: 004395A01C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(54534003)(189002)(377424004)(199003)(77096005)(110136002)(2900100001)(10400500002)(189998001)(122556002)(97736004)(92566002)(106356001)(4326007)(5660300001)(102836003)(229853001)(6116002)(3280700002)(66066001)(3660700001)(2906002)(101416001)(8936002)(86362001)(450100001)(68736007)(7846002)(50986999)(105586002)(76576001)(11100500001)(7736002)(54356999)(305945005)(7696003)(19580405001)(74316002)(3846002)(19580395003)(81156014)(8676002)(81166006)(9686002)(106116001)(586003)(33656002)(87936001)(5002640100001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0802MB2612; H:AM5PR0802MB2610.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Aug 2016 14:10:39.1852 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2612 X-MC-Unique: CmziInykPDa8MumQcU4HnA-1 In aarch64_classify_symbol symbols are allowed full-range offsets on relocations. This means the offset can use all of the +/-4GB offset, leaving no offset available for the symbol itself. This results in relocation overflow and link-time errors for simple expressions like &global_char + 0xffffff00. To avoid this, limit the offset to +/-1GB so that the symbol needs to be within a 3GB offset from its references. For the tiny code model use a 64KB offset, allowing most of the 1MB range for code/data between the symbol and its references. Bootstrap OK, updated tests now pass rather than failing with symbol out of range. OK for commit? As this is a latent bug, OK to backport to GCC6.x? ChangeLog: 2016-08-23 Wilco Dijkstra gcc/ * config/aarch64/aarch64.c (aarch64_classify_symbol): Apply reasonable limit to symbol offsets. testsuite/ * gcc.target/aarch64/symbol-range.c (foo): Set new limit. * gcc.target/aarch64/symbol-range-tiny.c (foo): Likewise. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index ab609223db7c54f467183db39c4f1ae8b789bfb5..60cc61a095bc144d602597a35b51b9a426c76c69 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -9367,24 +9367,22 @@ aarch64_classify_symbol (rtx x, rtx offset) we have no way of knowing the address of symbol at compile time so we can't accurately say if the distance between the PC and symbol + offset is outside the addressible range of +/-1M in the - TINY code model. So we rely on images not being greater than - 1M and cap the offset at 1M and anything beyond 1M will have to - be loaded using an alternative mechanism. Furthermore if the - symbol is a weak reference to something that isn't known to - resolve to a symbol in this module, then force to memory. */ + TINY code model. So we limit the maximum offset to +/-64KB and + assume the offset to the symbol is not larger than +/-(1M - 64KB). + Furthermore force to memory if the symbol is a weak reference to + something that doesn't resolve to a symbol in this module. */ if ((SYMBOL_REF_WEAK (x) && !aarch64_symbol_binds_local_p (x)) - || INTVAL (offset) < -1048575 || INTVAL (offset) > 1048575) + || !IN_RANGE (INTVAL (offset), -0x10000, 0x10000)) return SYMBOL_FORCE_TO_MEM; return SYMBOL_TINY_ABSOLUTE; case AARCH64_CMODEL_SMALL: /* Same reasoning as the tiny code model, but the offset cap here is - 4G. */ + 1G, allowing +/-3G for the offset to the symbol. */ if ((SYMBOL_REF_WEAK (x) && !aarch64_symbol_binds_local_p (x)) - || !IN_RANGE (INTVAL (offset), HOST_WIDE_INT_C (-4294967263), - HOST_WIDE_INT_C (4294967264))) + || !IN_RANGE (INTVAL (offset), -0x40000000, 0x40000000)) return SYMBOL_FORCE_TO_MEM; return SYMBOL_SMALL_ABSOLUTE; diff --git a/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c b/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c index d7e46b059e41f2672b3a1da5506fa8944e752e01..d399a3637ed834ddc4bb429594c4ec229b5c2ea8 100644 --- a/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c +++ b/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c @@ -1,12 +1,12 @@ -/* { dg-do compile } */ +/* { dg-do link } */ /* { dg-options "-O3 -save-temps -mcmodel=tiny" } */ -int fixed_regs[0x00200000]; +char fixed_regs[0x00200000]; int -foo() +main() { - return fixed_regs[0x00080000]; + return fixed_regs[0x000ff000]; } /* { dg-final { scan-assembler-not "adr\tx\[0-9\]+, fixed_regs\\\+" } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/symbol-range.c b/gcc/testsuite/gcc.target/aarch64/symbol-range.c index 6574cf4310430b847e77ea56bf8f20ef312d53e4..4b4ec8dab9321026d1fae96d336565a7883c8203 100644 --- a/gcc/testsuite/gcc.target/aarch64/symbol-range.c +++ b/gcc/testsuite/gcc.target/aarch64/symbol-range.c @@ -1,12 +1,12 @@ -/* { dg-do compile } */ +/* { dg-do link } */ /* { dg-options "-O3 -save-temps -mcmodel=small" } */ -int fixed_regs[0x200000000ULL]; +char fixed_regs[0x200000000ULL]; int -foo() +main() { - return fixed_regs[0x100000000ULL]; + return fixed_regs[0xfffff000ULL]; } /* { dg-final { scan-assembler-not "adrp\tx\[0-9\]+, fixed_regs\\\+" } } */