From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42151 invoked by alias); 2 Nov 2016 16:48:47 -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 41169 invoked by uid 89); 2 Nov 2016 16:48:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,KAM_LOTSOFHASH,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=no version=3.3.2 spammy=cap, host_wide_int_c, HOST_WIDE_INT_C, HContent-Language:en-GB X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr20056.outbound.protection.outlook.com (HELO EUR02-VE1-obe.outbound.protection.outlook.com) (40.107.2.56) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Nov 2016 16:48:36 +0000 Received: from AM5PR0802MB2610.eurprd08.prod.outlook.com (10.175.46.18) by AM5PR0802MB2388.eurprd08.prod.outlook.com (10.175.43.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12; Wed, 2 Nov 2016 16:48:33 +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.0693.009; Wed, 2 Nov 2016 16:48:33 +0000 From: Wilco Dijkstra To: Richard Earnshaw , GCC Patches CC: nd Subject: Re: [PATCH v2][AArch64] Fix symbol offset limit Date: Wed, 02 Nov 2016 16:48:00 -0000 Message-ID: References: ,<896d038e-f19f-d95e-2213-f3360ba71b28@arm.com>,,,, In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-office365-filtering-correlation-id: de6b61e8-bf52-4a97-3542-08d403401561 x-microsoft-exchange-diagnostics: 1;AM5PR0802MB2388;7:FQnJkLtMgjh5I625pn/FFVaNbf4eLf6mjH+mWOXZTkRvRjkE4X62BdoYh/pKY0MKe6/JqXcbOiTgL5ekmI8M7s4F5vvhWiHoco+Ez+RmyLWxAZpQ2uYB1k40geD3PoI28s45Oei7K6cyXo08iW8Sdj90NvSOT97+npR0UlYdzX2eex/63n2tLo8xb0LNieiJwPoB8Xx6XxwQDCeLIVl5diMK0lH59E8q/XVcy3TUqvdUCJRlIJEbLPt9u+DJzPFwQsU7+RZ/eBsoXKIojST8SDUmJ3KIa6lgkhQ/nr7j6wzTALRRETM2w9M1LzkKbNonQosdJ9k431RRWpb0oZITvWaQsd2j29EzXmePy64ckIY= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2388; 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:AM5PR0802MB2388;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2388; x-forefront-prvs: 0114FF88F6 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(199003)(377424004)(189002)(24454002)(54534003)(76576001)(586003)(122556002)(19580405001)(2900100001)(19580395003)(7696004)(10400500002)(5002640100001)(3660700001)(11100500001)(3900700001)(4326007)(33656002)(101416001)(6116002)(54356999)(106356001)(5001770100001)(106116001)(76176999)(105586002)(102836003)(3280700002)(50986999)(3846002)(8936002)(97736004)(2950100002)(305945005)(189998001)(74316002)(7846002)(87936001)(7736002)(93886004)(92566002)(450100001)(2906002)(66066001)(81156014)(5660300001)(77096005)(8676002)(81166006)(86362001)(68736007)(9686002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0802MB2388;H:AM5PR0802MB2610.eurprd08.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Nov 2016 16:48:33.6414 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2388 X-SW-Source: 2016-11/txt/msg00216.txt.bz2 =A0=20=20=20 =A0 ping From: Wilco Dijkstra Sent: 12 September 2016 15:50 To: Richard Earnshaw; GCC Patches Cc: nd Subject: Re: [PATCH v2][AArch64] Fix symbol offset limit =A0=A0=A0=20 Wilco wrote:=A0=A0=A0=20 > The original example is from GCC itself, the fixed_regs array is small bu= t due to > optimization we can end up with &fixed_regs + 0xffffffff. We could also check the bounds of each symbol if they exist, like the patch= below. In aarch64_classify_symbol symbols are allowed full-range offsets on reloca= tions. This means the offset can use all of the +/-4GB offset, leaving no offset a= vailable for the symbol itself.=A0 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 wi= thin a 3GB offset from its references.=A0 For the tiny code model use a 64KB offse= t, allowing most of the 1MB range for code/data between the symbol and its references. For symbols with a defined size, limit the offset to be within the size of = the symbol. ChangeLog: 2016-09-12=A0 Wilco Dijkstra=A0 =A0=A0=A0 gcc/ =A0=A0=A0=A0=A0=A0=A0 * config/aarch64/aarch64.c (aarch64_classify_symbol): =A0=A0=A0=A0=A0=A0=A0 Apply reasonable limit to symbol offsets. =A0=A0=A0 testsuite/ =A0=A0=A0=A0=A0=A0=A0 * gcc.target/aarch64/symbol-range.c (foo): Set new li= mit. =A0=A0=A0=A0=A0=A0=A0 * gcc.target/aarch64/symbol-range-tiny.c (foo): Likew= ise. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 385bd560fb12cd5d404e6ddb2f01edf1fe72d729..275a828ac9e6e9b8187380c1b60= 2ffb1b2bcfb21 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -9351,6 +9351,8 @@ aarch64_classify_symbol (rtx x, rtx offset) =A0=A0=A0=A0=A0=A0 if (aarch64_tls_symbol_p (x)) =A0=A0=A0=A0=A0=A0=A0=A0 return aarch64_classify_tls_symbol (x); =A0 +=A0=A0=A0=A0=A0 const_tree decl =3D SYMBOL_REF_DECL (x); + =A0=A0=A0=A0=A0=A0 switch (aarch64_cmodel) =A0=A0=A0=A0=A0=A0=A0=A0 { =A0=A0=A0=A0=A0=A0=A0=A0 case AARCH64_CMODEL_TINY: @@ -9359,25 +9361,45 @@ aarch64_classify_symbol (rtx x, rtx offset) =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 we have no way of knowing the addre= ss of symbol at compile time =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 so we can't accurately say if the d= istance between the PC and =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 symbol + offset is outside the addr= essible range of +/-1M in the -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 TINY code model.=A0 So we rely on images= not being greater than -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 1M and cap the offset at 1M and anything= beyond 1M will have to -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 be loaded using an alternative mechanism= .=A0 Furthermore if the -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 symbol is a weak reference to something = that isn't known to -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 resolve to a symbol in this module, then= force to memory.=A0 */ +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 TINY code model.=A0 So we limit the maxi= mum offset to +/-64KB and +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 assume the offset to the symbol is not l= arger than +/-(1M - 64KB). +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Furthermore force to memory if the symbo= l is a weak reference to +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 something that doesn't resolve to a symb= ol in this module.=A0 */ =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if ((SYMBOL_REF_WEAK (x) =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 && !aarch64_symbol_binds_loca= l_p (x)) -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 || INTVAL (offset) < -1048575 || INTV= AL (offset) > 1048575) +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 || !IN_RANGE (INTVAL (offset), -0x100= 00, 0x10000)) =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return SYMBOL_FORCE_TO_MEM; + +=A0=A0=A0=A0=A0=A0=A0=A0 /* Limit offset to within the size of a declarati= on if available.=A0 */ +=A0=A0=A0=A0=A0=A0=A0=A0 if (decl && DECL_P (decl)) +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 { +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 const_tree decl_size =3D DECL_SIZE (d= ecl); + +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (decl_size +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 && !IN_RANGE (INTVAL (off= set), 0, tree_to_shwi (decl_size))) +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return SYMBOL_FORCE_TO_MEM; +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } + =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return SYMBOL_TINY_ABSOLUTE; =A0 =A0=A0=A0=A0=A0=A0=A0=A0 case AARCH64_CMODEL_SMALL: =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 /* Same reasoning as the tiny code model, bu= t the offset cap here is -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 4G.=A0 */ +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 1G, allowing +/-3G for the offset to the= symbol.=A0 */ =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if ((SYMBOL_REF_WEAK (x) =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 && !aarch64_symbol_binds_loca= l_p (x)) -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 || !IN_RANGE (INTVAL (offset), HOST_W= IDE_INT_C (-4294967263), -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 HOST_WIDE_INT_C (4294967264))) +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 || !IN_RANGE (INTVAL (offset), -0x400= 00000, 0x40000000)) =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return SYMBOL_FORCE_TO_MEM; + +=A0=A0=A0=A0=A0=A0=A0=A0 /* Limit offset to within the size of a declarati= on if available.=A0 */ +=A0=A0=A0=A0=A0=A0=A0=A0 if (decl && DECL_P (decl)) +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 { +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 const_tree decl_size =3D DECL_SIZE (d= ecl); + +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (decl_size +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 && !IN_RANGE (INTVAL (off= set), 0, tree_to_shwi (decl_size))) +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return SYMBOL_FORCE_TO_MEM; +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } + =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return SYMBOL_SMALL_ABSOLUTE; =A0 =A0=A0=A0=A0=A0=A0=A0=A0 case AARCH64_CMODEL_TINY_PIC: diff --git a/gcc/testsuite/gcc.target/aarch64/symbol-range-tiny.c b/gcc/tes= tsuite/gcc.target/aarch64/symbol-range-tiny.c index d7e46b059e41f2672b3a1da5506fa8944e752e01..d399a3637ed834ddc4bb429594c= 4ec229b5c2ea8 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 } */ =A0/* { dg-options "-O3 -save-temps -mcmodel=3Dtiny" } */ =A0 -int fixed_regs[0x00200000]; +char fixed_regs[0x00200000]; =A0 =A0int -foo() +main() =A0{ -=A0 return fixed_regs[0x00080000]; +=A0 return fixed_regs[0x000ff000]; =A0} =A0 =A0/* { dg-final { scan-assembler-not "adr\tx\[0-9\]+, fixed_regs\\\+" } } = */ diff --git a/gcc/testsuite/gcc.target/aarch64/symbol-range.c b/gcc/testsuit= e/gcc.target/aarch64/symbol-range.c index 6574cf4310430b847e77ea56bf8f20ef312d53e4..4b4ec8dab9321026d1fae96d336= 565a7883c8203 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 } */ =A0/* { dg-options "-O3 -save-temps -mcmodel=3Dsmall" } */ =A0 -int fixed_regs[0x200000000ULL]; +char fixed_regs[0x200000000ULL]; =A0 =A0int -foo() +main() =A0{ -=A0 return fixed_regs[0x100000000ULL]; +=A0 return fixed_regs[0xfffff000ULL]; =A0} =A0 =A0/* { dg-final { scan-assembler-not "adrp\tx\[0-9\]+, fixed_regs\\\+" } }= */=A0=A0=A0=A0=A0=A0=A0=20=20=20=20=20