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
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
5.7 About link-time code generation<br />
5.7.1 Considerations when using LTCG<br />
5.7.2 Example<br />
<strong>Using</strong> linker optimizations<br />
Link-time code generation (LTCG) enables cross source-file optimization by delaying code<br />
generation until <strong>the</strong> link stage. This can significantly reduce code size. To enable LTCG, compile<br />
your source with -c --ltcg to create objects in an intermediate format. You must <strong>the</strong>n link <strong>the</strong>se<br />
object files with --ltcg to instruct <strong>the</strong> linker to perform code generation.<br />
Both armcc and armlink have a --ltcg command-line option to enable LTCG.<br />
Note<br />
You can also use LTCG with Profiler-guided optimizations.<br />
Be aware of <strong>the</strong> following when using LTCG:<br />
• If no input objects are compiled with --ltcg, <strong>the</strong> final object is <strong>the</strong> same as that produced<br />
without LTCG.<br />
• Debug information is not preserved in any object files compiled with --ltcg. However,<br />
debug information is still preserved for any object files that are not compiled with --ltcg.<br />
• You cannot use specific object file names in scatter files because LTCG causes a<br />
temporary object file to be created and used for linking. If you are using a scatter file, <strong>the</strong>n<br />
you must match files using <strong>the</strong> wildcard *. O<strong>the</strong>rwise no match is made on <strong>the</strong> temporary<br />
file.<br />
• If <strong>the</strong>re is more than one entry point in <strong>the</strong> input object files provided to <strong>the</strong> linker, <strong>the</strong><br />
linker clears all entry points. Therefore, you must specify an entry point on <strong>the</strong> linker<br />
command-line with:<br />
--entry=symbol<br />
Any input section containing an entry point is not removed. For example, where an object<br />
is built without --ltcg.<br />
Note<br />
The linker option --entry=object(symbol) is not supported when using LTCG.<br />
The following example shows a typical use of LTCG:<br />
1. Create ELF object files one.o and two.o with --ltcg:<br />
armcc -c --ltcg one.c -o one.o<br />
armcc -c --ltcg two.c -o two.o<br />
The compiler generates intermediate code into <strong>the</strong> object files.<br />
2. Link <strong>the</strong>m using <strong>the</strong> command:<br />
armlink --ltcg one.o two.o -o ltcg_image.axf<br />
The linker:<br />
1. Combines all <strong>the</strong> immediate code toge<strong>the</strong>r, losing <strong>the</strong> link to original object file names.<br />
2. Performs code generation for <strong>the</strong> intermediate code.<br />
<strong>ARM</strong> DUI 0474C Copyright © 2010-2011 <strong>ARM</strong>. All rights reserved. 5-11<br />
ID080411 Non-Confidential