------- Comment #14 from ubizjak at gmail dot com  2009-03-01 20:13 -------
(In reply to comment #5)
> Uros, looking at this again, after manually changing
>   leal    $_48(,%eax,4), %eax
> to
>   leal    _48(,%eax,4), %eax
> things build again with the label being defined as
>         .type   $_48, @object
>         .size   $_48, 12
>   $_48:
> and used like
>   cmpl    $$_48+12, %eax
> without problems.
> 
> Do you believe this is a bug for leal in the older version of binutils
> (2.15) FreeBSD ships?  I am surprised that it works when I remove the $.

It works only because "_48" will create a relocation to an external object. You
can see this by using 'objdump -dr init-list.o", where init-list.o is created
with "gcc -O2 -m32 -c -std=gnu++0x"

When this part is assembled (on linux!):

        ja      .L306
        leal    ._48(,%eax,4), %eax
        movl    %eax, 44(%esp)
        subl    $._48, %eax
        sarl    $2, %eax

An offset to an object in .data section is calculated at assembly time, so you
will get:

...
 579:   0f 87 01 02 00 00       ja     780 <main+0x780>
 57f:   8d 04 85 18 00 00 00    lea    0x18(,%eax,4),%eax
                        582: R_386_32   .data
 586:   89 44 24 2c             mov    %eax,0x2c(%esp)
 58a:   2d 18 00 00 00          sub    $0x18,%eax
                        58b: R_386_32   .data
 58f:   c1 f8 02                sar    $0x2,%eax
...

while removing "." (equivalent to removing "$" on BSD) from the lea operand
leaves an relocation to external symbol:

...
 579:   0f 87 01 02 00 00       ja     780 <main+0x780>
 57f:   8d 04 85 00 00 00 00    lea    0x0(,%eax,4),%eax
                        582: R_386_32   _48
 586:   89 44 24 2c             mov    %eax,0x2c(%esp)
 58a:   2d 18 00 00 00          sub    $0x18,%eax
                        58b: R_386_32   .data
 58f:   c1 f8 02                sar    $0x2,%eax

I found much more interesting the fact, that both:

        subl    ._48, %eax
and
        subl    $._48, %eax

produce the same result, while changing:

        leal    ._48(,%eax,4), %eax
to
        leal    $._48(,%eax,4), %eax

produces:

init-list.s: Assembler messages:
init-list.s:2664: Error: junk `(,%eax,4)' after expression
init-list.s:2664: Error: suffix or operands invalid for `lea'

I think that H.J. can explain the reason for this inconsistency in the
assembler.


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hjl dot tools at gmail dot
                   |                            |com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37520

Reply via email to