From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47500 invoked by alias); 24 Feb 2020 11:43:50 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 47417 invoked by uid 89); 24 Feb 2020 11:43:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.5 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=strictly X-HELO: esa2.mentor.iphmx.com Received: from esa2.mentor.iphmx.com (HELO esa2.mentor.iphmx.com) (68.232.141.98) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Feb 2020 11:43:48 +0000 IronPort-SDR: LHN/1f7C2+LNall78ItKXL40a+4chytba6aYMR2j4G+oGBR0mjbDcF7X0CWENzS53ZfZ6EtTDH 2XNvETstBXj7LO8dDtpDq2Y4GzdcC+owtMNyN7VV5hT2JzxtUkmvZceedBMcLnjiK9sIbw+CXj PT/uFe58Ll97+cuo9z3EpilbY392NHeqNyt/Ha25U5xuU2WP3vGcjX16D6TbDXdaE864+0H2d1 hfL3MAX5FIofNrPKWNshK1wNMfA2hI8gWyvC4fT9X0wUXdn3Kvq0DSDCjcRpItxVMtij/eVIFs M9c= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 24 Feb 2020 03:43:46 -0800 IronPort-SDR: nz8JoUoxyTgwXDdZgXyOXkKpxI0AZDMvloX9T4y3hBt678Wn8tTtfs1R2Tw/JC9w98/lcRuR4U bUYkrRTBlZR3+zBMo2O/p8WR9STilN5uBsdGrcSDS3D/VMH5EMmW3UoIcZRTPCfz9xnAaO6R1g tHOKHGNfl0eO1GprMjYWvlcrUYNh17PirBqVQMu7UyaCmNVB7fxVrobaFcCbsZZpyrR2BDroJp nT9r8rBTtp6ENrxtATzW3DB/sx8xFasr/9BQDnPyy82+K+EZFsZ7TbCaDbQUVOqhUBi1PBj6O5 Cjs= Subject: Re: Branch instructions that depend on target distance To: Petr Tesarik , References: <20200224120528.0a88c6a8@ezekiel.suse.cz> From: Andrew Stubbs Message-ID: <83530a03-1cbe-90ce-d363-eeeaa906d125@codesourcery.com> Date: Mon, 24 Feb 2020 11:43:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200224120528.0a88c6a8@ezekiel.suse.cz> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Return-Path: ams@codesourcery.com X-SW-Source: 2020-02/txt/msg00184.txt.bz2 On 24/02/2020 11:05, Petr Tesarik wrote: > Hi all, > > I'm looking into reviving the efforts to port gcc to VideoCore IV [1]. > One issue I've run into is the need to find out target branch distance > at compile time. I looked around, and it's not the first one > architecture with such requirement, but AFAICS it has never been solved > properly. > > For example, AVR tracks instruction length. Later, ret_cond_branch() > selects between a branch instruction and an inverted branch followed by > an unconditional jump based on these calculated lengths. > > This works great ... until there's some inline asm() statement, for > which gcc cannot keep track of the length attribute, so it is probably > taken as zero. Linker then fails with a cryptic message: > >> relocation truncated to fit: R_AVR_7_PCREL against `no symbol' You can probably fix this by implementing the ADJUST_INSN_LENGTH macro and recognising the inline assembler. See the internals manual. We encountered similar issues with the recent GCN port, and the correct solution was to add the length attribute everywhere. The attributes are often conservative estimates (rather than having extra alternatives for every possible encoding), so the asm problem is mitigated somewhat, at the cost of a few "far" branches where they're not strictly necessary. There were also addition problems because "far" branches clobber the condition register, and "near" branches do not, but that's another story. Andrew