public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Aneesh V <aneesh@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/4] arm: add %function attribute to assembly functions
Date: Sat, 18 Feb 2012 18:54:11 +0530	[thread overview]
Message-ID: <4F3FA67B.8060603@ti.com> (raw)
In-Reply-To: <4F3F79B4.5060903@aribaud.net>

Hi Albert,

On Saturday 18 February 2012 03:43 PM, Albert ARIBAUD wrote:
> Hi Aneesh,
>
> Le 17/02/2012 12:09, Aneesh V a ?crit :
>> Hi Albert,
>>
>> On Wednesday 15 February 2012 07:27 PM, Aneesh V wrote:
>>> This is done using the following directive preceding
>>> each function definition:
>>>
>>> .type<func-name>, %function
>>>
>>> This marks the symbol as a function in the object
>>> header which in turn helps the linker in some cases.
>>>
>>> In particular this was found needed for resolving ARM/Thumb
>>> calls correctly in a build with Thumb interworking enabled.
>>>
>>> This solves the following problem I had reported earlier:
>>>
>>> "When U-Boot/SPL is built using the Thumb instruction set the
>>> toolchain has a potential issue with weakly linked symbols.
>>> If a function has a weakly linked default implementation in C
>>> and a real implementation in assembly GCC is confused about the
>>> instruction set of the assembly implementation. As a result
>>> the assembly function that is built in ARM is executed as
>>> if it is Thumb. This results in a crash"
>>>
>>> Signed-off-by: Aneesh V<aneesh@ti.com>
>>
>> Does this look good to you. I was a bit nervous about touching so many
>> files. Please let me know if you would prefer to change only the OMAP
>> function that was creating the ARM/Thumb problem. I did a "MAKEALL -a
>> arm" and didn't see any new errors.
>>
>> Let me know if this is an acceptable solution to the problem.
>
> Regarding the solution: it is quite ok to me. I would just like to
> understand the exact effect of the .function directive, what its options
> are and if some of these should not be explicitly specified.
>
> Regarding touching many files: I won't be worried as long as you check
> that the first three patches have no effect on existing boards. This can
> be verified as follows -- if you haven't done so already:
>
> - build your OMAP target without the patch set and do a hex dump of
> u-boot.bin;
>
> - apply the first three patches of your set, rebuild your OMAP target
> without the patch set and do a hex dump of u-boot.bin;
>
> - compare both dumps. Normally you should only see one difference, in
> the build version and date -- if .function does not actually alter the
> assembly code, which I hope it indeed does not when building for ARM.
>
> If there are more changes than build version and date, then they might
> be due to .function requiring some yet unknown additional option, or to
> some change in patch 1 or 3 not being completely conditioned on
> CONFIG_SYS_THUMB_BUILD.

I can reproduce the problem with a simple test program.
Note: I can reproduce this with Sourcery G++ Lite 2010q1-202 (GCC 4.4.1
- Binutils 2.19.51.20090709)
But I *can not* reproduce reproduce this with Linaro GCC 2012.01 (GCC
4.6.3 , Binutils 2.22)
So apparently the issue has been fixed recently. Unfortunately Linaro
GCC 2012.01 creates a new Thumb problem that I am investigating now.
Somehow I missed this when I tested earlier. So, my Thumb build is
not working with Linaro GCC 2012.01. But this one is not reproduced on
Sourcery G++ Lite 2010q1-202!

Here is the program I used to reproduce the problem in Sourcery G++
Lite 2010q1-202 that this patch is addressing

a.c:
====
extern void foo (void) __attribute__ ((weak, alias ("__foo")));

void __foo (void)
{
}

extern void call_foo(void);

int main (void)
{
   call_foo ();
}

b.S:
====
.text
.align  2
.global foo
foo:
	push	{r7}
	add	r7, sp, #0
	mov	sp, r7
	pop	{r7}
	bx	lr
	.size	foo, .-foo


c.S:
====
.text
.align  2

.global call_foo
call_foo:
	bl	foo
	bx	lr

.global __aeabi_unwind_cpp_pr0
__aeabi_unwind_cpp_pr0:
	bx	lr

Now build it and take the assembly dump using the following commands:

arm-none-linux-gnueabi-gcc -mthumb -mthumb-interwork -c a.c
arm-none-linux-gnueabi-gcc -mthumb -mthumb-interwork -c b.S
arm-none-linux-gnueabi-gcc -mthumb -mthumb-interwork -c c.S
arm-none-linux-gnueabi-ld -r a.o -o alib.o
arm-none-linux-gnueabi-ld -r b.o -o blib.o
arm-none-linux-gnueabi-ld -r c.o -o clib.o
arm-none-linux-gnueabi-ld --start-group clib.o  alib.o blib.o 
--end-group -o a.out
arm-none-linux-gnueabi-objdump -S --reloc a.out

You will get something like this in the assembly dump:
00008094 <call_foo>:
     8094:	fa000006 	blx	80b4 <foo>
     8098:	e12fff1e 	bx	lr

The blx is wrong as we are jumping to an ARM function from ARM.

Now if you change b.S like this:

  .text
  .align  2
+.type foo, %function
  .global foo
  foo:
  	push	{r7}


And compile it again in the same way you will see:
00008094 <call_foo>:
     8094:	eb000006 	bl	80b4 <foo>
     8098:	e12fff1e 	bx	lr

Please note that the branch to foo is correct now.

I hope this convinces you that %function indeed has an effect.

I will get back with more details on the Linaro GCC 2012.01 later.

