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 Defining Additional Symbols with a mapfile.
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 { global: foo = FUNCTION FILTER filtee.so.1; bar = DATA S0x4 FILTER filtee.so.1; local: *; }; $ cc -o filter.so.1 -G -Kpic -h filter.so.1 -M mapfile -R. $ nm -x filter.so.1 | egrep "foo|bar" [39] |0x000102b0|0x00000004|OBJT |GLOB |0 |12 |bar [45] |0x00000000|0x00000000|FUNC |GLOB |0 |ABS |foo $ elfdump -y filter.so.1 | egrep "foo|bar" [1] F [0] filtee.so.1 bar [7] F [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.