Using the DIRECT
mapfile
Keyword
The DIRECT
mapfile
keyword provides a means of establishing a direct binding for individual symbols. This mechanism is intended for specialized link-editing scenarios.
From the components used in the previous example, the function main
() references the external functions W
() and X
(). The binding of these functions follow the default search model.
$ LD_DEBUG=symbols,bindings prog3
....
18754: symbol=W; lookup in file=prog3 [ ELF ]
18754: symbol=W; lookup in file=./W.so.2 [ ELF ]
18754: binding file=prog3 to file=./W.so.2: symbol 'W'
....
18754: symbol=X; lookup in file=prog3 [ ELF ]
18754: symbol=X; lookup in file=./W.so.2 [ ELF ]
18754: symbol=X; lookup in file=./X.so.2 [ ELF ]
18754: binding file=prog3 to file=./X.so.2: symbol 'X'
prog3
can be rebuilt with DIRECT
mapfile
keywords so that direct bindings are established to the functions W
() and X
().
$ cat mapfile $mapfile_version 2 SYMBOL_SCOPE { global: W { FLAGS = EXTERN DIRECT }; X { FLAGS = EXTERN DIRECT }; }; $ cc -o prog4 -R. main.c W.so.2 X.so.2 -Mmapfile
The LD_DEBUG
environment variable can be used to observe the runtime bindings.
$ LD_DEBUG=symbols,bindings,detail prog4
....
23432: symbol=W; lookup in file=./W.so.2 [ ELF ]
23432: binding file=prog4 to file=./W.so.2: symbol 'W' (direct)
23432: symbol=X; lookup in file=./X.so.2 [ ELF ]
23432: binding file=prog4 to file=./x.so.2: symbol 'X' (direct)
The
lari
(1) utility can also reveal the direct binding information. However in this case, the functions W
() and X
() are not multiply defined. Therefore, by default lari
does not find these functions interesting. The -a
option must be used to display all symbol information.
$ lari -a prog4
....
[1:1ED]: W(): ./W.so.2
....
[2:1ED]: X(): ./X.so.2
....
Note:
The same direct binding toW.so.2
and X.so.1
, can be produced by building prog4
with the -B direct
option or the -z direct
option. The intent of this example is solely to convey how the mapfile
keyword can be used.