 RealView Linker and Utilities Guide |
|
| Linker feedbackarmlink provides feedback for the next time a file is compiled, to inform the compiler about unused functions. These are placed in their own sections for future elimination by the linker. When the ‑‑inline optimization is turned on (see Branch inlining), functions inlined by the linker are also emitted in the feedback file. These functions are also placed in their own sections. The ‑‑feedback file option generates a feedback file containing each output filename, as a comment, and the unused symbols found in the file, for example:
;#<FEEDBACK># ARM Linker, RVCT ver [Build num]: Last Updated: Date
;VERSION 0.2
;FILE foo.o
unused_func1 <= USED 0
inlined_func <= LINKER_INLINED
;FILE bar.o
unused_func2 <= USED 0
When you next compile the source, use the compiler option ‑‑feedback file to specify the linker-generated feedback file to use. If no feedback file exists, the compiler issues a warning message. To see how linker feedback works: Create a file fb.c containing the code shown in Example 3.1. Example 3.1. Feedback example
#include <stdio.h>
void legacy()
{
printf("This is a legacy function, that is no longer used.\n");
}
int cubed(int i)
{
return i*i*i;
}
void main()
{
int n = 3;
printf("%d cubed = %d\n",n,cubed(n));
}
Compile the program (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. 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, RVCT ver [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. 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
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 main .text area. They are compiled into their own ELF sections. Therefore, armlink can remove the legacy() and cubed() functions from the final image.
NoteTo 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. |
|