public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Issues with the dot '.' symbol and the .fill directive
@ 2007-03-15 21:53 Dave Rager
  2007-03-16  5:20 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Rager @ 2007-03-15 21:53 UTC (permalink / raw)
  To: binutils

Forgive my noob-ish-ness. I'm not sure if I'm not understanding
something correctly or if I've stumbled on a genuine bug. What I
thought I understood and which worked with 2.15 seems to now be broken
on 2.16 and 2.17.

Here is some sample code that demonstrates the problem on each machine
I've tried so far.

.fill 4,1,0xff
.long .            # outputs a 4
#.fill 32 - 8,1,0  # works on all
#.fill 32 - .,1,0   # works on 2.15, does not work on 2.16 or 2.17
#.space 32 - .      # works on 2.15, does not work on 2.16 or 2.17
#. = . + 32 - .     # silly thing to do but works on 2.17

The goal is to fill the remaining bytes after the code with 0s in a
flat binary using the .fill directive. As I've understood from the
docs, .fill 32 - ., 1, 0 will write (32 - .) or 24 1-byte 0s.

Using any one of the commented lines works as expected with 2.15.

00000000  FF FF FF FF 04 00 00 00 00 00 00 00 00 00 00 00 ................
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

Compiling on 2.16 or 2.17  with line 4 uncommented produces the following error:

test.s: Assembler messages:
test.s:4: Error: .space specifies non-absolute value

gdb shows the first part of the conditional on line 2009 of write.c to
be the culprit:

(S_GET_SEGMENT (symbolP) != absolute_section) evaluates to true.

Since this section of code hasn't changed between 2.15 and 2.17, I've
been digging around to find where this value is set and where it may
be modified. So far I haven't found anything out of the ordinary but
then I'm not completely familiar with this code.

Interestingly, in both 2.15 and 2.17 the call to S_GET_VALUE (symbolP)
just before the conditional returns the expected value of 24.

So, is this a bug (smells like it :-) or expected behavior? Let me
know if I'm missing something... or if I'm just off my rocker!

Thanks,
Dave.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Issues with the dot '.' symbol and the .fill directive
  2007-03-15 21:53 Issues with the dot '.' symbol and the .fill directive Dave Rager
@ 2007-03-16  5:20 ` Alan Modra
  2007-03-16 14:19   ` Dave Rager
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2007-03-16  5:20 UTC (permalink / raw)
  To: Dave Rager; +Cc: binutils

On Thu, Mar 15, 2007 at 05:53:34PM -0400, Dave Rager wrote:
> .fill 4,1,0xff
> .long .            # outputs a 4

Not exactly.  It outputs a relocation too, <section start> + 4.
If you understand that, you'll see why the assembler is complaining
about "32 - ." not being absolute.  "." is relative to the section
start, so any expression involving "." can't be absolute unless you
substract off another section relative value.

> #.fill 32 - 8,1,0  # works on all
> #.fill 32 - .,1,0   # works on 2.15, does not work on 2.16 or 2.17

Newer assemblers have better error checking.  Rewrite your code as

a:
 .fill 4,1,0xff
 .long .
 .fill 32 - (. - a)

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Issues with the dot '.' symbol and the .fill directive
  2007-03-16  5:20 ` Alan Modra
@ 2007-03-16 14:19   ` Dave Rager
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Rager @ 2007-03-16 14:19 UTC (permalink / raw)
  To: binutils

On 3/16/07, Alan Modra <amodra@bigpond.net.au> wrote:
> On Thu, Mar 15, 2007 at 05:53:34PM -0400, Dave Rager wrote:
> > .fill 4,1,0xff
> > .long .            # outputs a 4
>
> Not exactly.  It outputs a relocation too, <section start> + 4.
> If you understand that, you'll see why the assembler is complaining
> about "32 - ." not being absolute.  "." is relative to the section
> start, so any expression involving "." can't be absolute unless you
> substract off another section relative value.
>
> > #.fill 32 - 8,1,0  # works on all
> > #.fill 32 - .,1,0   # works on 2.15, does not work on 2.16 or 2.17
>
> Newer assemblers have better error checking.  Rewrite your code as
>
> a:
>  .fill 4,1,0xff
>  .long .
>  .fill 32 - (. - a)
>
> --
> Alan Modra
> IBM OzLabs - Linux Technology Centre
>

Alan, Thanks. That makes sense. Probably explains why I didn't find
anything wrong with the code. :-)

Thanks again for the help!
Dave.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-03-16 14:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-15 21:53 Issues with the dot '.' symbol and the .fill directive Dave Rager
2007-03-16  5:20 ` Alan Modra
2007-03-16 14:19   ` Dave Rager

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).