On 17/04/16 07:52, Sivanupandi, Pitchumani wrote:
Hi All,
Hello Pitchumani
It seems gcc (may be from 5) optimizes the global variable's accesses though standard C functions are called in-between the accesses.
(...)
This example is derived from avr-libc's test.
Ref: http://svn.savannah.nongnu.org/viewvc/trunk/avr-libc/tests/simulate/regression/bug-27242.c?revision=2131&root=avr-libc&view=markup
avr-gcc (used gcc-5.2) optimizes the __brkval access at line 43 by reusing the registers which is loaded with __brkval value. Is that expected?
When -ffreestanding option is enabled, the global variable is loaded from memory for line #43.
Without -ffreestanding, gcc "knows" the semantic of malloc() and realloc()
Or is there any specific option to avoid optimizing such variable access?
In this case you can probably define __brkval as volatile
In a more generic case, you could force gcc not to reuse the value by
inserting an appropiate no-op asm statement.
Best regards