From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78056 invoked by alias); 25 Oct 2016 09:47:23 -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 76949 invoked by uid 89); 25 Oct 2016 09:47:22 -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,SPF_PASS autolearn=no version=3.3.2 spammy=Apply, cap, IN_RANGE, in_range X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Oct 2016 09:47:12 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01lp0209.outbound.protection.outlook.com [213.199.154.209]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-57-ZYYWS33SOi2tABL0lURH7w-1; Tue, 25 Oct 2016 10:47:08 +0100 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.669.16; Tue, 25 Oct 2016 09:47:07 +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.0669.021; Tue, 25 Oct 2016 09:47:07 +0000 From: Wilco Dijkstra To: Richard Earnshaw , GCC Patches CC: nd Subject: Re: [PATCH v2][AArch64] Fix symbol offset limit Date: Tue, 25 Oct 2016 09:47:00 -0000 Message-ID: References: ,<896d038e-f19f-d95e-2213-f3360ba71b28@arm.com>,,, In-Reply-To: x-ms-office365-filtering-correlation-id: e8252dc4-5a22-4c4e-d878-08d3fcbbe225 x-microsoft-exchange-diagnostics: 1;AM5PR0802MB2388;7:ktbYITmnYh5nNuDbb/OAUGUUl0+a3L0E0vVn7jg9kfhURUY3xIcE2UW4Pu+dJ1Ak8Ipu+/MGcu0BfIN8OKUtjvH3osqgNSjdgazuN7qDCsFUSVb+8XeoIh7AcxM0E9UrVwqv3WQuFfj7S5Qc9EdiG60uk3HGWwd3UUlU4VFB/oWvUj3IXkFXhjr9ZG23m8X/qaYf/M/ocXfXyhEXk9yePaaocHsiOhvqABObvodi9hodNp3BqfhVdkKpcuL+kb32eUdr5QGqQ80NH4FFMG3ZxmpJ1bObFQ7B0qeOfU+bAOz4V/1w/spp/PK/E3NOkoe8bwwOIByyVGcVlo2FnJYbsD5BjDk3n22qXKrIsCMhRCw= 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)(10201501046)(3002001)(6055026);SRVR:AM5PR0802MB2388;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2388; x-forefront-prvs: 01068D0A20 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(199003)(189002)(24454002)(377424004)(54534003)(97736004)(81156014)(3280700002)(2900100001)(50986999)(7736002)(76176999)(93886004)(11100500001)(54356999)(19580395003)(305945005)(7846002)(19580405001)(9686002)(3846002)(5001770100001)(105586002)(76576001)(92566002)(586003)(86362001)(5002640100001)(77096005)(68736007)(450100001)(74316002)(102836003)(106116001)(101416001)(6116002)(122556002)(8676002)(8936002)(3900700001)(5660300001)(106356001)(81166006)(2950100002)(66066001)(87936001)(3660700001)(10400500002)(7696004)(189998001)(4326007)(33656002)(2906002);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; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Oct 2016 09:47:07.0585 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2388 X-MC-Unique: ZYYWS33SOi2tABL0lURH7w-1 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2016-10/txt/msg01992.txt.bz2 =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