How do I compute the code size of my benchmark code?

A typical application consists of:

  • Start-up code

  • Benchmark code

  • Code of standard libraries

When performing benchmarks, the code size of the application is the most relevant information. Therefore, the benchmark code should be located in a different section than the start-up code and code of the libraries. The following snippet, of a user-defined linker script, illustrates how you can locate libraries to a different memory area.

Example

SECTIONS
{
	.text.lib :
	{
		*lib*.a*(.text*)
		*hwinit.o(.text*)
		*start_up.o(.text*)
	} > LIB_MEM_AREA

	.text :
	{
		*(.text*)
		*(.text.*)
	} > BENCH_MEM_AREA

	.bss :
	{
		*(.bss*)
	} > DATA_MEM_AREA

}

The statement lib.a*(.text*), will take all library search paths into account. The user has to define memory areas, e.g., "LIB_MEM_AREA", in the memory description of the linker script.

Example

/* MEMORY SECTION */

ENTRY(main)

MEMORY
{
    /* FLASH-MEM */
    LIB_MEM_AREA (rx):     org = 0x80000000, len = 3M
    /* SCRATCH-PAD-MEM */
    BENCH_MEM_AREA (rx):   org = 0x70100000, len = 64K
    DATA_MEM_AREA (rwx):   org = 0x70000000, len = 64K
}

The computed size of output sections can be displayed by the following command:

llvm-size -A <.elf>

The size of the output section ".text" is the code size of your benchmark code.

If the options -ffunction-sections and -fdata-sections are set, then the linker will be able to remove unreferenced input sections via the linker option -Wl,--gc-sections. This will reduce the code size.