This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Gas bug: Broken code generated for inter-section arithmetic.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]