Problem with Using debug and release mode

Issues 1 to 3: I have never observed that in VSCode + PlatformIO extension. Can you cross-check by using that? Note that changing the platformio.ini or CMake files will result in a full rebuild though, as compiler options have changed. Changing only a source file should only cause a single recompile + relink due to that source file.

E.g., in the previously discussed Zephyr project, I add one line to src/main.cpp and press “Build” again.

Processing nucleo_l476rg (platform: ststm32@17.5.0; board: nucleo_l476rg; framework: zephyr)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_l476rg.html
PLATFORM: ST STM32 (17.5.0) > ST Nucleo L476RG
HARDWARE: STM32L476RGT6 80MHz, 96KB RAM, 1MB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES:
 - framework-zephyr @ 2.30600.240316 (3.6.0)
 - tool-cmake @ 3.21.3
 - tool-dtc @ 1.4.7
 - tool-ninja @ 1.9.0
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\nucleo_l476rg\src\main.o
Linking .pio\build\nucleo_l476rg\zephyr\firmware-pre0.elf
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.bfd.exe: warning: .pio\build\nucleo_l476rg\zephyr\firmware-pre0.elf has a LOAD segment with RWX permissions
Memory region         Used Size  Region Size  %age Used
           FLASH:       84872 B         1 MB      8.09%
             RAM:       10504 B        96 KB     10.69%
        IDT_LIST:         121 B        32 KB      0.37%
Generating ISR table .pio\build\nucleo_l476rg\zephyr\isr_tables.c
Linking .pio\build\nucleo_l476rg\firmware.elf
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.bfd.exe: warning: .pio\build\nucleo_l476rg\firmware.elf has a LOAD segment with RWX permissions
Memory region         Used Size  Region Size  %age Used
           FLASH:       84872 B         1 MB      8.09%
             RAM:       10504 B        96 KB     10.69%
        IDT_LIST:          0 GB        32 KB      0.00%
Checking size .pio\build\nucleo_l476rg\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  10.7% (used 10506 bytes from 98304 bytes)
Flash: [=         ]   7.8% (used 82020 bytes from 1048576 bytes)
Building .pio\build\nucleo_l476rg\firmware.bin
================ [SUCCESS] Took 4.82 seconds ================

It only regenerated main.o, then relinked the firmware (in a 2-stage link process). All other object files were reused, 100%.

Issue 4: This was discussed in Granular optimisation settings - #2 by maxgerhardt.