ARM gas ld question
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
ARM gas ld question

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> Embedded System
Author Message
Guest






Posted: Wed Jan 12, 2005 1:39 pm    Post subject: ARM gas ld question Reply with quote

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
Back to top
Tauno Voipio
Guest





Posted: Wed Jan 12, 2005 3:28 pm    Post subject: Re: ARM gas ld question Reply with quote

nospam3658@lycos.com wrote:
Quote:
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

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

--

Tauno Voipio
tauno voipio (at) iki fi
Back to top
Guest






Posted: Wed Jan 12, 2005 6:04 pm    Post subject: Re: ARM gas ld question Reply with quote

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.
Back to top
Tauno Voipio
Guest





Posted: Thu Jan 13, 2005 12:54 am    Post subject: Re: ARM gas ld question Reply with quote

nospam3658@lycos.com wrote:
Quote:
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.


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
Back to top
Guest






Posted: Thu Jan 13, 2005 2:42 pm    Post subject: Re: ARM gas ld question Reply with quote

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
Back to top
42Bastian Schick
Guest





Posted: Fri Jan 14, 2005 1:19 pm    Post subject: Re: ARM gas ld question Reply with quote

On 13 Jan 2005 01:42:41 -0800, nospam3658@lycos.com wrote:

Quote:
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.

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
Do not email to bastian42@yahoo.com, it's a spam-only account :-)
Use <same-name>@epost.de instead !
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> Embedded System All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB