06.02.2013 Views

ARM Compiler toolchain Using the Linker - ARM Information Center

ARM Compiler toolchain Using the Linker - ARM Information Center

ARM Compiler toolchain Using the Linker - ARM Information Center

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.6 Example of using linker feedback<br />

To see how linker feedback works:<br />

1. Create a file fb.c containing <strong>the</strong> code shown in this example:<br />

#include <br />

void legacy()<br />

{<br />

printf("This is a legacy function that is no longer used.\n");<br />

}<br />

int cubed(int i)<br />

{<br />

return i*i*i;<br />

}<br />

void main()<br />

{<br />

int n = 3;<br />

printf("%d cubed = %d\n",n,cubed(n));<br />

}<br />

<strong>Using</strong> linker optimizations<br />

Example 5-1 Feedback example<br />

2. Compile <strong>the</strong> program, and ignore <strong>the</strong> warning that <strong>the</strong> feedback file does not exist:<br />

armcc --asm -c --feedback fb.txt fb.c<br />

This inlines <strong>the</strong> cubed() function by default, and creates an assembler file fb.s and an<br />

object file fb.o. In <strong>the</strong> assembler file, <strong>the</strong> code for legacy() and cubed() is still present.<br />

Because of <strong>the</strong> inlining, <strong>the</strong>re is no call to cubed() from main.<br />

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

3. Link <strong>the</strong> object file to create <strong>the</strong> linker feedback file with <strong>the</strong> command line:<br />

armlink --info sizes --list fbout1.txt --feedback fb.txt fb.o -o fb.axf<br />

<strong>Linker</strong> diagnostics are output to <strong>the</strong> file fbout1.txt.<br />

The linker feedback file identifies <strong>the</strong> source file that contains <strong>the</strong> unused functions in a<br />

comment (not used by <strong>the</strong> compiler) and includes entries for <strong>the</strong> legacy() and cubed()<br />

functions:<br />

;## <strong>ARM</strong> <strong>Linker</strong>, RVCT ver [Build num]: Last Updated: Date<br />

;VERSION 0.2<br />

;FILE fb.o<br />

cubed

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!