2013/03/05

A Bug of ARM Compiler Error

Log an ARM compiler error.
Be careful bit field in the structure.
Good case, to write a the bit field, read/modify/write operation is done: do 4 bytes ready, update 3 bytes, write 4 bytes back.
 
 // With this structure  
 typedef __packed struct{  
   mUINT_32 nvSecSetIndex : 24;
   mUINT_32 dummy : 16;
 }mtNV_SEC_SET; 
 
 // We get compile result  
 nvSecSetIndex = setIndex;  
 00139a 9001         STR   r0,[sp,#4]  
 00139c f7fffffe     BL    __aeabi_uread4  
 0013a0 f3650017     BFI   r0,r5,#0,#24  
 0013a4 9901         LDR   r1,[sp,#4]  
 0013a6 f7fffffe     BL    __aeabi_uwrite4   

NG case, do 4 bytes write directly. This will overwrites the memory of address ((int)&(p->nvSecSetIndex) + 3). Happens when the structure has only one bit field.
  
 // With this structure  
 typedef __packed struct{  
   mUINT_32 nvSecSetIndex : 24;   
 }mtNV_SEC_SET;  

 // We get compile result  
 nvSecSetIndex = setIndex;  
 00139a 4628         MOV   r0,r5  
 00139c f7fffffe     BL    __aeabi_uwrite4   

No comments:

Post a Comment

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...