Augmenting a Symbol Definition
The creation of an absolute data symbol within a shared object
should be avoided. An external reference from a dynamic
executable to a data item within a shared object typically
requires the creation of a copy relocation. See Copy Relocations. To
provide for this relocation, the data item should be
associated with data storage. This association can be
produced by defining the symbol within a relocatable object
file. This association can also be produced by defining the
symbol within a mapfile
together with a
size
declaration and
no
value
declaration. See SYMBOL_SCOPE and SYMBOL_VERSION Directives.
A data symbol can be filtered. See Shared Objects as Filters. To provide this
filtering, an object file definition can be augmented with a
mapfile
definition. The
following example creates a filter containing a function and
data definition.
$ cat mapfile $mapfile_version 2 SYMBOL_SCOPE { global: foo { TYPE=FUNCTION; FILTER=filtee.so.1 }; bar { TYPE=DATA; SIZE=0x4; FILTER=filtee.so.1 }; local: *; }; $ cc -o filter.so.1 -G -Kpic -h filter.so.1 -M mapfile -R. $ elfdump -sN.dynsym filter.so.1 | egrep 'foo|bar' [1] 0x105f8 0x4 OBJT GLOB D 1 .data bar [7] 0 0 FUNC GLOB D 1 ABS foo $ elfdump -y filter.so.1 | egrep 'foo|bar' [1] [ FILTER ] [0] filtee.so.1 bar [7] [ FILTER ] [0] filtee.so.1 foo
At runtime, a reference from an external object to either of these symbols is resolved to the definition within the filtee.