I use the same code under the windows keil-C with armcc v6 ,the optimization parameter is -Oz and the linux gcc-arm-none-eabi-9-2020-q2-update, the optimization parameter is -Os. I don't understand why the code size is so different. the hex from keil-C is about 1584 bytes, but the hex from linux gcc about 33xx bytes.
Check the disassembly of both the binaries and see what extra data/code got added into the gcc-built binary.
View all questions in GNU Toolchain forum