Hi,
I have a C-project which runs on NRF52832 (cortex M4). Using Segger Embedded Studio Release 5.10b (Build 2020091601.43513 Linux x64), segger-cc: version 10.6.6.
My issue is the compiler generates an strd instruction using an unaligned address, which causes a hard fault when I run it.
C-code:
Display All
When compiling with optimization level 0, everything runs fine.
However, when changing optimization level to 1 (and above), the following code is generated by the compiler (only parts of generated code shown):
Display All
The issue is the last line (#14), causing a hard fault because the address in r0 is 0x2000637a which is not 32-bit aligned. Changing the address to 0x2000637c before executing the line causes no hard fault.
Edit: The address in question (0x2000637a) is the first parameter in the function (*ctx).
The question is; is this caused by me and something I have configured wrong in my project? Or is this a bug in the compiler?
Best regards.
I have a C-project which runs on NRF52832 (cortex M4). Using Segger Embedded Studio Release 5.10b (Build 2020091601.43513 Linux x64), segger-cc: version 10.6.6.
My issue is the compiler generates an strd instruction using an unaligned address, which causes a hard fault when I run it.
C-code:
Source Code
- int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
- {
- SHA256_VALIDATE_RET( ctx != NULL );
- SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 );
- ctx->total[0] = 0;
- ctx->total[1] = 0;
- if( is224 == 0 )
- {
- /* SHA-256 */
- ctx->state[0] = 0x6A09E667;
- ctx->state[1] = 0xBB67AE85;
- ctx->state[2] = 0x3C6EF372;
- ctx->state[3] = 0xA54FF53A;
- ctx->state[4] = 0x510E527F;
- ctx->state[5] = 0x9B05688C;
- ctx->state[6] = 0x1F83D9AB;
- ctx->state[7] = 0x5BE0CD19;
- }
- else
- {
- /* SHA-224 */
- ctx->state[0] = 0xC1059ED8;
- ctx->state[1] = 0x367CD507;
- ctx->state[2] = 0x3070DD17;
- ctx->state[3] = 0xF70E5939;
- ctx->state[4] = 0xFFC00B31;
- ctx->state[5] = 0x68581511;
- ctx->state[6] = 0x64F98FA7;
- ctx->state[7] = 0xBEFA4FA4;
- }
- ctx->is224 = is224;
- return( 0 );
- }
However, when changing optimization level to 1 (and above), the following code is generated by the compiler (only parts of generated code shown):
Source Code
- 6681 str r1, [r0, #0x68]
- F04F0C00 mov.w r12, #0
- F64473A4 movw r3, #0x4FA4
- F6CB63FA movt r3, #0xBEFA
- 2900 cmp r1, #0
- BF04 itt eq
- F64C5319 movweq r3, #0xCD19
- F6C533E0 movteq r3, #0x5BE0
- F64872A7 movw r2, #0x8FA7
- F2C642F9 movt r2, #0x64F9
- BF04 itt eq
- F64D12AB movweq r2, #0xD9AB
- F6C17283 movteq r2, #0x1F83
- E9C02308 strd r2, r3, [r0, #32]
The issue is the last line (#14), causing a hard fault because the address in r0 is 0x2000637a which is not 32-bit aligned. Changing the address to 0x2000637c before executing the line causes no hard fault.
Edit: The address in question (0x2000637a) is the first parameter in the function (*ctx).
The question is; is this caused by me and something I have configured wrong in my project? Or is this a bug in the compiler?
Best regards.
The post was edited 1 time, last by cnaess ().