clang-17, lto and aggressive optimisations

Lately, i updated lnDSO150 to v2.3, in particular its build system to be in sync with how i do things nowadays.

The main goal is to easily switch between GCC and CLANG-17 (  arm or riscv )

The lnDSO150 has one variant (the FNIRSI one) with less flash ( only 64 kB), so i could use every flash gain possible

Using clang + lto DID provide a nice size reduction (final size was ~ 50 kB for the fnirsi build) and at first it seemed to work alright.

At first.


Then, i realized that it made some underlying problem appear due its aggressive optimization.

In other words, the bugs were there since day one, but hidden because the software was losing the race against the hardware every time.


A couple of examples :

- On the DSO150, some of the screen GPIO are reprogrammed as input to scan if  buttons have been pressed. If you flip the gpio too quickly, the button MAY keep the last state it was when used as output, causing random fake key pressed. Adding a couple of nops fixed the issue.

- Similarly, the flash driver was racing against the flash hw. Adding a couple of nops fixed the issue, probably not the right fix.


It is human to first assume clang+lto is a buggy compiler. That's not the case, it was buggy code.





Comments

Popular posts from this blog

Component tester with STM32 : Part 1 ADC, Resistor

Fixing the INA3221

INA3221, weird wiring