1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Jump addresses messed up with GNU as

Discussion in 'Embedded' started by Sebastien, Jul 26, 2005.

  1. Sebastien

    Sebastien Guest

    Hello,

    I'm trying to assemble the following program (ARM architecture) :

    ..text
    nop
    1:
    nop
    nop
    nop
    bal 1b

    GNU as produces the following code (read back with objdump -d) :
    Disassembly of section .text:

    00000000 <.text>:
    0: e1a00000 nop (mov r0,r0)
    4: e1a00000 nop (mov r0,r0)
    8: e1a00000 nop (mov r0,r0)
    c: e1a00000 nop (mov r0,r0)
    10: eaffffff b 14 <.text+0x14>

    As you can see, the address for the jump is outside the program :(
    I assemble with the following command :
    arm-elf-as -mcpu=arm7tdmi -o myprog.o myprog.s

    The problem's exactly the same when not using a local label.
    Any ideas ?
    Thanks,
    Sebastien
     
    Sebastien, Jul 26, 2005
    #1
    1. Advertisements

  2. Sebastien

    Tauno Voipio Guest

    I just wonder:

    Which version is your objdump?

    Mine produced the following output:

    temp$ arm-elf-objdump -D xyz.o

    xyz.o: file format elf32-littlearm

    Disassembly of section .text:

    00000000 <.text>:
    0: e1a00000 nop (mov r0,r0)
    4: e1a00000 nop (mov r0,r0)
    8: e1a00000 nop (mov r0,r0)
    c: e1a00000 nop (mov r0,r0)
    10: eaffffff b 0x4
    Disassembly of section .data:

    My assembler and other binary utilities are of version 2.14.
     
    Tauno Voipio, Jul 26, 2005
    #2
    1. Advertisements

  3. Sebastien

    Sebastien Guest

    I just wonder:
    GNU objdump 2.15 [FreeBSD] 2004-05-23

    The problem does not come from objdump, but from the assembler itself, if I
    specify the address manually, objdump produces the correct output (and my
    program works when I load it into the CPU).
    I found out that the assembler adds the current address to the label
    address... The workaround is to use "b label-." instead of "b label" ; but
    that's quite dirty.
     
    Sebastien, Jul 26, 2005
    #3
  4. Sebastien

    Sebastien Guest

    GNU objdump 2.15 [FreeBSD] 2004-05-23

    Oops, I took my native objdump (that's where the "FreeBSD" comes from). But
    my ARM objdump is 2.15 too.
     
    Sebastien, Jul 26, 2005
    #4
  5. Yes, it is. Do you use linker?

    Vadim
     
    Vadim Borshchev, Jul 27, 2005
    #5
  6. Sebastien

    Sebastien Guest

    Yes, it is. Do you use linker?

    I didn't. But I have a similar problem when using GCC (I downgraded to GCC
    3.4.3 and Binutils 2.14 to see if it was a GCC4 bug, but it is not), for
    example with the following program :

    int main(void)
    {
    int i;

    for(i=0;i<10000;i++);
    (...)

    I compile it with :

    $ arm-elf-gcc -O2 -Wall -g -mcpu=arm7tdmi main.c -c -o main.o
    $ arm-elf-gcc -O2 -Wall -g -mcpu=arm7tdmi -s -o monitor.o main.o
    $ arm-elf-objcopy -I elf32-little -O binary main.o monitor.arm

    (I tried various flags, same problem)

    Then I check the final output :

    $ arm-elf-objcopy -I binary -O elf32-littlearm monitor.arm temp.o
    $ arm-elf-objdump -marm7tdmi -D temp.o

    00000000 <_binary_monitor_arm_start>:
    0: e3a03c27 mov r3, #9984 ; 0x2700
    4: e2833010 add r3, r3, #16 ; 0x10
    8: e2533001 subs r3, r3, #1 ; 0x1
    c: 1a000000 bne 14 <_binary_monitor_arm_start+0x14>
    (...)

    The jump address is incorrect : it should be _binary_monitor_arm_start+0x08
    instead (and the code actually fails because of that when loaded in the
    CPU).

    But the intermediate object file looks correct :

    $ arm-elf-objdump -d main.o

    00000000 <main>:
    0: e3a03c27 mov r3, #9984 ; 0x2700
    4: e2833010 add r3, r3, #16 ; 0x10
    8: e2533001 subs r3, r3, #1 ; 0x1
    c: 1a000000 bne 8 <main+0x8>

    Any clue ?
     
    Sebastien, Jul 27, 2005
    #6
  7. Sebastien

    Sebastien Guest

    $ arm-elf-objcopy -I elf32-little -O binary main.o monitor.arm

    Ah, that's pretty stupid, I used main.o instead of monitor.o
    Works much better now :)
     
    Sebastien, Jul 27, 2005
    #7
  8. Do I understand you right that you are loading and executing the code from
    the object file (main.o) *before* you have it linked into executable?

    Vadim
     
    Vadim Borshchev, Jul 27, 2005
    #8
  9. No, I didn't. Semantic confusion over "-o monitor.o main.o" part.

    Vadim
     
    Vadim Borshchev, Jul 27, 2005
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.