Making use of objcopy's --update-section for fun and profit

The binutils project’s objcopy utility gained an –update-section feature with the 2.26 release. This flag lets you insert the contents of any file into an already existing section in the ELF. You can make use of this flag to do a couple of things that are currently tricky to get right - placing data computed from the contents of the ELF (say the SHA1 hash of flash contents) into a binary, and creating a combined bootloader/application image from two separate binary files.

LTO and the linker command line

If you’re using GCC’s LTO feature, make sure you repeat the compiler flags when linking. So, if you compile code with -Os -ffunction-sections, make sure you pass the same flags to the gcc driver when linking. This is needed because LTO effectively recompiles by streaming in IR from the object files and regenerating code. Only this time it knows about the code in all the object files that’s going to be part of the final executable, so it can perform a bunch of optimizations it previously couldn’t.