This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Gas bug: Broken code generated for inter-section arithmetic.
- From: Alan Modra <amodra at gmail dot com>
- To: Jeff Prothero <jprother at altera dot com>
- Cc: binutils at sourceware dot org
- Date: Fri, 24 Apr 2015 08:45:20 +0930
- Subject: Re: Gas bug: Broken code generated for inter-section arithmetic.
- Authentication-results: sourceware.org; auth=none
- References: <pdftww6u43f dot fsf at sj-interactive3 dot altera dot com>
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