object files can contain more information about a global symbol than just its address:
they can contain the size of the symbol and its type as well. These are not merely
debugger conveniences, but are actually necessary when the program being written is a
((shared library)). Yasm therefore supports some extensions to the NASM syntax
directive (see Section 5.6), allowing you to specify these
features. Yasm also provides the ELF-specific directives in Section 9.3 to allow
specifying this information for non-global symbols.
global hashlookup:function, hashtable:data
exports the global symbol
hashlookup as a function and
hashtable as a data object.
Optionally, you can control the ELF visibility of the symbol. Just add one of the
protected. The default is
course. For example, to make
global hashlookup:function hidden
You can also specify the size of the data associated with the symbol, as a numeric expression (which may involve labels, and even forward references) after the type specifier. Like this:
global hashtable:data (hashtable.end - hashtable) hashtable: db this,that,theother ; some data here .end:
This makes Yasm automatically calculate the length of the table and place that
information into the ELF symbol table. The same information can be given more verbosely
TYPE (see Section 9.3.3) and
(see Section 9.3.2) directives as follows:
global hashtable type hashtable object size hashtable hashtable.end - hashtable hashtable: db this,that,theother ; some data here .end:
Declaring the type and size of global symbols is necessary when writing shared library code.