Optimizing for size

Michael Meissner newlib@the-meissners.org
Sat Aug 30 20:05:00 GMT 2003

On Thu, Aug 28, 2003 at 02:31:40AM +0200, Vincent Rubiolo wrote:
> Hello to you newlib experts,
> I am currently investigating on means to reduce the code size of our 
> project that I ported from ADS 1.2 to GNU toolchain with newlib.
> The perl scripts I use to report sizes of the different parts show that the 
> runtime lib could be one area of such improvements.
> I would like to have your feedback concerning the following points :
> 1. The build of newlib with optimisations for size has no incidence of the 
> library size archive (libc.a) at all. The memory usage (we have two memory 
> zones, RAM and FLASH) is -192 bytes in FLASH and -12 bytes in RAM (retaken 
> over by padding) between the two versions of the library. Can I expect more 
> from the size-optimised version of newlib of are these typical memory 
> improvements?
> 2. Since enabling -fdata-sections and -ffunction-sections flags of gcc 
> along with --gc-sections really improved the size of the binary, I was 
> thinking about tweaking newlib to build in such a way. After having dug 
> into the source, I see that this can be done via C-defines for the mallocr 
> to contain only one function each time. Is there any other less painful way 
> of doing this (such as -fdata-sections and -ffunction-sections)?
> Thank you for your consideration.

If for some reason you are using the printf family of functions (printf,
fprintf, sprintf), you might get an immediate reduction in space if you switch
to the iprintf functions (iprintf, fiprintf, siprintf).  The printf functions
support the printing of floating point values, while the iprintf functions are
integer only.  In addition to the space for handling %f/%d/%g, it also brings
in the most of the floating point emulator on systems without hardware floating

Michael Meissner
email: gnu@the-meissners.org

More information about the Newlib mailing list