ELF file size discrepancy - Page 1
Forum section: electronics / general

author: peter-h
author_rank: Super Contributor
timestamp: November 25, 2022, 09:45:30 pm
content: This is the Cube Build Analyserbut the resulting binary file is 463k (473092 bytes).The ELF is 5.2MBMy post build batch file isCode:arm-none-eabi-objcopy -S --strip-all -R .bss -R .main_heap -R .ccmram -O binary xxx.elf bin.datProbably I am not quite "stripping all" but what can I do to narrow it down?The bin.dat is the file which is actually programmed into the CPU FLASH. I know this because I wrote all that code; the boot loader and all. That file is loaded from a FAT12 file system (FatFS) and its actual size in bytes is programmed. So if there is some excess in bin.dat, it doesn't do anything, or there is no excess and the Build Analyser display is BS.The only reason this actually matters is because I have a code size ceiling of 510k in this version of the project, due to unrelated factors (the CPU is 1MB FLASH).Of the total code size, about 300k is MBEDTLSThe "MBED" is a bit of a joke... Next year they will be calling a PC with 24GB RAM "embedded".

author: hans
author_rank: Super Contributor
timestamp: November 25, 2022, 10:26:44 pm
content: A bin file cannot "jump" memory sections. Your BL uses 12.39kB, but reserves 32kB. So around 19.6kB of space will be filled with 0s to get to the memory address of the main program.32kB+429.8kB=461.8kB = 472883bPretty close to your 473092b .bin file.If you want a program file that can write memory at any arbritrary location, you need .hex.Concerning usage.. your main program last memory address is at 462kB out 510kB. So it is the actual usage. Perhaps a bit more than expected because the BL is healthily proportioned at 32kB, even though 16kB at this point would fit, but not sure about the FLASH pages on that chip.

author: eutectique
author_rank: Frequent Contributor
timestamp: November 25, 2022, 11:58:50 pm
content: Do objdump of your elf file. You will find hefty .debug* sections.Also, consider "fill=0xff' option for objcopy. Otherwise unused areas are filled with zeros.Or consider .hex or .srec format, as already suggested.

author: eutectique
author_rank: Frequent Contributor
timestamp: November 26, 2022, 12:09:17 am
content: Quote from: peter-h on November 25, 2022, 09:45:30 pmInside a tomograph, itisembedded.

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 26, 2022, 01:03:54 am
content: What was the original question?

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 26, 2022, 03:42:37 am
content: Yep if the OP wants to know what is really inside the ELF file, he can run objdump on it. Probably 'objdump -x' is the best bet here.arm-none-eabi-objdump should be part of the compiler's binaries.

author: peter-h
author_rank: Super Contributor
timestamp: November 26, 2022, 06:41:09 am
content: Thank you - the boot loader / boot block pretty well explains it.I am keeping the 32k reserved for that, for future use. Also the bottom FLASH block is 32k which is handy because reflashing that block (takes ~300ms) is the only bricking time window.I could go to hex format if this was a problem, but also I could recompile the code with -Os which on past tests should save about 40k.