cancel
Showing results for 
Search instead for 
Did you mean: 

Why does my build include so many 'unused' functions ?

Strooom
Associate III

I use STM32CubeIde in a fairly standard way, only that I use C++ source on top of the C HAL code. When inspecting the build with Build Analyzer, I noticed A LOT of code which I think I never included.. (never sure what all the HAL files do..) for example

std::__moneypunct_cache(...) :

seems to be some standard library to deal with numbers in financial format.. No idea where this could be. I don't do any of that in my application.

I think I didn't use any of the std:: stuff, but still a lot of it seems to be in my build.

When I want to do OTA firmware updates, this is going to be a problem..

Is there a simple way to strip all unused library code from the build ?

Should I use different build settings ?

Is there a way to trace back to the code who is calling these libraries ?

3 REPLIES 3
S.Ma
Principal

Disable main() by inserting temporarily a "return;" at the top of the function.

If your toolchain is decently operating, the linker will remove all the unused functions and your code footprint should be the startup() and the interrupt service routines if any.

The linker will discard all the function never referenced.

The linker has vision limits, especially when the user code uses function pointers....

Only penalty is build time, and even this, makefile will make the time shrink once the first build is done.

Perhaps some format related to printf/scanf

I supposed you'd do a disassembly with symbols, and cross-reference the functions.

Dump the ELF libraries, and GREP those..

Should be able to determine who imports / exports the symbols, and perhaps write an AWK script or whatever you data processing / scripting language of choice is.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Ok, that is simple to try : when I do that, all the library stuff is still in the build.

Here are my linker settings..


_legacyfs_online_stmicro_images_0693W00000blA4yQAE.pngStill, the Interrupt routines call HAL functions, so it may still be included from there..

I see that some of the LoRaWAN stuff uses printf statements for debugging, so maybe it's included from there...