This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ld emitting blx immdetiate for Cortex M3
Am 16.03.2012 um 13:09 schrieb Matthew Gretton-Dann:
> On Fri, Mar 16, 2012 at 08:34:46AM +0000, Benjamin Hase wrote:
>> Hi all,
>>
>> the following simple program causes the linker to emit 'blx immediate':
>>
>> #include <stdlib.h>
>>
>> int main(int argc, char **argv)
>> {
>> int x = atoi("123");
>> return x;
>> }
>>
>> compilation with
>>
>> % arm-none-eabi-gcc -o toolchain-test.elf -Wall -nostartfiles -msoft-float -mlittle-endian -Wl,-t -mthumb -mcpu=cortex-m3 -Wl,--entry=main main.c
>> /Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/bin/ld: mode armelf
>> /var/folders/6r/jwq4v3_56p19hr18dyx7wcjh0000gn/T//ccANJypP.o
>> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/thumb/libc.a)lib_a-atoi.o
>> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/thumb/libc.a)lib_a-strtol.o
>> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/thumb/libc.a)lib_a-ctype_.o
>> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/thumb/libc.a)lib_a-impure.o
>> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/thumb/libgcc.a)_udivsi3.o
>> (/Users/benjamin/sat_bleeding/bin/../lib/gcc/arm-none-eabi/4.6.3/thumb/libgcc.a)_dvmd_tls.o
>>
>> arm-none-eabi-objdump -d shows in strtol_r (which is internally called from newlib) blx instructions:
>>
>> 80a2: 1c30 adds r0, r6, #0
>> 80a4: 4651 mov r1, sl
>> 80a6: f000 e910 blx 82c8 <__aeabi_uidivmod>
>> 80aa: 1c30 adds r0, r6, #0
>> 80ac: 4689 mov r9, r1
>> 80ae: 4651 mov r1, sl
>> 80b0: f000 e88c blx 81cc <__aeabi_uidiv>
>> 80b4: 2603 movs r6, #3
>
> Take a look at __aeabi_uidivmod and __aeabi_uidiv - I think you will find
> that they are in ARM state, and so the BLX is valid.
Is it possible to recognize for which state functions are compiled? I tried objdump -x (full output below),
but I am not sure how to interpret this and if it can be seen at all…
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0000005e R_ARM_THM_CALL __aeabi_uidivmod
00000068 R_ARM_THM_CALL __aeabi_uidiv
00000160 R_ARM_ABS32 __ctype_ptr__
>
> This is because you have not set up your multilibs correctly for Cortex-M3
> and so (at a guess) you have linked v7-M code against v4-T code containing
> ARM state code. The linker will not complain about this as it views the two
> as being compatible - the linker has no idea about which core you are
> targeting your image at.
There are two questions for me:
a) it seems as if the linker tries to do the right thing, the used libraries are below thumb/,
according to the linker trace. That, of course, does not ensure the libraries itself are right…
b) If the linker is allowed to change opcodes (as it looks like in this example), shouldn't
he know about which opcodes are allowed? And this is architecture dependent IMHO.
>
> Configuring and building a suitable toolchain for this is non-trivial.
>
> The following website gives a pre-built GCC 4.6 based toolchain with Cortex-M
> libraries. It also gives instructions for how to build such a toolchain
> from scratch if the options provided are not suitable for you.
A link would have been nice :-)
Thank you,
Benjamin
full output of arm-none-eabi-objdump -x lib_a-strtol.o
lib_a-strtol.o: file format elf32-littlearm
lib_a-strtol.o
architecture: arm, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000
private flags = 5000000: [Version5 EABI]
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000184 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 000001b8 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 000001b8 2**0
ALLOC
3 .debug_info 00000a5e 00000000 00000000 000001b8 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
4 .debug_abbrev 000001bd 00000000 00000000 00000c16 2**0
CONTENTS, READONLY, DEBUGGING
5 .debug_loc 00000379 00000000 00000000 00000dd3 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_aranges 00000020 00000000 00000000 0000114c 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
7 .debug_line 00000222 00000000 00000000 0000116c 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
8 .debug_str 00000523 00000000 00000000 0000138e 2**0
CONTENTS, READONLY, DEBUGGING
9 .comment 00000012 00000000 00000000 000018b1 2**0
CONTENTS, READONLY
10 .ARM.attributes 00000032 00000000 00000000 000018c3 2**0
CONTENTS, READONLY
11 .debug_frame 00000058 00000000 00000000 000018f8 2**2
CONTENTS, RELOC, READONLY, DEBUGGING
SYMBOL TABLE:
00000000 l df *ABS* 00000000 strtol.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .debug_info 00000000 .debug_info
00000000 l d .debug_abbrev 00000000 .debug_abbrev
00000000 l d .debug_loc 00000000 .debug_loc
00000000 l d .debug_aranges 00000000 .debug_aranges
00000000 l d .debug_line 00000000 .debug_line
00000000 l d .debug_str 00000000 .debug_str
00000000 l d .debug_frame 00000000 .debug_frame
00000000 l d .comment 00000000 .comment
00000000 l d .ARM.attributes 00000000 .ARM.attributes
00000000 *UND* 00000000 __aeabi_uidivmod
00000000 *UND* 00000000 __aeabi_uidiv
00000000 g F .text 00000164 _strtol_r
00000000 *UND* 00000000 __ctype_ptr__
00000164 g F .text 00000020 strtol
00000000 *UND* 00000000 _impure_ptr
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0000005e R_ARM_THM_CALL __aeabi_uidivmod
00000068 R_ARM_THM_CALL __aeabi_uidiv
00000160 R_ARM_ABS32 __ctype_ptr__
00000174 R_ARM_THM_CALL _strtol_r
00000180 R_ARM_ABS32 _impure_ptr
RELOCATION RECORDS FOR [.debug_info]:
OFFSET TYPE VALUE
00000006 R_ARM_ABS32 .debug_abbrev
0000000c R_ARM_ABS32 .debug_str
00000011 R_ARM_ABS32 .debug_str
00000015 R_ARM_ABS32 .debug_str
00000019 R_ARM_ABS32 .text
0000001d R_ARM_ABS32 .text
00000021 R_ARM_ABS32 .debug_line
0000002f R_ARM_ABS32 .debug_str
00000036 R_ARM_ABS32 .debug_str
0000003d R_ARM_ABS32 .debug_str
00000044 R_ARM_ABS32 .debug_str
0000004b R_ARM_ABS32 .debug_str
00000052 R_ARM_ABS32 .debug_str
00000059 R_ARM_ABS32 .debug_str
0000005e R_ARM_ABS32 .debug_str
0000006b R_ARM_ABS32 .debug_str
00000070 R_ARM_ABS32 .debug_str
0000007b R_ARM_ABS32 .debug_str
0000008f R_ARM_ABS32 .debug_str
0000009a R_ARM_ABS32 .debug_str
000000be R_ARM_ABS32 .debug_str
000000cc R_ARM_ABS32 .debug_str
000000db R_ARM_ABS32 .debug_str
000000e6 R_ARM_ABS32 .debug_str
000000f3 R_ARM_ABS32 .debug_str
00000100 R_ARM_ABS32 .debug_str
00000105 R_ARM_ABS32 .debug_str
00000111 R_ARM_ABS32 .debug_str
0000012c R_ARM_ABS32 .debug_str
0000013a R_ARM_ABS32 .debug_str
00000148 R_ARM_ABS32 .debug_str
0000017a R_ARM_ABS32 .debug_str
00000186 R_ARM_ABS32 .debug_str
00000194 R_ARM_ABS32 .debug_str
000001a2 R_ARM_ABS32 .debug_str
000001b0 R_ARM_ABS32 .debug_str
000001be R_ARM_ABS32 .debug_str
000001cc R_ARM_ABS32 .debug_str
000001da R_ARM_ABS32 .debug_str
000001e8 R_ARM_ABS32 .debug_str
000001f6 R_ARM_ABS32 .debug_str
00000205 R_ARM_ABS32 .debug_str
00000212 R_ARM_ABS32 .debug_str
00000220 R_ARM_ABS32 .debug_str
0000022f R_ARM_ABS32 .debug_str
0000023e R_ARM_ABS32 .debug_str
0000025e R_ARM_ABS32 .debug_str
0000026b R_ARM_ABS32 .debug_str
00000279 R_ARM_ABS32 .debug_str
00000287 R_ARM_ABS32 .debug_str
00000295 R_ARM_ABS32 .debug_str
000002c3 R_ARM_ABS32 .debug_str
000002cf R_ARM_ABS32 .debug_str
000002dd R_ARM_ABS32 .debug_str
000002f2 R_ARM_ABS32 .debug_str
00000325 R_ARM_ABS32 .debug_str
00000333 R_ARM_ABS32 .debug_str
0000034f R_ARM_ABS32 .debug_str
0000035d R_ARM_ABS32 .debug_str
0000036b R_ARM_ABS32 .debug_str
00000379 R_ARM_ABS32 .debug_str
00000387 R_ARM_ABS32 .debug_str
00000395 R_ARM_ABS32 .debug_str
000003cd R_ARM_ABS32 .debug_str
000003db R_ARM_ABS32 .debug_str
000003f7 R_ARM_ABS32 .debug_str
00000405 R_ARM_ABS32 .debug_str
00000413 R_ARM_ABS32 .debug_str
00000421 R_ARM_ABS32 .debug_str
0000042f R_ARM_ABS32 .debug_str
0000043d R_ARM_ABS32 .debug_str
00000471 R_ARM_ABS32 .debug_str
0000047f R_ARM_ABS32 .debug_str
0000048e R_ARM_ABS32 .debug_str
0000049d R_ARM_ABS32 .debug_str
000004ac R_ARM_ABS32 .debug_str
000004bb R_ARM_ABS32 .debug_str
000004ca R_ARM_ABS32 .debug_str
000004d9 R_ARM_ABS32 .debug_str
000004e8 R_ARM_ABS32 .debug_str
000004f7 R_ARM_ABS32 .debug_str
00000506 R_ARM_ABS32 .debug_str
00000515 R_ARM_ABS32 .debug_str
00000524 R_ARM_ABS32 .debug_str
00000533 R_ARM_ABS32 .debug_str
00000542 R_ARM_ABS32 .debug_str
00000551 R_ARM_ABS32 .debug_str
00000560 R_ARM_ABS32 .debug_str
0000056f R_ARM_ABS32 .debug_str
0000057e R_ARM_ABS32 .debug_str
0000058e R_ARM_ABS32 .debug_str
0000059e R_ARM_ABS32 .debug_str
000005ae R_ARM_ABS32 .debug_str
000005be R_ARM_ABS32 .debug_str
000005d7 R_ARM_ABS32 .debug_str
00000672 R_ARM_ABS32 .debug_str
0000067e R_ARM_ABS32 .debug_str
0000068b R_ARM_ABS32 .debug_str
0000069a R_ARM_ABS32 .debug_str
000006a9 R_ARM_ABS32 .debug_str
000006c5 R_ARM_ABS32 .debug_str
000006d2 R_ARM_ABS32 .debug_str
000006e1 R_ARM_ABS32 .debug_str
000006f0 R_ARM_ABS32 .debug_str
00000719 R_ARM_ABS32 .debug_str
00000728 R_ARM_ABS32 .debug_str
00000737 R_ARM_ABS32 .debug_str
00000746 R_ARM_ABS32 .debug_str
00000755 R_ARM_ABS32 .debug_str
00000764 R_ARM_ABS32 .debug_str
00000773 R_ARM_ABS32 .debug_str
00000782 R_ARM_ABS32 .debug_str
00000791 R_ARM_ABS32 .debug_str
000007a0 R_ARM_ABS32 .debug_str
000007af R_ARM_ABS32 .debug_str
000007bf R_ARM_ABS32 .debug_str
000007cf R_ARM_ABS32 .debug_str
000007df R_ARM_ABS32 .debug_str
000007ef R_ARM_ABS32 .debug_str
000007ff R_ARM_ABS32 .debug_str
0000080f R_ARM_ABS32 .debug_str
0000081f R_ARM_ABS32 .debug_str
0000082f R_ARM_ABS32 .debug_str
00000879 R_ARM_ABS32 .debug_str
00000888 R_ARM_ABS32 .debug_str
000008c1 R_ARM_ABS32 .debug_str
000008cd R_ARM_ABS32 .debug_str
0000092b R_ARM_ABS32 .debug_str
00000936 R_ARM_ABS32 .text
0000093a R_ARM_ABS32 .text
0000093e R_ARM_ABS32 .debug_loc
00000947 R_ARM_ABS32 .debug_str
00000951 R_ARM_ABS32 .debug_loc
00000956 R_ARM_ABS32 .debug_str
00000960 R_ARM_ABS32 .debug_loc
00000965 R_ARM_ABS32 .debug_str
0000096f R_ARM_ABS32 .debug_loc
00000974 R_ARM_ABS32 .debug_str
0000097e R_ARM_ABS32 .debug_loc
0000098b R_ARM_ABS32 .debug_loc
0000099a R_ARM_ABS32 .debug_loc
000009a7 R_ARM_ABS32 .debug_loc
000009ac R_ARM_ABS32 .debug_str
000009b6 R_ARM_ABS32 .debug_loc
000009c5 R_ARM_ABS32 .debug_loc
000009d4 R_ARM_ABS32 .debug_loc
000009d9 R_ARM_ABS32 .debug_str
000009e3 R_ARM_ABS32 .debug_loc
000009fb R_ARM_ABS32 .debug_str
00000a06 R_ARM_ABS32 .text
00000a0a R_ARM_ABS32 .text
00000a0e R_ARM_ABS32 .debug_loc
00000a1f R_ARM_ABS32 .debug_loc
00000a2e R_ARM_ABS32 .debug_loc
00000a33 R_ARM_ABS32 .debug_str
00000a3d R_ARM_ABS32 .debug_loc
00000a43 R_ARM_ABS32 .debug_str
00000a50 R_ARM_ABS32 .debug_str
RELOCATION RECORDS FOR [.debug_aranges]:
OFFSET TYPE VALUE
00000006 R_ARM_ABS32 .debug_info
00000010 R_ARM_ABS32 .text
RELOCATION RECORDS FOR [.debug_line]:
OFFSET TYPE VALUE
00000174 R_ARM_ABS32 .text
RELOCATION RECORDS FOR [.debug_frame]:
OFFSET TYPE VALUE
00000014 R_ARM_ABS32 .debug_frame
00000018 R_ARM_ABS32 .text
00000040 R_ARM_ABS32 .debug_frame
00000044 R_ARM_ABS32 .text
---
Benjamin Hase
Forschung & Entwicklung
Tel.: +49 (0) 23 24 / 96 48-0
---------------------------------------------------------------------
RESOL - Elektronische Regelungen GmbH
Heiskampstr. 10 - 45527 Hattingen / Germany
Sitz Hattingen - Geschäftsführer: Rudolf Pfeil
Amtsgericht - Registergericht - Essen - HRB 15674
---------------------------------------------------------------------