undefined instructions in kernel.elf generated in arm-none-eabi-gcc compilation

Asked by Miguel Cafruni

Hi !
I'm having a problem in a bare metal application that compile correctly for raspbarry pi b+ v1.2 2014, but don't work properly. The application is a RTOS.
For example: the following function in C:

float StrToFloat(char valor[25]) /* Convert a string stored in a global variable dado[25] for floating point representation */
{
 int i;
 float F1 = 1;
 float F2 = 10;
     if(valor[0] != '-'){
 for(i=dot-1; i>=0; i--)
 {
  V+=((float)valor[i]-0x030) * F1;
   F1*=10;
 }
 for(i=dot+1; i<pos; i++)
 {
  V+=((float)valor[i]-0x030) / F2;
   F2*=10;
 }
 return(V);
 }
 else{
 for(i=dot-1; i>=1; i--)
 {
  V+=((float)valor[i]-0x030) * F1;
   F1*=10;
 }
 for(i=dot+1; i<pos; i++)
 {
  V+=((float)valor[i]-0x030) / F2;
   F2*=10;
 }
 V *= -1;
 return(V);
 }
}
I disassembly the kernel.elf using objdump and get the following lines for the above function "StrToFloat" (the undefined instructions are almost in the end):

00009f78 <StrToFloat>:
    9f78: e52db004 push {fp} ; (str fp, [sp, #-4]!)
    9f7c: e28db000 add fp, sp, #0
    9f80: e24dd01c sub sp, sp, #28
    9f84: e50b0018 str r0, [fp, #-24] ; 0xffffffe8
    9f88: e3a035fe mov r3, #1065353216 ; 0x3f800000
    9f8c: e50b300c str r3, [fp, #-12]
    9f90: e59f3244 ldr r3, [pc, #580] ; a1dc <StrToFloat+0x264>
    9f94: e50b3010 str r3, [fp, #-16]
    9f98: e51b3018 ldr r3, [fp, #-24] ; 0xffffffe8
    9f9c: e5d33000 ldrb r3, [r3]
    9fa0: e353002d cmp r3, #45 ; 0x2d
    9fa4: 0a000040 beq a0ac <StrToFloat+0x134>
    9fa8: e59f3230 ldr r3, [pc, #560] ; a1e0 <StrToFloat+0x268>
    9fac: e5933000 ldr r3, [r3]
    9fb0: e2433001 sub r3, r3, #1
    9fb4: e50b3008 str r3, [fp, #-8]
    9fb8: ea000015 b a014 <StrToFloat+0x9c>
    9fbc: e51b3008 ldr r3, [fp, #-8]
    9fc0: e51b2018 ldr r2, [fp, #-24] ; 0xffffffe8
    9fc4: e0823003 add r3, r2, r3
    9fc8: e5d33000 ldrb r3, [r3]
    9fcc: ee073a90 vmov s15, r3
    9fd0: eef87a67 vcvt.f32.u32 s15, s15
    9fd4: ed9f7a7e vldr s14, [pc, #504] ; a1d4 <StrToFloat+0x25c>
    9fd8: ee377ac7 vsub.f32 s14, s15, s14
    9fdc: ed5b7a03 vldr s15, [fp, #-12]
    9fe0: ee277a27 vmul.f32 s14, s14, s15
    9fe4: e59f31f8 ldr r3, [pc, #504] ; a1e4 <StrToFloat+0x26c>
    9fe8: edd37a00 vldr s15, [r3]
    9fec: ee777a27 vadd.f32 s15, s14, s15
    9ff0: e59f31ec ldr r3, [pc, #492] ; a1e4 <StrToFloat+0x26c>
    9ff4: edc37a00 vstr s15, [r3]
    9ff8: ed5b7a03 vldr s15, [fp, #-12]
    9ffc: ed9f7a75 vldr s14, [pc, #468] ; a1d8 <StrToFloat+0x260>
    a000: ee677a87 vmul.f32 s15, s15, s14
    a004: ed4b7a03 vstr s15, [fp, #-12]
    a008: e51b3008 ldr r3, [fp, #-8]
    a00c: e2433001 sub r3, r3, #1
    a010: e50b3008 str r3, [fp, #-8]
    a014: e51b3008 ldr r3, [fp, #-8]
    a018: e3530000 cmp r3, #0
    a01c: aaffffe6 bge 9fbc <StrToFloat+0x44>
    a020: e59f31b8 ldr r3, [pc, #440] ; a1e0 <StrToFloat+0x268>
    a024: e5933000 ldr r3, [r3]
    a028: e2833001 add r3, r3, #1
    a02c: e50b3008 str r3, [fp, #-8]
    a030: ea000015 b a08c <StrToFloat+0x114>
    a034: e51b3008 ldr r3, [fp, #-8]
    a038: e51b2018 ldr r2, [fp, #-24] ; 0xffffffe8
    a03c: e0823003 add r3, r2, r3
    a040: e5d33000 ldrb r3, [r3]
    a044: ee073a90 vmov s15, r3
    a048: eef87a67 vcvt.f32.u32 s15, s15
    a04c: ed9f7a60 vldr s14, [pc, #384] ; a1d4 <StrToFloat+0x25c>
    a050: ee377ac7 vsub.f32 s14, s15, s14
    a054: ed5b7a04 vldr s15, [fp, #-16]
    a058: ee877a27 vdiv.f32 s14, s14, s15
    a05c: e59f3180 ldr r3, [pc, #384] ; a1e4 <StrToFloat+0x26c>
    a060: edd37a00 vldr s15, [r3]
    a064: ee777a27 vadd.f32 s15, s14, s15
    a068: e59f3174 ldr r3, [pc, #372] ; a1e4 <StrToFloat+0x26c>
    a06c: edc37a00 vstr s15, [r3]
    a070: ed5b7a04 vldr s15, [fp, #-16]
    a074: ed9f7a57 vldr s14, [pc, #348] ; a1d8 <StrToFloat+0x260>
    a078: ee677a87 vmul.f32 s15, s15, s14
    a07c: ed4b7a04 vstr s15, [fp, #-16]
    a080: e51b3008 ldr r3, [fp, #-8]
    a084: e2833001 add r3, r3, #1
    a088: e50b3008 str r3, [fp, #-8]
    a08c: e59f3154 ldr r3, [pc, #340] ; a1e8 <StrToFloat+0x270>
    a090: e5933000 ldr r3, [r3]
    a094: e51b2008 ldr r2, [fp, #-8]
    a098: e1520003 cmp r2, r3
    a09c: baffffe4 blt a034 <StrToFloat+0xbc>
    a0a0: e59f313c ldr r3, [pc, #316] ; a1e4 <StrToFloat+0x26c>
    a0a4: e5933000 ldr r3, [r3]
    a0a8: ea000044 b a1c0 <StrToFloat+0x248>
    a0ac: e59f312c ldr r3, [pc, #300] ; a1e0 <StrToFloat+0x268>
    a0b0: e5933000 ldr r3, [r3]
    a0b4: e2433001 sub r3, r3, #1
    a0b8: e50b3008 str r3, [fp, #-8]
    a0bc: ea000015 b a118 <StrToFloat+0x1a0>
    a0c0: e51b3008 ldr r3, [fp, #-8]
    a0c4: e51b2018 ldr r2, [fp, #-24] ; 0xffffffe8
    a0c8: e0823003 add r3, r2, r3
    a0cc: e5d33000 ldrb r3, [r3]
    a0d0: ee073a90 vmov s15, r3
    a0d4: eef87a67 vcvt.f32.u32 s15, s15
    a0d8: ed9f7a3d vldr s14, [pc, #244] ; a1d4 <StrToFloat+0x25c>
    a0dc: ee377ac7 vsub.f32 s14, s15, s14
    a0e0: ed5b7a03 vldr s15, [fp, #-12]
    a0e4: ee277a27 vmul.f32 s14, s14, s15
    a0e8: e59f30f4 ldr r3, [pc, #244] ; a1e4 <StrToFloat+0x26c>
    a0ec: edd37a00 vldr s15, [r3]
    a0f0: ee777a27 vadd.f32 s15, s14, s15
    a0f4: e59f30e8 ldr r3, [pc, #232] ; a1e4 <StrToFloat+0x26c>
    a0f8: edc37a00 vstr s15, [r3]
    a0fc: ed5b7a03 vldr s15, [fp, #-12]
    a100: ed9f7a34 vldr s14, [pc, #208] ; a1d8 <StrToFloat+0x260>
    a104: ee677a87 vmul.f32 s15, s15, s14
    a108: ed4b7a03 vstr s15, [fp, #-12]
    a10c: e51b3008 ldr r3, [fp, #-8]
    a110: e2433001 sub r3, r3, #1
    a114: e50b3008 str r3, [fp, #-8]
    a118: e51b3008 ldr r3, [fp, #-8]
    a11c: e3530000 cmp r3, #0
    a120: caffffe6 bgt a0c0 <StrToFloat+0x148>
    a124: e59f30b4 ldr r3, [pc, #180] ; a1e0 <StrToFloat+0x268>
    a128: e5933000 ldr r3, [r3]
    a12c: e2833001 add r3, r3, #1
    a130: e50b3008 str r3, [fp, #-8]
    a134: ea000015 b a190 <StrToFloat+0x218>
    a138: e51b3008 ldr r3, [fp, #-8]
    a13c: e51b2018 ldr r2, [fp, #-24] ; 0xffffffe8
    a140: e0823003 add r3, r2, r3
    a144: e5d33000 ldrb r3, [r3]
    a148: ee073a90 vmov s15, r3
    a14c: eef87a67 vcvt.f32.u32 s15, s15
    a150: ed9f7a1f vldr s14, [pc, #124] ; a1d4 <StrToFloat+0x25c>
    a154: ee377ac7 vsub.f32 s14, s15, s14
    a158: ed5b7a04 vldr s15, [fp, #-16]
    a15c: ee877a27 vdiv.f32 s14, s14, s15
    a160: e59f307c ldr r3, [pc, #124] ; a1e4 <StrToFloat+0x26c>
    a164: edd37a00 vldr s15, [r3]
    a168: ee777a27 vadd.f32 s15, s14, s15
    a16c: e59f3070 ldr r3, [pc, #112] ; a1e4 <StrToFloat+0x26c>
    a170: edc37a00 vstr s15, [r3]
    a174: ed5b7a04 vldr s15, [fp, #-16]
    a178: ed9f7a16 vldr s14, [pc, #88] ; a1d8 <StrToFloat+0x260>
    a17c: ee677a87 vmul.f32 s15, s15, s14
    a180: ed4b7a04 vstr s15, [fp, #-16]
    a184: e51b3008 ldr r3, [fp, #-8]
    a188: e2833001 add r3, r3, #1
    a18c: e50b3008 str r3, [fp, #-8]
    a190: e59f3050 ldr r3, [pc, #80] ; a1e8 <StrToFloat+0x270>
    a194: e5933000 ldr r3, [r3]
    a198: e51b2008 ldr r2, [fp, #-8]
    a19c: e1520003 cmp r2, r3
    a1a0: baffffe4 blt a138 <StrToFloat+0x1c0>
    a1a4: e59f3038 ldr r3, [pc, #56] ; a1e4 <StrToFloat+0x26c>
    a1a8: edd37a00 vldr s15, [r3]
    a1ac: eef17a67 vneg.f32 s15, s15
    a1b0: e59f302c ldr r3, [pc, #44] ; a1e4 <StrToFloat+0x26c>
    a1b4: edc37a00 vstr s15, [r3]
    a1b8: e59f3024 ldr r3, [pc, #36] ; a1e4 <StrToFloat+0x26c>
    a1bc: e5933000 ldr r3, [r3]
    a1c0: ee073a90 vmov s15, r3
    a1c4: eeb00a67 vmov.f32 s0, s15
    a1c8: e24bd000 sub sp, fp, #0
    a1cc: e49db004 pop {fp} ; (ldr fp, [sp], #4)
    a1d0: e12fff1e bx lr
    a1d4: 42400000 submi r0, r0, #0
    a1d8: 41200000 ; <UNDEFINED> instruction: 0x41200000
    a1dc: 41200000 ; <UNDEFINED> instruction: 0x41200000
    a1e0: 000120e8 andeq r2, r1, r8, ror #1
    a1e4: 0000dcc8 andeq sp, r0, r8, asr #25
    a1e8: 0000dcc4 andeq sp, r0, r4, asr #25

Note the last lines just above with undefined instructions. I do not know how to eliminate this problem or what they mean and how hurt my program. There is not warning messages in compilation time.
There are many undefined instructions for all disassembly file that have 13800+ lines.
The Linux installation tarball is gcc-arm-none-eabi-5_4-2016q2-20160622-linux.tar.bz2
My laptop is a i5 core and S.O. is Ubuntu 16.04 LTS.
Sorry by the long text and thanks for attention!
Miguel

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Tejas Belagod
Solved:
Last query:
Last reply:
Revision history for this message
Best Tejas Belagod (belagod-tejas) said :
#1

Note the bx lr at address

a1d0: e12fff1e bx lr

This suggests to me that all the 'instructions' you're seeing after the bx lr is actually a literal pool. As long as control does not reach this point, you OK.

Revision history for this message
Miguel Cafruni (cafruni71) said :
#2

Hi Tejas
Thank you for your explanation, but I still without understand why this is generated, because I compared this disassembly with another from a compilation for a real processor (lpc2378) the same arm1176, the same RTOS and there is not undefined instructions in .text section ou .rodata section.
Miguel

Revision history for this message
Miguel Cafruni (cafruni71) said :
#3

I'm understanding what is a literal pool right now, :P, so I have simply accept that for a arm embedded in RAM the compiler work differently for a arm physical?

Revision history for this message
Miguel Cafruni (cafruni71) said :
#4

Hi Tejas!!
Because your answer I understand the literal pool and make some optimizations in my C code:

float StrToFloat(char valor[25]) /* Convert a string stored in a global variable dado[25] for floating*/
{
 int i;
 int F1 = 1;
 int F2 = 10;

 for(i=dot-1; i>=0; i--)
 {
  V+=((float)valor[i]-0x030) * F1;
   F1*=10;
 }
 for(i=dot+1; i<pos; i++)
 {
  V+=((float)valor[i]-0x030) / F2;
   F2*=10;
 }
        if(valor[0] == '-')
        {
 V *= -1;
 return(V);
        }
 else return(V);
}

As you see the variables F1 and F2 now are integer variables and was this cause the literal pools !!

Now the disassembly lines for the function (about 60 lines more shorted):

00009f78 <StrToFloat>:
    9f78: e52db004 push {fp} ; (str fp, [sp, #-4]!)
    9f7c: e28db000 add fp, sp, #0
    9f80: e24dd01c sub sp, sp, #28
    9f84: e50b0018 str r0, [fp, #-24] ; 0xffffffe8
    9f88: e3a03001 mov r3, #1
    9f8c: e50b300c str r3, [fp, #-12]
    9f90: e3a0300a mov r3, #10
    9f94: e50b3010 str r3, [fp, #-16]
    9f98: e59f3160 ldr r3, [pc, #352] ; a100 <StrToFloat+0x188>
    9f9c: e5933000 ldr r3, [r3]
    9fa0: e2433001 sub r3, r3, #1
    9fa4: e50b3008 str r3, [fp, #-8]
    9fa8: ea000019 b a014 <StrToFloat+0x9c>
    9fac: e51b3008 ldr r3, [fp, #-8]
    9fb0: e51b2018 ldr r2, [fp, #-24] ; 0xffffffe8
    9fb4: e0823003 add r3, r2, r3
    9fb8: e5d33000 ldrb r3, [r3]
    9fbc: ee073a90 vmov s15, r3
    9fc0: eef87a67 vcvt.f32.u32 s15, s15
    9fc4: ed9f7a4c vldr s14, [pc, #304] ; a0fc <StrToFloat+0x184>
    9fc8: ee377ac7 vsub.f32 s14, s15, s14
    9fcc: e51b300c ldr r3, [fp, #-12]
    9fd0: ee073a90 vmov s15, r3
    9fd4: eef87ae7 vcvt.f32.s32 s15, s15
    9fd8: ee277a27 vmul.f32 s14, s14, s15
    9fdc: e59f3120 ldr r3, [pc, #288] ; a104 <StrToFloat+0x18c>
    9fe0: edd37a00 vldr s15, [r3]
    9fe4: ee777a27 vadd.f32 s15, s14, s15
    9fe8: e59f3114 ldr r3, [pc, #276] ; a104 <StrToFloat+0x18c>
    9fec: edc37a00 vstr s15, [r3]
    9ff0: e51b200c ldr r2, [fp, #-12]
    9ff4: e1a03002 mov r3, r2
    9ff8: e1a03103 lsl r3, r3, #2
    9ffc: e0833002 add r3, r3, r2
    a000: e1a03083 lsl r3, r3, #1
    a004: e50b300c str r3, [fp, #-12]
    a008: e51b3008 ldr r3, [fp, #-8]
    a00c: e2433001 sub r3, r3, #1
    a010: e50b3008 str r3, [fp, #-8]
    a014: e51b3008 ldr r3, [fp, #-8]
    a018: e3530000 cmp r3, #0
    a01c: aaffffe2 bge 9fac <StrToFloat+0x34>
    a020: e59f30d8 ldr r3, [pc, #216] ; a100 <StrToFloat+0x188>
    a024: e5933000 ldr r3, [r3]
    a028: e2833001 add r3, r3, #1
    a02c: e50b3008 str r3, [fp, #-8]
    a030: ea000019 b a09c <StrToFloat+0x124>
    a034: e51b3008 ldr r3, [fp, #-8]
    a038: e51b2018 ldr r2, [fp, #-24] ; 0xffffffe8
    a03c: e0823003 add r3, r2, r3
    a040: e5d33000 ldrb r3, [r3]
    a044: ee073a90 vmov s15, r3
    a048: eef87a67 vcvt.f32.u32 s15, s15
    a04c: ed9f7a2a vldr s14, [pc, #168] ; a0fc <StrToFloat+0x184>
    a050: ee377ac7 vsub.f32 s14, s15, s14
    a054: e51b3010 ldr r3, [fp, #-16]
    a058: ee073a90 vmov s15, r3
    a05c: eef87ae7 vcvt.f32.s32 s15, s15
    a060: ee877a27 vdiv.f32 s14, s14, s15
    a064: e59f3098 ldr r3, [pc, #152] ; a104 <StrToFloat+0x18c>
    a068: edd37a00 vldr s15, [r3]
    a06c: ee777a27 vadd.f32 s15, s14, s15
    a070: e59f308c ldr r3, [pc, #140] ; a104 <StrToFloat+0x18c>
    a074: edc37a00 vstr s15, [r3]
    a078: e51b2010 ldr r2, [fp, #-16]
    a07c: e1a03002 mov r3, r2
    a080: e1a03103 lsl r3, r3, #2
    a084: e0833002 add r3, r3, r2
    a088: e1a03083 lsl r3, r3, #1
    a08c: e50b3010 str r3, [fp, #-16]
    a090: e51b3008 ldr r3, [fp, #-8]
    a094: e2833001 add r3, r3, #1
    a098: e50b3008 str r3, [fp, #-8]
    a09c: e59f3064 ldr r3, [pc, #100] ; a108 <StrToFloat+0x190>
    a0a0: e5933000 ldr r3, [r3]
    a0a4: e51b2008 ldr r2, [fp, #-8]
    a0a8: e1520003 cmp r2, r3
    a0ac: baffffe0 blt a034 <StrToFloat+0xbc>
    a0b0: e51b3018 ldr r3, [fp, #-24] ; 0xffffffe8
    a0b4: e5d33000 ldrb r3, [r3]
    a0b8: e353002d cmp r3, #45 ; 0x2d
    a0bc: 1a000007 bne a0e0 <StrToFloat+0x168>
    a0c0: e59f303c ldr r3, [pc, #60] ; a104 <StrToFloat+0x18c>
    a0c4: edd37a00 vldr s15, [r3]
    a0c8: eef17a67 vneg.f32 s15, s15
    a0cc: e59f3030 ldr r3, [pc, #48] ; a104 <StrToFloat+0x18c>
    a0d0: edc37a00 vstr s15, [r3]
    a0d4: e59f3028 ldr r3, [pc, #40] ; a104 <StrToFloat+0x18c>
    a0d8: e5933000 ldr r3, [r3]
    a0dc: ea000001 b a0e8 <StrToFloat+0x170>
    a0e0: e59f301c ldr r3, [pc, #28] ; a104 <StrToFloat+0x18c>
    a0e4: e5933000 ldr r3, [r3]
    a0e8: ee073a90 vmov s15, r3
    a0ec: eeb00a67 vmov.f32 s0, s15
    a0f0: e24bd000 sub sp, fp, #0
    a0f4: e49db004 pop {fp} ; (ldr fp, [sp], #4)
    a0f8: e12fff1e bx lr
    a0fc: 42400000 submi r0, r0, #0
    a100: 00011f90 muleq r1, r0, pc ; <UNPREDICTABLE>
    a104: 0000db70 andeq sp, r0, r0, ror fp
    a108: 0000db6c andeq sp, r0, ip, ror #22

Well now I have a big C code to optimize...
Many thanks !
Cheers
Miguel

Revision history for this message
Miguel Cafruni (cafruni71) said :
#5

Thanks Tejas Belagod, that solved my question.