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.

ARM gas ld question

Discussion in 'Embedded' started by Guest, Jan 12, 2005.

  1. Guest

    Guest Guest

    Hi,

    I am using the GNU tools ld and gas to assemble a program which is
    contained in two files. I am using the thumb instruction set. I use
    the following flags when assembling: -mcpu=arm7tdmi -mthumb -EL

    My problem is when trying to jump from one function to another that is
    contained in the other file. If I do this:

    ld r0,=func_name
    mov pc,r0

    then everything works as expected. However, if I do

    b func_name

    it doesn't work. I have dissassembled the final linked code using
    objdump to see what is happening, and the branch address doesn't make
    sense. While investigating the problem I changed the branch to a
    function in the same file, and the dissasembly then looks OK, and the
    program works. The problem is only when I branch to a function in the
    other file.

    It looks like the symbol func_name is being found - I have specified
    it as global in my second file, and the linker doesn't complain that
    it can't find a reference. In addition, the first method above works,
    so this proves that the symbol is being found.

    Is this weird behaviour, or am I doing something wrong?

    I don't write a lot of assembler so maybe this is the problem!

    thx
     
    Guest, Jan 12, 2005
    #1
    1. Advertisements

  2. Guest

    Tauno Voipio Guest

    Strip the problem to minimal sources showing the effect,
    post the sources, link map and objdump result.
     
    Tauno Voipio, Jan 12, 2005
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    OK, I'll shrink the sources and post. One other bit of information is
    that the branch instructions do work for the ARM instruction set, just
    not for the thumb. i.e. replacing code 16 with code 32 in the
    assembler sources, and removing the -thumb when assembling with gas.
     
    Guest, Jan 12, 2005
    #3
  4. Guest

    Tauno Voipio Guest

    Maybe you're missing .thumb_func from the targets.

    For an example, see the code generated by ARM GCC with
    -mthumb -S.
     
    Tauno Voipio, Jan 12, 2005
    #4
  5. Guest

    Guest Guest

    Thanks for the response.

    I did not have the .thumb_func directives in my sources. I have just
    put them in, now if I use 'bl' instructions, then the dissassembly
    shows correct branch addresses. However, 'b' instructions still behave
    as before. As it happens I can use 'bl' to get my code working for now
    so at least I can get on with what I'm doing - thanks for the tip
    Tauno.

    It would be nice to know how to get the 'b' instruction working, I
    guess there is another directive missing. I have done a google search
    looking for an example of using the thumb instruction set with GNU
    tools but haven't found anything - that's what I could really do with.

    I have looked at the output of gcc and have tried the '.type
    function_name,function' directive, but this doesn't sort the branch
    problem. This directive is not needed for the 'bl' instruction. All
    that was required here was the .thumb_func directive just before the
    label of the function being branched to.

    Thx
     
    Guest, Jan 13, 2005
    #5
  6. Note: bl and b have different possible branch distances in Thumb.
    Maybe the branch and the destination are too far from each other ?
    (The linker should report an error, but maybe there is a bug !?)
     
    42Bastian Schick, Jan 14, 2005
    #6
    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.