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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.3 Elimination of unused sections<br />

5.3.1 See also<br />

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

Unused section elimination is <strong>the</strong> most significant optimization on image size that is performed<br />

by <strong>the</strong> linker. It removes unreachable code and data from <strong>the</strong> final image.<br />

Unused section elimination is suppressed in cases that might result in <strong>the</strong> removal of all sections.<br />

To control this optimization use <strong>the</strong> --remove, --no_remove, --first, --last, and --keep linker<br />

options.<br />

Unused section elimination requires an entry point. Therefore, if <strong>the</strong>re is no entry point specified<br />

for an image, use <strong>the</strong> --entry linker option to specify an entry point and permit unused section<br />

elimination to work, if it is enabled.<br />

Note<br />

By default, unused section elimination is disabled if you are building DLLs with --dll, or shared<br />

libraries with --shared. Therefore, you must explicitly include --remove to re-enable unused<br />

section elimination.<br />

Use <strong>the</strong> --info unused linker option to instruct <strong>the</strong> linker to generate a list of <strong>the</strong> unused sections<br />

that it eliminates.<br />

An input section is retained in <strong>the</strong> final image under <strong>the</strong> following conditions:<br />

• if it contains an entry point<br />

• if it is referred to, directly or indirectly, by a non-weak reference from an input section<br />

containing an entry point<br />

• if it is specified as <strong>the</strong> first or last input section by <strong>the</strong> --first or --last option (or a<br />

scatter-loading equivalent)<br />

• if it is marked as unremovable by <strong>the</strong> --keep option.<br />

Note<br />

<strong>Compiler</strong>s usually collect functions and data toge<strong>the</strong>r and emit one section for each category.<br />

The linker can only eliminate a section if it is entirely unused.<br />

You can mark a function or variable in source code with <strong>the</strong> __attribute__((used)) attribute.<br />

This causes armcc to generate <strong>the</strong> symbol __tagsym$$used for each of <strong>the</strong> functions and variables,<br />

and ensures that <strong>the</strong> function or variable is not removed by <strong>the</strong> linker.<br />

You can also use <strong>the</strong> --split_sections compiler command-line option to instruct <strong>the</strong> compiler<br />

to generate one ELF section for each function in <strong>the</strong> source file.<br />

Concepts<br />

• Input sections, output sections, regions, and Program Segments on page 4-5<br />

• About weak references and definitions on page 4-32<br />

• Elimination of common debug sections on page 5-2<br />

• Elimination of common groups or sections on page 5-3<br />

• Elimination of unused virtual functions on page 5-6.<br />

<strong>ARM</strong> DUI 0474C Copyright © 2010-2011 <strong>ARM</strong>. All rights reserved. 5-4<br />

ID080411 Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!