29.12.2014 Views

RealView Compilation Tools Compiler Reference Guide - ARM ...

RealView Compilation Tools Compiler Reference Guide - ARM ...

RealView Compilation Tools Compiler Reference Guide - ARM ...

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.

<strong>Compiler</strong>-specific Features<br />

Usage<br />

Functions and variable declarations<br />

For declarations, this storage class specifies an extern object declaration<br />

that, even if not present, does not cause the linker to fault an unresolved<br />

reference.<br />

For example:<br />

__weak void f(void);<br />

...<br />

f(); // call f weakly<br />

If the reference to a missing weak function is made from code that<br />

compiles to a branch or branch link instruction, then either:<br />

• The reference is resolved as branching to the next instruction. This<br />

effectively makes the branch a NOP.<br />

• The branch is replaced by a NOP instruction.<br />

Function definitions<br />

Functions defined with __weak export their symbols weakly. A weakly<br />

defined function behaves like a normally defined function unless a non<br />

weakly defined function of the same name is linked into the same image.<br />

If both a non weakly defined function and a weakly defined function exist<br />

in the same image then all calls to the function resolve to call the non<br />

weak function. If multiple weak definitions are available, the linker<br />

chooses one for use by all calls.<br />

Functions declared with __weak and then defined without __weak behave<br />

as non weak functions.<br />

Restrictions<br />

There are restrictions when you qualify function and variable declarations, and function<br />

definitions, with __weak.<br />

Functions and variable declarations<br />

A function or variable cannot be used both weakly and non weakly in the<br />

same compilation. For example the following code uses f() weakly from<br />

g() and h():<br />

void f(void);<br />

void g()<br />

{<br />

f();<br />

}<br />

<strong>ARM</strong> DUI 0348A Copyright © 2007, 2010 <strong>ARM</strong> Limited. All rights reserved. 4-21<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!