[ACTIVITY] Week 07

2012-02-19 Thread Zhenqiang Chen
Summary:
  * crosstool-ng patches for linaro 2012.02 binary toolchain release

Details:
  1. Revise the gdb lsb build patches based on gdb-7.4.
  2. Clean up old patches and only keep the latest version, since we
only keep the latest version in config for linaro.
  3. Window installer patch.
* Scripts to use installjammer to create the win32 install package.
* Apply linaro logo to the install package.
* Sync up the install directory and Start-menu layout with
embedded toolchain.
* Test the package on win7.

Plans:
  * Finalize 2012.02 binary toolchain release.

Best regards!
-Zhenqiang

___
linaro-toolchain mailing list
linaro-toolchain@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-toolchain


Re: gcc: Thumb interworking and weakly linked functions

2012-02-19 Thread V, Aneesh
+  linaro-toolchain

Hello Ulrich,

I want to revisit this old thread. Sorry for the sloppy follow-up. But,
this time around I have more data.

On Tue, Mar 15, 2011 at 9:00 PM, Ulrich Weigand
 wrote:
> Aneesh V  wrote:
>
>> I was trying to build u-boot in Thumb2 for OMAP4. Everything was fine
>> until I added some patches recently. One of these patches introduced an
>> API (let's say foo()) that has a weakly linked alias(let's say
>> __foo()) and a strongly linked implementation(the real foo()) in an
>> assembly file.
>>
>> Although I give -mthumb and -mthumb-interwork for all the files,
>> apparently GCC generates ARM code for assembly files. In the final
>> image foobar() calls foo() using a BL. Since foobar() is in Thumb and
>> foo() in ARM, it ends up crashing. Looks like foobar() assumed foo()
>> to be Thumb because __foo() is Thumb.
>
> I'm unable to reproduce this.  Do you have a complete test case?
>
> I've tried with the following small example:
>
> foo1.c:
>
> extern void foo (void) __attribute__ ((weak, alias ("__foo")));
>
> void __foo (void)
> {
> }
>
> int main (void)
> {
>  foo ();
> }
>
> foo2.S:
>        .text
>        .align  2
>        .global foo
>        .type   foo, %function
> foo:
>        push    {r7}
>        add     r7, sp, #0
>        mov     sp, r7
>        pop     {r7}
>        bx      lr
>        .size   foo, .-foo
>
> When building just "gcc foo1.c", I get:
>
> 835c <__foo>:
>    835c:       b480            push    {r7}
>    835e:       af00            add     r7, sp, #0
>    8360:       46bd            mov     sp, r7
>    8362:       bc80            pop     {r7}
>    8364:       4770            bx      lr
>    8366:       bf00            nop
>
> 8368 :
>    8368:       b580            push    {r7, lr}
>    836a:       af00            add     r7, sp, #0
>    836c:       f7ff fff6       bl      835c <__foo>
>    8370:       4618            mov     r0, r3
>    8372:       bd80            pop     {r7, pc}
>
> When building both files "gcc foo1.c foo2.S", I get instead:
>
> 8368 :
>    8368:       b580            push    {r7, lr}
>    836a:       af00            add     r7, sp, #0
>    836c:       f000 e802       blx     8374 
>    8370:       4618            mov     r0, r3
>    8372:       bd80            pop     {r7, pc}
>
> 8374 :
>    8374:       e92d0080        push    {r7}
>    8378:       e28d7000        add     r7, sp, #0
>    837c:       e1a0d007        mov     sp, r7
>    8380:       e8bd0080        pop     {r7}
>    8384:       e12fff1e        bx      lr
>
>
> So it seems to me the linker is handling this correctly ...
>
> (This is on Ubuntu Natty using system gcc and binutils.)

I could reproduce the problem on older tool-chain(Sourcery G++ Lite
2010q1-202) [1]  with a modified version of your sample code:

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, I build them using the following commands, which is similar to
what U-Boot does:

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
armobjdump -S --reloc a.out

You will get something like:
8094 :
8094:   fa06blx 80b4 
8098:   e12fff1ebx  lr

Please note that that the 'blx' is not correct. Now, do the following change:

diff --git a/b.S b/b.S
index e0f2de9..96dba1f 100644
--- a/b.S
+++ b/b.S
@@ -1,5 +1,6 @@
 .text
 .align  2
+.type foo, %function
 .global foo
 foo:
push{r7}

And build it again the same way and you will see:
8094 :
8094:   eb06bl  80b4 
8098:   e12fff1ebx  lr

I can't reproduce this on Linaro GCC 2012.01, so looks like the problem
is solved in recent tool-chains. However, sadly I could reproduce a
different but similar problem with Linaro GCC 2012.01. This time the
call is from C(Thumb) to assembly(ARM) and no weakly linked symbols are
involved.

a.c:

int main (void)
{
  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

.global __aeabi_unwind_cpp_pr0
__aeabi_unwind_cpp_pr0:
bx  lr

arm-linux-gnueabi-gcc -mthumb -mthumb-interwork -c