链接程序和库指南

调试帮助

Solaris 链接程序附带有调试库。使用此库,可以更详细地跟踪链接编辑过程。此库有助于您了解或调试应用程序和库的链接编辑。使用此库显示的信息类型应保持不变。不过,信息的确切格式可能随发行版的不同而有所变化。

如果您不太了解 ELF 格式,则可能会不熟悉某些调试输出。不过,也许您希望大概了解其中许多方面。

使用 -D 选项可以启用调试。生成的所有输出将被定向到标准错误。必须使用一个或多个标记扩充此选项,以指示需要的调试类型。在命令行中键入 -D help 可以显示可用的标记。


$ 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: cap        display hardware/software capability processing

debug: detail     provide more information in conjunction with other 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: statistics display processing statistics

debug: strtab     display information about string table compression; detail

debug:              shows layout of string tables

debug: support    display support library processing

debug: symbols    display symbol table processing; detail flag shows

debug:              internal symbol table addition and resolution

debug: tls        display TLS processing info

debug: unused     display unused/unreferenced files; detail flag shows

debug:              unused sections

debug: versions   display version processing

注 –

此列表是一个示例,用于显示对链接编辑器有意义的选项。确切选项可能随发行版的不同而有所变化。


大多数编译器驱动程序在预处理阶段解释 -D 选项。因此,LD_OPTIONS 环境变量是一种适合将此选项传递到链接编辑器的机制。

以下示例说明如何跟踪输入文件。确定已找到的库或已从归档中提取的可重定位目标文件时,此语法特别有用。


$ 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)

............

此例中,从归档库 libfoo.a 中提取了成员 foo.o,以满足对 prog 的链接编辑要求。请注意,对归档搜索了两次,以验证提取 foo.o 是否没有提取其他可重定位目标文件。多个 "again" 诊断指示该归档使用 lorder(1)tsort(1) 进行排序的候选归档。

使用 symbols 标记,可以确定导致提取归档成员的符号和进行初始符号引用的目标文件。


$ 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 ]

.............

符号 foomain.o 引用,并且被添加到链接编辑器的内部符号表中。此符号引用导致从归档 libfoo.a 中提取可重定位目标文件 foo.o


注 –

本文档中对此输出进行了简化。


detail 标记和 symbols 标记一起使用,可以观察输入文件处理期间的符号解析详细信息。


$ 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

............

已使用提取的归档成员 foo.o 中的符号定义覆盖 main.o 中未定义原始符号 foo。详细的符号信息反映每个符号的属性。

在上一个示例中,可以看到使用一些调试标记可产生大量输出。要监视部分输入文件的活动,可直接在链接编辑命令行中放置 -D 选项。可以通过切换打开和关闭此选项。在以下示例中,只有在处理库 libbar 期间,才会打开符号处理的显示功能。


$ ld .... -o prog main.o -L. -Dsymbols -lbar -D!symbols ....

注 –

要获取链接编辑命令行,可能必须从使用的任何驱动程序展开编译行。 请参见使用编译器驱动程序