From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21749 invoked by alias); 20 Apr 2006 10:53:19 -0000 Received: (qmail 21740 invoked by uid 22791); 20 Apr 2006 10:53:19 -0000 X-Spam-Check-By: sourceware.org Received: from cam-admin0.cambridge.arm.com (HELO cam-admin0.cambridge.arm.com) (193.131.176.58) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 20 Apr 2006 10:53:16 +0000 Received: from cam-owa1.Emea.Arm.com (cam-owa1.emea.arm.com [10.1.255.62]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id k3KAr0uc008591; Thu, 20 Apr 2006 11:53:00 +0100 (BST) Received: from pc960.cambridge.arm.com ([10.1.255.211]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0); Thu, 20 Apr 2006 11:53:00 +0100 Subject: Re: plt for arm gnu thumb From: Richard Earnshaw To: johnmc@sidsa.es Cc: binutils@sources.redhat.com In-Reply-To: <1322.195.53.86.158.1145523785.squirrel@webmail> References: <4385.195.53.86.158.1145361498.squirrel@webmail> <1145373227.14054.16.camel@pc960.cambridge.arm.com> <20060418154515.GA13751@nevyn.them.org> <1145375346.14054.20.camel@pc960.cambridge.arm.com> <20060418160255.GA15072@nevyn.them.org> <4596.195.53.86.158.1145376723.squirrel@webmail> <20060418203900.GA23304@nevyn.them.org> <1178.195.53.86.158.1145458815.squirrel@webmail> <20060419150716.GA13655@nevyn.them.org> <1322.195.53.86.158.1145523785.squirrel@webmail> Content-Type: text/plain Message-Id: <1145530371.16122.30.camel@pc960.cambridge.arm.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Thu, 20 Apr 2006 14:38:00 -0000 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00279.txt.bz2 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 : 524: 4652 mov r2, sl ... 00000548 : 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.