This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

arm/thumb: problems with function pointers


Heyho!

When I do something simple like
 == first file ==
int callee() { return 42; }
int main() {
    return caller(callee);
}
 == second file ==
int caller(int (*fn)()) {
    (fn)();
}
 == end ==

and compile this for arm with -mthumb and -fpic (without -fpic I get a
linking error 'bad reloc type 10' so I didn't investigate further), the
pointer to callee does not have its lsb set. Since thumb creates a
_call_via_rX which uses the bx instruction, callee is called in arm
state.

I first had callee in a third file so when compiling main callee would
be undefined, but having callee together with main does not make a
difference.

Tools: as always. gcc-3.0.3/binutils-2.11.2 for production, but I made a
quick experiment with cvs head (14h old) and afaict it's not been fixed
there.

I discovered the problem while trying to get a thumbified busybox. any
help would be appreciated - I suspect it's similar to the fix [1] Phil
Blundell sent me on a similar problem, but it's apparently different
enough to need a different fix. (no English teacher reading this?
good... ;-) 

My bet is that what was done to be R_ARM_ABS32 in elf32-arm.h needs to
be done to R_ARM_GOT32 relocations, too. But the R_ARM_GOT32 case is
more complex than the ABS32 one...

Hmmm, I'll probably look at it tomorrow - but I don't know nuffin about
bfd, so I'd be glad if somebody else is quicker.
 
greets from Zürich
-- vbi

[1] 'Re: Linking arm thumb code' from 23 Nov 2001 10:24:39 +0000


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]