Debugging Aids
A debugging library is provided with the Solaris linkers. This library enables you to trace the link-editing process in more detail. This library helps you understand, or debug, the link-edit of your own applications or libraries. Although the type of information displayed using this library is expected to remain constant, the exact format of the information might change slightly from release to release.
Some of the debugging output might be unfamiliar if you do not have an intimate knowledge of the ELF format. However, many aspects might be of general interest to you.
Debugging is enabled by using the -D option, and all output produced is directed to the standard error. This option must be augmented with one or more tokens to indicate the type of debugging required. The tokens available can be displayed by typing -D help at the command line.
$ ld -Dhelp debug: debug: For debugging the link-editing of an application: debug: LD_OPTIONS=-Dtoken1,token2 cc -o prog ... debug: or, debug: ld -Dtoken1,token2 -o prog ... debug: where placement of -D on the command line is significant debug: and options can be switched off by prepending with `!'. debug: debug: debug: args display input argument processing debug: basic provide basic trace information/warnings debug: detail provide more information in conjunction with other debug: options debug: entry display entrance criteria descriptors debug: files display input file processing (files and libraries) debug: got display GOT symbol information debug: help display this help message debug: libs display library search paths; detail flag shows actual debug: library lookup (-l) processing debug: map display map file processing debug: move display move section processing debug: reloc display relocation processing debug: sections display input section processing debug: segments display available output segments and address/offset debug: processing; detail flag shows associated sections debug: support display support library processing debug: symbols display symbol table processing; debug: detail flag shows resolution and linker table addition debug: tls display TLS processing info debug: versions display version processing |
Note - This listing is an example, and shows the options meaningful to the link-editor. The exact options might differ from release to release.
Most compiler drivers interpret the -D option during their preprocessing phase. Therefore, the LD_OPTIONS environment variable is a suitable mechanism for passing this option to the link-editor.
The following example shows how input files can be traced. This syntax can be especially useful in determining what libraries have been located, or what relocatable objects have been extracted from an archive during a link-edit.
$ LD_OPTIONS=-Dfiles cc -o prog main.o -L. -lfoo ............ debug: file=main.o [ ET_REL ] debug: file=./libfoo.a [ archive ] debug: file=./libfoo.a(foo.o) [ ET_REL ] debug: file=./libfoo.a [ archive ] (again) ............ |
Here the member foo.o is extracted from the archive library libfoo.a to satisfy the link-edit of prog. Notice that the archive is searched twice to verify that the extraction of foo.o did not warrant the extraction of additional relocatable objects. More than one "(again)" display indicates that the archive is a candidate for ordering using lorder(1) and tsort(1).
By using the symbols token, you can determine which symbol caused an archive member to be extracted, and which object made the initial symbol reference.
$ LD_OPTIONS=-Dsymbols cc -o prog main.o -L. -lfoo ............ debug: symbol table processing; input file=main.o [ ET_REL ] ............ debug: symbol[7]=foo (global); adding debug: debug: symbol table processing; input file=./libfoo.a [ archive ] debug: archive[0]=bar debug: archive[1]=foo (foo.o) resolves undefined or tentative symbol debug: debug: symbol table processing; input file=./libfoo(foo.o) [ ET_REL ] ............. |
The symbol foo is referenced by main.o and is added to the link-editor's internal symbol table. This symbol reference causes the extraction of the relocatable object foo.o from the archive libfoo.a.
Note - This output has been simplified for this document.
By using the detail token together with the symbols token, the details of symbol resolution during input file processing can be observed.
$ LD_OPTIONS=-Dsymbols,detail cc -o prog main.o -L. -lfoo ............ debug: symbol table processing; input file=main.o [ ET_REL ] ............ debug: symbol[7]=foo (global); adding debug: entered 0x000000 0x000000 NOTY GLOB UNDEF REF_REL_NEED debug: debug: symbol table processing; input file=./libfoo.a [ archive ] debug: archive[0]=bar debug: archive[1]=foo (foo.o) resolves undefined or tentative symbol debug: debug: symbol table processing; input file=./libfoo.a(foo.o) [ ET_REL ] debug: symbol[1]=foo.c ............. debug: symbol[7]=bar (global); adding debug: entered 0x000000 0x000004 OBJT GLOB 3 REF_REL_NEED debug: symbol[8]=foo (global); resolving [7][0] debug: old 0x000000 0x000000 NOTY GLOB UNDEF main.o debug: new 0x000000 0x000024 FUNC GLOB 2 ./libfoo.a(foo.o) debug: resolved 0x000000 0x000024 FUNC GLOB 2 REF_REL_NEED ............ |
The original undefined symbol foo from main.o has been overridden with the symbol definition from the extracted archive member foo.o. The detailed symbol information reflects the attributes of each symbol.
In the previous example, you can see that using some of the debugging tokens can produce a wealth of output. In cases where you are interested only in the activity around a subset of the input files, the -D option can be placed directly in the link-edit command-line, and toggled on and off. In the following example the display of symbol processing is switched on only during the processing of the library libbar.
$ ld .... -o prog main.o -L. -Dsymbols -lbar -D!symbols .... |
Note - To obtain the link-edit command line you might have to expand the compilation line from any driver being used. See "Using a Compiler Driver".