SPRAB89A September 2011 – March 2014
A weak function is a function whose symbol has binding STB_WEAK. A program can successfully link without a definition of a weak function, leaving references to it unresolved.
The linker handles unresolved weak function calls differently depending on whether static linking or dynamic linking is used.
When static linking is used, the linker replaces calls to undefined weak functions with what effectively becomes a NOP. But to enable optimizations such as tail call elimination in which the callee does not return to the call site, the replacement must preserve some aspects of the call's behavior. Therefore the replacement is not with NOP, but with a surrogate return instruction:
B.S2 B3 ; replacement for unresolved weak call
This behavior imposes these additional requirements on calls to weak functions:
The ABI supports calls to imported weak functions; that is, potentially defined in a different static link unit.
When dynamic linking is used, the global offset table (GOT) is used to decide whether to leave the unresolved weak function with a value of 0 or patch in the address of _ _c6xabi_weak_return(), which simply returns to its caller. If the value of 0 is used (for the Linux platform), a guard is required. If the _ _c6xabi_weak_return() function is used (for the bare metal platform), no guard is not required.