ARM gas ld question

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View

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!


Re: ARM gas ld question
Quoted text here. Click to load it

Strip the problem to minimal sources showing the effect,
post the sources, link map and objdump result.


Tauno Voipio
tauno voipio (at) iki fi

Re: ARM gas ld question
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.

Re: ARM gas ld question
Quoted text here. Click to load it

Maybe you're missing .thumb_func from the targets.

For an example, see the code generated by ARM GCC with
  -mthumb -S.


Tauno Voipio
tauno voipio (at) iki fi

Re: ARM gas ld question
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

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.


Re: ARM gas ld question

Quoted text here. Click to load it

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 !?)

Do not email to, it's a spam-only account :-)
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline