ARM GCC hardfault when using -O2

it2022-12-27  80

When using ARM GCC g++ compiler with optimization level -O2 (and up) this code:

HAL_R32(REG_AON_STACK);// => r0 = (*(volatile uint32_t*)(0x00000000)) 200008a8: 2300 movs r3, #0 200008aa: 681b ldr r3, [r3, #0] 200008ac: deff udf #255 ; 0xff

And this gives me hardfault at undefined instruction @0x200008ac. Also, if there is more code after that, it is not compiled into final binary.

You can disable this by using -fno-delete-null-pointer-checks

The pointer you are passing has a value which matches the null pointer, and the compiler can see that from static analysis, so it faults (because that is the defined behaviour).

最新回复(0)