You copied the Doc URL to your clipboard.

Symbol binding directives

These directives modify the ELF binding of one or more symbols.

Syntax

.global symbol[, symbol]…
.local symbol[, symbol]…
.weak symbol[, symbol]…

Description

.global

The .global directive sets the symbol binding to STB_GLOBAL. These symbols will be visible to all object files being linked, so a definition in one object file can satisfy a reference in another.

.local

The .local directive sets the symbol binding in the symbol table to STB_LOCAL. These symbols are not visible outside the object file they are defined or referenced in, so multiple object files can use the same symbol names without interfering with each other.

.weak

The .weak directive sets the symbol binding to STB_WEAK. These symbols behave similarly to global symbols, with these differences:

  • If a reference to a symbol with weak binding is not satisfied (no definition of the symbol is found), this is not an error.
  • If multiple definitions of a weak symbol are present, this is not an error. If a definition of the symbol with strong binding is present, that one will satisfy all references to the symbol, otherwise one of the weak references will be chosen.

Operation

The symbol binding directive can be at any point in the assembly file, before or after any references or definitions of the symbol.

If the binding of a symbol is not specified using one of these directives, the default binding is:

  • If a symbol is not defined in the assembly file, it will by default have global visibility.
  • If a symbol is defined in the assembly file, it will by default have local visibility.

Note

.local and .L are different directives. Symbols starting with .L are not put into the symbol table.

Examples

    // This function has global binding, so can be referenced from other object
    // files. The symbol 'value' defaults to local binding, so other object
    // files can use the symbol name 'value' without interfering with this
    // definition and reference.
    .global get_val
  get_val:
    ldr r0, value
    bx lr
  value:
    .word 0x12345678

    // The symbol 'printf' is not defined in this file, so defaults to global
    // binding, so the linker will search other object files and libraries to
    // find a definition of it.
    bl printf

    // The debug_trace symbol is a weak reference. If a definition of it is
    // found by the linker, this call will be relocated to point to it. If a
    // definition is not found (e.g. in a release build, which does not include
    // the debug code), the linker will point the bl instruction at the next
    // instruction, so it has no effect.
    .weak debug_trace
    bl debug_trace
Was this page helpful? Yes No