br,
Aneesh

  reply	other threads:[~2012-02-18 13:24 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-06 11:37 [U-Boot] [RFC PATCH 0/4] Enable Thumb build for ARM platforms Aneesh V
2012-02-06 11:37 ` [U-Boot] [RFC PATCH 1/4] ARM: enable Thumb build Aneesh V
2012-02-06 18:45   ` Tom Rini
2012-02-07  7:43     ` Aneesh V
2012-02-06 11:37 ` [U-Boot] [RFC PATCH 2/4] OMAP3+: fix issues with " Aneesh V
2012-02-06 21:06   ` Albert ARIBAUD
2012-02-07  7:49     ` Aneesh V
2012-02-09  8:58     ` Aneesh V
2012-02-06 11:37 ` [U-Boot] [RFC PATCH 3/4] OMAP3+: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-02-06 11:37 ` [U-Boot] [RFC PATCH 4/4] OMAP4: enable Thumb build Aneesh V
2012-02-06 12:26 ` [U-Boot] [RFC PATCH 0/4] Enable Thumb build for ARM platforms Aneesh V
2012-02-06 13:22   ` Aneesh V
2012-02-15 13:57 ` [U-Boot] [PATCH " Aneesh V
2012-02-15 13:57 ` [U-Boot] [PATCH 1/4] ARM: enable Thumb build Aneesh V
2012-02-15 13:57 ` [U-Boot] [PATCH 2/4] arm: add %function attribute to assembly functions Aneesh V
2012-02-17 11:09   ` Aneesh V
2012-02-18 10:13     ` Albert ARIBAUD
2012-02-18 13:24       ` Aneesh V [this message]
2012-02-18 15:04         ` Albert ARIBAUD
2012-02-18 16:34         ` Aneesh V
2012-02-18 16:48           ` Albert ARIBAUD
2012-02-20 16:08             ` Aneesh V
2012-02-23 11:06               ` Aneesh V
2012-02-17 17:13   ` Mike Frysinger
2012-02-18 11:12     ` Aneesh V
2012-02-18 11:34       ` Albert ARIBAUD
2012-02-18 22:03   ` Simon Glass
2012-02-19  7:15     ` Mike Frysinger
2012-02-20 20:07       ` Tom Rini
2012-02-20 21:53         ` Simon Glass
2012-02-21  4:19           ` Mike Frysinger
2012-02-21  4:44             ` Simon Glass
2012-02-21 14:33             ` Tom Rini
2012-02-21 15:42               ` Mike Frysinger
2012-02-21 18:03                 ` Aneesh V
2012-02-21 19:28                   ` Mike Frysinger
2012-02-21 20:01                     ` Aneesh V
2012-02-21  4:18         ` Mike Frysinger
2012-02-15 13:57 ` [U-Boot] [PATCH 3/4] armv7: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-02-15 13:57 ` [U-Boot] [PATCH 4/4] OMAP4: enable Thumb build Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 1/5] arm: adapt asm/linkage.h from Linux Aneesh V
2012-02-23 14:01   ` Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 2/5] armv7: add appropriate headers for assembly functions Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 3/5] ARM: enable Thumb build Aneesh V
2012-02-23 14:57   ` Mike Frysinger
2012-02-23 17:28     ` Aneesh V
2012-02-23 17:34       ` Tom Rini
2012-02-23 17:49         ` Aneesh V
2012-02-23 17:51           ` Tom Rini
2012-02-23 18:09             ` Aneesh V
2012-02-23 18:13               ` Aneesh V
2012-02-23 18:05           ` Mike Frysinger
2012-02-23 18:04       ` Mike Frysinger
2012-02-23 18:12         ` Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 4/5] armv7: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-02-23 13:39 ` [U-Boot] [PATCH v2 5/5] OMAP4: enable Thumb build Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 1/6] arm: adapt asm/linkage.h from Linux Aneesh V
2012-02-23 14:59   ` Mike Frysinger
2012-02-23 15:24     ` Tom Rini
2012-02-23 16:57       ` Mike Frysinger
2012-02-23 17:40     ` Aneesh V
2012-02-23 23:52       ` Mike Frysinger
2012-02-24 10:30         ` Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 2/6] armv7: add appropriate headers for assembly functions Aneesh V
2012-02-23 14:59   ` Mike Frysinger
2012-02-23 14:06 ` [U-Boot] [PATCH v3 3/6] ARM: enable Thumb build Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 4/6] armv7: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-02-23 15:05   ` Mike Frysinger
2012-02-23 17:50     ` Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 5/6] omap4+: Avoid using __attribute__ ((__packed__)) Aneesh V
2012-02-23 14:21   ` Tom Rini
2012-02-23 14:56     ` Aneesh V
2012-02-23 15:03       ` Mike Frysinger
2012-02-23 15:03     ` Mike Frysinger
2012-02-23 15:42       ` Aneesh V
2012-02-23 14:06 ` [U-Boot] [PATCH v3 6/6] OMAP4: enable Thumb build Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 1/6] arm: adapt asm/linkage.h from Linux Aneesh V
2012-03-08 17:14   ` Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 2/6] armv7: add appropriate headers for assembly functions Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 3/6] ARM: enable Thumb build Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 4/6] armv7: Use -march=armv7-a and thereby enable Thumb-2 Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 5/6] omap4+: Avoid using __attribute__ ((__packed__)) Aneesh V
2012-03-08 17:10 ` [U-Boot] [PATCH 6/6] OMAP4: enable Thumb build Aneesh V

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=4F3FA67B.8060603@ti.com \
    --to=aneesh@ti.com \
    --cc=u-boot@lists.denx.de \
    /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