public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Richard Earnshaw <rearnsha@arm.com>
To: johnmc@sidsa.es
Cc: binutils@sources.redhat.com
Subject: Re: plt for arm gnu thumb
Date: Thu, 20 Apr 2006 14:38:00 -0000	[thread overview]
Message-ID: <1145530371.16122.30.camel@pc960.cambridge.arm.com> (raw)
In-Reply-To: <1322.195.53.86.158.1145523785.squirrel@webmail>

On Thu, 2006-04-20 at 10:03, johnmc@sidsa.es wrote:
> > On Wed, Apr 19, 2006 at 05:00:15PM +0200, johnmc@sidsa.es wrote:
> >> Hi Daniel
> >
> > Please, if you have further questions, send them to the list and not to
> > me personally.  That's more useful for everyone.
> >
> > Also, if you want help, I recommend more precise reports: command lines
> > used, test cases, objdump output for what appears to be wrong.
> >
> > --
> > Daniel Jacobowitz
> > CodeSourcery
> >
> 
> hello
> 
> A couple of days ago I found out that the "procedure linkage table" - plt
> produced  when transitioning
> on an ARM V4t chip does not function.
> So the suggestion was that I design my code so that the transition from
> the plt is to an ARM compiled
> function that then can call a THUMB compiled function.
> 
> I have been trying to do this and it does not seem to work either - or
> maybe I am not doing it properly as
> I have no previous experience using interworking.
> 
> In order to test this I have built a small test shared library .
> Here are the commands I used to build this SHARED LIBRARY.
> 
> The 2 modules used are
> dyn_load_module.c  - THUMB
> dynamic_arm.c      - ARM
> 

You'll need to construct something like the following:

Your main application code:
int func_real(void) __attribute__((visibility("hidden")));
int x;

int func_real(void)
{
    return x + 1;
}

Compile that with -mthumb -mthumb-interwork etc.

Then the wrapper file:

int func_real(void) __attribute__((visibility("hidden")));

int func(void)
{
    return func_real();
}

Compile that with (at least) -O2 -mthumb-interwork (but not thumb).

Now, when you build your shared library, you'll get:

00000524 <func_real>:
 524:   4652            mov     r2, sl
 ...

00000548 <func>:
 548:   eaffffff        b       54c <__func_real_from_arm>

0000054c <__func_real_from_arm>:
 54c:   e59fc004        ldr     ip, [pc, #4]    ; 558 <__func_real_from_arm+0xc>
 550:   e08cc00f        add     ip, ip, pc
 554:   e12fff1c        bx      ip
 558:   ffffffcd        undefined instruction 0xffffffcd

You'll note that the linker has inserted a suitable trampoline sequence
to get from ARM to thumb state when there is a branch instruction.  You
could hand-optimize this if you wanted to write some assembly code
yourself, for example:

	.text
	.align	2
	.global	func
	.type	func, %function
func:
	ldr	ip, [pc, #4]
1:	add	ip, ip, pc
	bx	ip
	.word	func_real - . - (1b + 8 - .)
	.size	func, .-func

(you could write this as a macro and then generate stubs for each
routine you need to export).

Unfortunately, there appears to be a bug in the handling of the
R_ARM_REL32 relocation in the linker that means that the sequence above
doesn't work as intended (the bottom bit in the relocated value is not
correctly set to create a suitable Thumb-ISA target).  You can work
around this by coding your trampoline as

func:
	ldr	ip, [pc, #4]
1:	add	ip, ip, pc
	orr	ip, ip, #1
	bx	ip
	.word	func_real - . - (1b + 8 - .)


R.

  reply	other threads:[~2006-04-20 10:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-18 13:06 johnmc
2006-04-18 13:10 ` Daniel Jacobowitz
2006-04-18 15:14   ` johnmc
2006-04-18 15:45 ` Richard Earnshaw
2006-04-18 15:49   ` Daniel Jacobowitz
2006-04-18 16:01     ` Richard Earnshaw
2006-04-18 16:49       ` Daniel Jacobowitz
     [not found]         ` <4596.195.53.86.158.1145376723.squirrel@webmail>
     [not found]           ` <20060418203900.GA23304@nevyn.them.org>
     [not found]             ` <1178.195.53.86.158.1145458815.squirrel@webmail>
     [not found]               ` <20060419150716.GA13655@nevyn.them.org>
2006-04-20 14:32                 ` johnmc
2006-04-20 14:38                   ` Richard Earnshaw [this message]
     [not found]                     ` <1507.195.53.86.158.1145536917.squirrel@webmail>
     [not found]                       ` <1145538390.16122.39.camel@pc960.cambridge.arm.com>
     [not found]                         ` <1576.195.53.86.158.1145540607.squirrel@webmail>
     [not found]                           ` <1145541382.16122.62.camel@pc960.cambridge.arm.com>
2006-04-24 18:23                             ` johnmc
2006-04-25 17:19                               ` Nick Clifton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1145530371.16122.30.camel@pc960.cambridge.arm.com \
    --to=rearnsha@arm.com \
    --cc=binutils@sources.redhat.com \
    --cc=johnmc@sidsa.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).