4.6 Example of using linker feedback

This is an example to show how linker feedback works.

Procedure

  1. Create a file fb.c containing the code shown in this example:
    #include <stdio.h>
    void legacy(void)
    {
        printf("This is a legacy function that is no longer used.\n");
    }
    int cubed(int i)
    {
        return i*i*i;
    }
    int main(void)
    {
        int n = 3;
        printf("%d cubed = %d\n",n,cubed(n));
        return 0;
    }
  2. Compile the program, and ignore the warning that the feedback file does not exist:
    armcc --asm -c --feedback fb.txt fb.c

    This inlines the cubed() function by default, and creates an assembler file fb.s and an object file fb.o. In the assembler file, the code for legacy() and cubed() is still present. Because of the inlining, there is no call to cubed() from main.

    An out-of-line copy of cubed() is kept because it is not declared as static.

  3. Link the object file to create the linker feedback file with the command line:
    armlink --info sizes --list fbout1.txt --feedback fb.txt fb.o -o fb.axf

    Linker diagnostics are output to the file fbout1.txt.

    The linker feedback file identifies the source file that contains the unused functions in a comment (not used by the compiler) and includes entries for the legacy() and cubed() functions:

    ;#<FEEDBACK># ARM Linker, 5.01 [Build num]: Last Updated: Date
    ;VERSION 0.2
    ;FILE fb.o
    cubed <= USED 0
    legacy <= USED 0

    This shows that the functions are not used.

  4. Repeat the compile and link stages with a different diagnostics file:
    armcc --asm -c --feedback fb.txt fb.c
    armlink --info sizes --list fbout2.txt fb.o -o fb.axf
  5. Compare the two diagnostics files, fbout1.txt and fbout2.txt, to see the sizes of the image components (for example, Code, RO Data, RW Data, and ZI Data). The Code component is smaller.

    In the assembler file, fb.s, the legacy() and cubed() functions are no longer in the same area as the main() function. They are compiled into their own ELF sections. Therefore, armlink can remove the legacy() and cubed() functions from the final image.

Postrequisites

Note:

To get the maximum benefit from linker feedback you have to do a full compile and link at least twice. However, a single compile and link using feedback from a previous build is usually sufficient.
Non-ConfidentialPDF file icon PDF versionARM DUI0474M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.