From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 411 invoked by alias); 9 Nov 2018 14:47:34 -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 361 invoked by uid 89); 9 Nov 2018 14:47:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.2 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=64kb X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr50073.outbound.protection.outlook.com (HELO EUR03-VE1-obe.outbound.protection.outlook.com) (40.107.5.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Nov 2018 14:47:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RUbX9IvuNtRrCRBByWUvrQncJ4t+UAgLWIzm5yYyuCo=; b=cf4DtQYnZrOnBqP9xpB0MIG9/LbetH3DbsZ/kQoAd/beFr351qfetrnOhsJXrx0e4JmfM8+ukNCcmSKDp1s0HEk8Z68iX89kqjvmMIgmvAdDDaM0X/U8SJ1aPAEbrV4NEF5jI+whiKJYsF7aQtT7GYtGlb05gEIAax2j11Esu34= Received: from DB5PR08MB1030.eurprd08.prod.outlook.com (10.166.14.15) by DB5PR08MB0919.eurprd08.prod.outlook.com (10.166.13.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.29; Fri, 9 Nov 2018 14:47:27 +0000 Received: from DB5PR08MB1030.eurprd08.prod.outlook.com ([fe80::f5c9:8ef6:9b28:8caa]) by DB5PR08MB1030.eurprd08.prod.outlook.com ([fe80::f5c9:8ef6:9b28:8caa%2]) with mapi id 15.20.1294.034; Fri, 9 Nov 2018 14:47:27 +0000 From: Wilco Dijkstra To: GCC Patches CC: nd Subject: [PATCH][AArch64] Fix symbol offset limit Date: Fri, 09 Nov 2018 14:47:00 -0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-SW-Source: 2018-11/txt/msg00727.txt.bz2 In aarch64_classify_symbol symbols are allowed full-range offsets on reloca= tions.=20 This means the offset can use all of the +/-4GB offset, leaving no offset a= vailable for the symbol itself. This results in relocation overflow and link-time e= rrors for simple expressions like &global_char + 0xffffff00. To avoid this, limit the offset to +/-1MB so that the symbol needs to be wi= thin a 3.9GB offset from its references. 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. Bootstrapped on AArch64, passes regress, OK for commit? ChangeLog: 2018-11-09 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 b6ea6d3f14b212b69f76d21b72527b6a8ea8cb0e..be03aeea8cd9bab07a01a161c4a= 91283bd25c99d 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -11794,26 +11794,26 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT off= set) the offset does not cause overflow of the final address. But 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. */ + symbol + offset is outside the addressible range of +/-1MB in the + TINY code model. So we limit the maximum offset to +/-64KB and + assume the offset to the symbol is not larger than +/-(1MB - 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)) - || !IN_RANGE (offset, -1048575, 1048575)) + || !IN_RANGE (offset, -0x10000, 0x10000)) return SYMBOL_FORCE_TO_MEM; + return SYMBOL_TINY_ABSOLUTE; =20 case AARCH64_CMODEL_SMALL: /* Same reasoning as the tiny code model, but the offset cap here is - 4G. */ + 1MB, allowing +/-3.9GB for the offset to the symbol. */ if ((SYMBOL_REF_WEAK (x) && !aarch64_symbol_binds_local_p (x)) - || !IN_RANGE (offset, HOST_WIDE_INT_C (-4294967263), - HOST_WIDE_INT_C (4294967264))) + || !IN_RANGE (offset, -0x100000, 0x100000)) return SYMBOL_FORCE_TO_MEM; + return SYMBOL_SMALL_ABSOLUTE; =20 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 } */ /* { dg-options "-O3 -save-temps -mcmodel=3Dtiny" } */ =20 -int fixed_regs[0x00200000]; +char fixed_regs[0x00200000]; =20 int -foo() +main () { - return fixed_regs[0x00080000]; + return fixed_regs[0x000ff000]; } =20 /* { 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 } */ /* { dg-options "-O3 -save-temps -mcmodel=3Dsmall" } */ =20 -int fixed_regs[0x200000000ULL]; +char fixed_regs[0x200000000ULL]; =20 int -foo() +main () { - return fixed_regs[0x100000000ULL]; + return fixed_regs[0xfffff000ULL]; } =20 /* { dg-final { scan-assembler-not "adrp\tx\[0-9\]+, fixed_regs\\\+" } } */