5.6. GLOBAL: Exporting Symbols

GLOBAL is the other end of EXTERN: if one module declares a symbol as EXTERN and refers to it, then in order to prevent linker errors, some other module must actually define the symbol and declare it as GLOBAL. Some assemblers use the name PUBLIC for this purpose.

The GLOBAL directive applying to a symbol must appear before the definition of the symbol.

GLOBAL uses the same syntax as EXTERN, except that it must refer to symbols which are defined in the same module as the GLOBAL directive. For example:

        global _main
_main:  ; some code

GLOBAL, like EXTERN, allows object formats to define private extensions by means of a colon. The elf object format, for example, lets you specify whether global data items are functions or data:

        global hashlookup:function, hashtable:data

Like EXTERN, the primitive form of GLOBAL differs from the user-level form only in that it can take only one argument at a time.