Possible Stack Overflow ???

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

mnf
Valued Contributor
Valued Contributor
Posts: 530
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 294 times
Contact:

Re: Possible Stack Overflow ???

Postby mnf » Sat Dec 08, 2018 8:38 pm

- as a possible fix to the interrupt code generated by avr-gcc.

I altered the optimisation level in avra.bat to 3 (instead of 2 in FC7 or s in FC8) -to do this make a backup of avra.bat - you can find its location from 'compiler options') - edit the batch file (right click and choose edit) and change the -Os (in FC8) or -O2 (in FC7) in the first line to -O3 (note do not change the -o %2 %3)

The line should be similar to:
"%~dp0..\bin\avr-gcc.exe" -mmcu=%1 -O3 -ffunction-sections -fdata-sections -funsigned-char -o %2 %3 -lm -Wl,-gc-sections
after editing.
Save the file and reload FC.
(Alternately save the new batch file to a new filename and create a new compiler profile using the new bat file)

This sets the optimisation level of the compiler to maximum.

Recompiling Iain's program seems to give a much optimised interrupt routine. Attached are the lst files with -Os and -O3 optimisation - and the interrupt vector and interrupt routine are combined in the -O3 version. (Note that I have compiled it for the 328p processor here - I don't have a licence for the ATTiny13 in FC8 - however testing for ATTiny13 in FC7 gives a similar improvement).

So - are there any disadvantages to using -O3 over -Os (the gcc docs are at https://gcc.gnu.org/onlinedocs/gcc/Opti ... tions.html)

O3 opt.txt
(14.84 KiB) Downloaded 43 times

Os opt.txt
(15.57 KiB) Downloaded 30 times


Martin
These users thanked the author mnf for the post (total 2):
Benj (Thu Dec 13, 2018 3:50 pm) • iain wilkie (Fri Dec 14, 2018 8:52 pm)
Rating: 10.53%
 

User avatar
Benj
Matrix Staff
Posts: 14295
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4394 times
Been thanked: 4123 times
Contact:

Re: Possible Stack Overflow ???

Postby Benj » Thu Dec 13, 2018 3:52 pm

Hi Martin,

There's a nice pros and cons table here for the various optimisation levels.

https://www.rapidtables.com/code/linux/gcc/gcc-o.html

Seems that -O3 takes longer to compile and uses more ROM than -Os but certainly could be handy in cases like this.

On the flip side -O3 seems to have significantly faster code over -Os.

I wonder if there is a way we can add these as an easy to edit option inside Flowcode as most of our compilers are now GCC based. I'll think on it.
These users thanked the author Benj for the post (total 2):
mnf (Thu Dec 13, 2018 10:08 pm) • iain wilkie (Fri Dec 14, 2018 8:52 pm)
Rating: 10.53%
 

mnf
Valued Contributor
Valued Contributor
Posts: 530
Joined: Wed May 31, 2017 11:57 am
Has thanked: 52 times
Been thanked: 294 times
Contact:

Re: Possible Stack Overflow ???

Postby mnf » Thu Dec 13, 2018 10:19 pm

An easy to change option sounds good...

As an aside. In v7 it is impossible to change the programmer from within the ide... In the options section, the only choice of .exe files means that the batch files can't be selected...

Martin

iain wilkie
Posts: 89
Joined: Tue Jul 14, 2009 4:37 pm
Has thanked: 10 times
Been thanked: 8 times
Contact:

Re: Possible Stack Overflow ???

Postby iain wilkie » Fri Dec 14, 2018 10:40 am

Hi Guys,

I can confirm that changing the compiler option from Os to O3 cures the original stack overflow problem due to the reduced stack overhead used
in the interrupt routine.

So it might be an idea to have this option easily available from within Flowcode.

Can I also ask if it could be changed to allow easy access to the .lst file from within Flowcode, its such a faff about to have to look at it from
outside flowcode.

Cheers

Iain
These users thanked the author iain wilkie for the post:
mnf (Fri Dec 14, 2018 2:59 pm)
Rating: 5.26%