From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129838 invoked by alias); 13 Jun 2017 14:00:59 -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 129542 invoked by uid 89); 13 Jun 2017 14:00:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LOTSOFHASH,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=2017-01-17, 20170117 X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr50063.outbound.protection.outlook.com (HELO EUR03-VE1-obe.outbound.protection.outlook.com) (40.107.5.63) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Jun 2017 14:00:27 +0000 Received: from VI1PR0802MB2621.eurprd08.prod.outlook.com (10.175.20.147) by VI1PR0802MB2400.eurprd08.prod.outlook.com (10.175.25.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1157.12; Tue, 13 Jun 2017 14:00:28 +0000 Received: from VI1PR0802MB2621.eurprd08.prod.outlook.com ([fe80::4434:9169:8398:f9dd]) by VI1PR0802MB2621.eurprd08.prod.outlook.com ([fe80::4434:9169:8398:f9dd%13]) with mapi id 15.01.1157.017; Tue, 13 Jun 2017 14:00:28 +0000 From: Wilco Dijkstra To: GCC Patches , James Greenhalgh CC: nd , Richard Earnshaw Subject: Re: [PATCH v3][AArch64] Fix symbol offset limit Date: Tue, 13 Jun 2017 14:00: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-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR0802MB2400;7:I/GE3pmbYCqrkGSvbPcqKMl/SWl+btlReca7Z2UtEuMrMy7rcYKsLCVDlRsAkBOk/Qk3S99BsYhg8ASC8zp3pm+p4pvqD79YJ8AwdeFKuFmKbEcfNNyUwoOo1mmABTBcQujgZ2nm5fvoxScuNdOh1mQkTHaQ6R6ylybORCJM2el/90UfDN4OgliYJq1iy/LPa8ojwQMZdruWZ/EDcOXCVcECNHegmN/F7PvI9r2O8AO444ojE/mXXrwy/Rug1yDskYbHwPz1gdbg2WGOMKrVBB7Gp4Baggh1qrMzBFRpkJ41ZMjU4c3pS/omKh2CYaTsBWjq2/O4A7+miwzzEZtdCw== x-ms-traffictypediagnostic: VI1PR0802MB2400: x-ms-office365-filtering-correlation-id: a46d1196-a3e7-41d3-95de-08d4b2648c82 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081);SRVR:VI1PR0802MB2400; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123555025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR0802MB2400;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR0802MB2400; x-forefront-prvs: 0337AFFE9A x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(39840400002)(39860400002)(39410400002)(39850400002)(39400400002)(39450400003)(189002)(377424004)(199003)(54534003)(72206003)(7736002)(106356001)(97736004)(14454004)(2906002)(305945005)(74316002)(105586002)(33656002)(3280700002)(101416001)(3660700001)(93886004)(53546009)(68736007)(25786009)(478600001)(189998001)(4326008)(6116002)(76176999)(54356999)(229853002)(53936002)(55016002)(6246003)(6436002)(38730400002)(6506006)(99286003)(8676002)(81156014)(81166006)(54906002)(2900100001)(5250100002)(6636002)(575784001)(5660300001)(9686003)(86362001)(102836003)(50986999)(2950100002)(8936002)(7696004);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0802MB2400;H:VI1PR0802MB2621.eurprd08.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A: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: 13 Jun 2017 14:00:28.8205 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2400 X-SW-Source: 2017-06/txt/msg00949.txt.bz2 ping From: Wilco Dijkstra Sent: 17 January 2017 15:14 To: Richard Earnshaw; GCC Patches; James Greenhalgh Cc: nd Subject: Re: [PATCH v3][AArch64] Fix symbol offset limit =A0=A0=A0=20 Here is v3 of the patch - tree_fits_uhwi_p was necessary to ensure the size= of a declaration is an integer. So the question is whether we should allow largish offsets outside of the bounds of symbols (v1), no offsets (this ver= sion), or small offsets (small negative and positive offsets just outside a symbol ar= e common). The only thing we can't allow is any offset like we currently do... 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: 2017-01-17=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 e8d65ead95a3c5730c2ffe64a9e057779819f7b4..f1d54e332dc1cf1ef0bc4b1e46b= 0ebebe1c4cea4 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -9809,6 +9809,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: @@ -9817,25 +9819,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 (tree_fits_uhwi_p (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_uhwi (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 (tree_fits_uhwi_p (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_uhwi (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..d49ff4dbe5786ef6d343d2b9005= 2c09676dd7fe5 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..75c87c12f08004c153efc5192e5= cfab566c089db 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=20=20=20=20=20