| |||
| Home > Using the Basic Linker Functionality > Optimizations and modifications > Linker feedback | |||
armlink 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 option
generates a feedback file containing each output filename, as a
comment, and the unused symbols found in the file, for example:file
;#<FEEDBACK># ARM Linker, RVCT2.2 [Build 435]: Last Updated: Wed May 04 10:15:30 2005
;VERSION 0.2
;FILE dhry_1.o
unused_func1 <= USED 0
inlined_func <= LINKER_INLINED
;FILE dhry_2.o
unused_func2 <= USED 0
When you next compile the source, use the compiler option --feedback to
specify the linker-generated feedback file to use. If no feedback
file exists, the compiler issues a warning message.file
To see how linker feedback works:
Create
a file fb.c containing the code shown in Example 3.2.
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 was 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.
For full details on these options see Generating image-related information and Controlling linker diagnostics.
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, RVCT2.2 [Build 435]: Last Updated: Wed May 04 10:45:30 2005
;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 (Code, RO
Data, RW Data, ZI Data,
and Debug). The Code and Debug components
are 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.
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.