• Hugo Grostabussiat's avatar
    Drastically reduce the size of m4.bin · 4380f79c
    Hugo Grostabussiat authored
    This commit reduces the size of the output binary by the following
    1) enabling compiler optimization and requesting it to optimize for size
    2) using the -ffunction-sections and -fdata-sections compiler options in
       addition to the --gc-sections linker option.
    The -ffunction-sections and -fdata-sections compiler options causes the
    compiler to generate a new section for every function and object.
    Doing this enables the linker to move around individual function instead
    of full compilation units.
    The --gc-sections option instructs the linker to discard input sections
    which are not referenced by other sections in the output.
    Those two features combined allow the linker to discard all the
    functions which are unused, which can save a lot of space in the
    resulting binary.
    To know which sections are unused, the linker needs to be told at least
    one section it should keep, otherwise it would discard all the sections
    since the firmware does not have a standard entry point.
    In our case, the ldscript orders the linker to keep the m4_start.o
    .text section, as it is the one that contains the vectors table, which
    is the root from which all the useful code will be called.
    The size of the resulting m4.bin after thoses optimizations is about
    4.4 KiB vs. 11 KiB before.
Makefile 782 Bytes