'cmake and make resulting in different binary sizes when cross-compiling

I am cross-compiling to an ARM target in a Ubuntu 20.04 host machine.

The files I am building are from an SDK from Quectel, which already has makefiles and it builds fine.

My job is to translate the makefiles into a CMakeFileList.txt to do the same as the makefile does. That is already done.

Procedure to translate makefiles to cmake

I ran the make with verbose mode, and then I collected all the flags that are set, linker options, compiler options, linker mapping, etc.

Issue found on this

I noticed that the binary differs from what is built via the makefiles and what is built via CMakeList.txt, although they are working.

Output from the original makefiles:

Memory region         Used Size  Region Size  %age Used
LOAD_IRAM_MCUVECTOR:         100 B        100 B    100.00%
   LOAD_IRAM_MCU:        4056 B       5020 B     80.80%
UNLOAD_DRAM_USRNV:          1 KB         1 KB    100.00%
   LOAD_DRAM_MCU:          48 B         4 KB      1.17%
UNLOAD_DRAM_PSPHYRET:          6 KB         6 KB    100.00%
       LOAD_IRAM:       32404 B        32 KB     98.89%
LOAD_DRAM_SHARED:      124448 B       156 KB     77.90%
   LOAD_DRAM_BSP:        3884 B         8 KB     47.41%
UNLOAD_DRAM_FLASHMEM:          7 KB         7 KB    100.00%
UNLOAD_DRAM_SLPMEM:         224 B        992 B     22.58%
       FLASH_APP:     2356204 B      2560 KB     89.88%

Output from the CMakeList.txt developed:

Memory region         Used Size  Region Size  %age Used
LOAD_IRAM_MCUVECTOR:         100 B        100 B    100.00%
   LOAD_IRAM_MCU:        4056 B       5020 B     80.80%
UNLOAD_DRAM_USRNV:          1 KB         1 KB    100.00%
   LOAD_DRAM_MCU:          48 B         4 KB      1.17%
UNLOAD_DRAM_PSPHYRET:          6 KB         6 KB    100.00%
       LOAD_IRAM:       32404 B        32 KB     98.89%
LOAD_DRAM_SHARED:      124464 B       156 KB     77.91%
   LOAD_DRAM_BSP:        3884 B         8 KB     47.41%
UNLOAD_DRAM_FLASHMEM:          7 KB         7 KB    100.00%
UNLOAD_DRAM_SLPMEM:         224 B        992 B     22.58%
       FLASH_APP:     2354932 B      2560 KB     89.83%

As you can see, the difference is quite small, 3984 Bytes more in the CMakeList.txt case.

The compiler and linker used are the same:

arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Toolchain for the Arm Architecture 11.2-2022.02 (arm-11.14)) 11.2.1 20220111
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

arm-none-eabi-ld --version
GNU ld (GNU Toolchain for the Arm Architecture 11.2-2022.02 (arm-11.14)) 2.37.20220122
Copyright (C) 2021 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.


Question: Is there a reason for this difference?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source