From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7050 invoked by alias); 23 Apr 2015 23:15:29 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 7036 invoked by uid 89); 23 Apr 2015 23:15:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f180.google.com Received: from mail-pd0-f180.google.com (HELO mail-pd0-f180.google.com) (209.85.192.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 23 Apr 2015 23:15:28 +0000 Received: by pdbqa5 with SMTP id qa5so31180741pdb.1 for ; Thu, 23 Apr 2015 16:15:26 -0700 (PDT) X-Received: by 10.70.128.110 with SMTP id nn14mr9575413pdb.135.1429830926420; Thu, 23 Apr 2015 16:15:26 -0700 (PDT) Received: from bubble.grove.modra.org (CPE-58-160-155-134.oycza5.sa.bigpond.net.au. [58.160.155.134]) by mx.google.com with ESMTPSA id hb6sm9066389pbd.88.2015.04.23.16.15.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 16:15:25 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 03B3EEA017E; Fri, 24 Apr 2015 08:45:20 +0930 (ACST) Date: Thu, 23 Apr 2015 23:15:00 -0000 From: Alan Modra To: Jeff Prothero Cc: binutils@sourceware.org Subject: Re: Gas bug: Broken code generated for inter-section arithmetic. Message-ID: <20150423231520.GR12627@bubble.grove.modra.org> Mail-Followup-To: Jeff Prothero , binutils@sourceware.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00368.txt.bz2 On Thu, Apr 23, 2015 at 10:49:56AM -0700, Jeff Prothero wrote: > Assembly code like (Nios2 example): > > .section version_header,"a" > anchor: > .4byte HelloWorld-ANCHOR > .section version_header_strings,"a" > .asciz "aaaaaaaa" > HelloWorld: > > currently silently produces bad code. [snip] > This catches all forbidden inter-section arithmetic expressions which > are assigned to symbols. > > Unfortunately, not all expressions are assigned to symbols. Common > constructs (here quoting tc-nios2.c, but arm etc are similar) like Right, and this is as it should be. [snip] > First, this problem is really cross-platform and should be fixed in > platform-independent code. Nope. In your example you have a special case of an expression that can actually be resolved (well, modulo fixing the case mismatch, anchor!=ANCHOR) since the subtrahend is in the current section. On targets that support a 32-bit pc-relative relocation you should see one of those relocations emitted against HelloWorld (or the section symbol). For instance on powerpc after fixing the case mismatch, I get $ binutils/objdump -sr forward.o forward.o: file format elf32-powerpc RELOCATION RECORDS FOR [version_header]: OFFSET TYPE VALUE 00000000 R_PPC_REL32 version_header_strings+0x00000009 Contents of section version_header: 0000 00000000 .... Contents of section version_header_strings: 0000 61616161 61616161 00 aaaaaaaa. If your target doesn't support the required relocation, the target code must handle the error. -- Alan Modra Australia Development Lab, IBM