From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126939 invoked by alias); 15 Aug 2017 16:27:08 -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 126455 invoked by uid 89); 15 Aug 2017 16:26:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL,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= X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0073.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Aug 2017 16:26:32 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com (10.168.86.22) by DB6PR08MB2664.eurprd08.prod.outlook.com (10.175.234.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1341.21; Tue, 15 Aug 2017 16:26:27 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::2d78:6ac0:142:cc9a]) by DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::2d78:6ac0:142:cc9a%18]) with mapi id 15.01.1341.020; Tue, 15 Aug 2017 16:26:27 +0000 From: Wilco Dijkstra To: GCC Patches , James Greenhalgh CC: nd , Richard Earnshaw Subject: Re: [PATCH v3][AArch64] Fix symbol offset limit Date: Tue, 15 Aug 2017 17:36: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;DB6PR08MB2664;6:SmHwsunJL0FDI+BYHTUbVhyAwiCe7+Rg3+0x5AFAPtqlxZG+pNWNPi2a1YJ8UYd9A+DX9PwjsGpWy8BFtb2tWtfMmMTYztWeBH+caBwYqXktez6lDjf6cvZ9B0d6H2881NeHmPkyZQr+k3UlcKN2wElVu+ZE9KzmqhzIfXeLSydPB0IPIVqfzkoLa+W6i7XzCPJ1kY1rkU2z853QJTZ1AsHJGGFgHVKDgwVjSnOKvMLcDT7x7dOHXZlRUqhNN6Q93X1J+yze2tWcbJiAZ5lyZFNegEk2EIcAeGYhB455UXdgNeFu2vF/cJe/WkA9Qz2yhYyJzfh/ZMgMGBTF5/gOPg==;5:55D3F2pMP0/Fd+QtMr3VlqjLpYGEixcS8o0ow5tWA7IN6vUbGYiHomVBlgFguUE+ZwdgBgsYKfmwtSGYseJKiYcJMcIdST/TgziBgQpWD8ZshRfBr42McK4L/ypTI7A96tsKfOiGFj/WWSJHFFYpOQ==;24:fze7fmIQ18d8lmEDXsWHI+1VtInwlYBftrM3e7jHABznMibfngxTogbNTQqQs6U6jlCox6xob+BW7EI559OtNxU/DTCSDqLzMmum0A1Qfk8=;7:y84bufqCX/GqT+OhvRtAGNcn7Q1OQ3o4w309QT7ntqiyEA3pM5JVF/YU6HOs7r9fAdF2h16zgh/EHxLmNHnRP+EDCoFB3riJbsD6Sg2+DOYqc0yUkGVsxKPmceGgufOjkikApU12tIIlZSFo3ZtyTgwAsCnMPL5z8tfFhzdcDjgr5XswptZX6zOw4EXcwJSn8heB17eTdu6rdpydPHr3U8pVP5K1n3RK1ryW7TCzc8M= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 44185c28-f6a0-41e3-12ea-08d4e3fa6101 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DB6PR08MB2664; x-ms-traffictypediagnostic: DB6PR08MB2664: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DB6PR08MB2664;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DB6PR08MB2664; x-forefront-prvs: 04004D94E2 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(377424004)(189002)(199003)(54534003)(189998001)(55016002)(86362001)(50986999)(2906002)(305945005)(5250100002)(72206003)(99286003)(76176999)(575784001)(102836003)(478600001)(3846002)(6506006)(54906002)(6116002)(54356999)(3280700002)(229853002)(7736002)(2950100002)(97736004)(6246003)(8676002)(7696004)(8936002)(9686003)(68736007)(101416001)(106356001)(53936002)(33656002)(4326008)(3660700001)(66066001)(6636002)(74316002)(5660300001)(105586002)(81156014)(93886004)(14454004)(81166006)(2900100001)(53546010)(6436002)(25786009);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR08MB2664;H:DB6PR0801MB2053.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: 15 Aug 2017 16:26:27.3778 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2664 X-SW-Source: 2017-08/txt/msg00957.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=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=20= =20=20=20=20