Viewing the files the runtime linker is operating on


I picked up a neat trick on the Solaris linker mailing list this week. If you want to see the complete set of input files that are processed by the runtime linker, you can use the “-Dfiles” LD_OPTION:

$ LD_OPTIONS=-Dfiles /usr/sfw/bin/gcc -o foo foo.c

debug:
debug: file=/usr/lib/crt1.o [ ET_REL ]
debug:
debug: file=/usr/lib/crti.o [ ET_REL ]
debug:
debug: file=/usr/lib/values-Xa.o [ ET_REL ]
debug:
debug: file=/usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/crtbegin.o [ ET_REL ]
debug:
debug: file=/var/tmp//cclLa4fy.o [ ET_REL ]
debug:
debug: file=/usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/libgcc.a [ archive ]
debug:
debug: file=/usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/libgcc_eh.a [ archive ]
debug:
debug: file=/usr/lib/libc.so [ ET_DYN ]
debug: file=/usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/libgcc.a reusing: originally processed as /usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/libgcc.a
debug:
debug: file=/usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/libgcc.a [ archive ]
debug: file=/usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/libgcc_eh.a reusing: originally processed as /usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/libgcc_eh.a
debug:
debug: file=/usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/libgcc_eh.a [ archive ]
debug:
debug: file=/usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/crtend.o [ ET_REL ]
debug:
debug: file=/usr/lib/crtn.o [ ET_REL ]
debug:

The Solaris linker provides numerous other debugging options, and the full list can be viewed by running ld with the “-Dhelp” option:

$ /usr/ccs/bin/ld -Dhelp

debug:
debug: Runtime Linking
debug: Diagnostics that trace the runtime linking of an application can be
debug: enabled to stderr by using the environment variable setting:
debug: LD_DEBUG=token1,token2 app ...
debug: Alternatively, the diagnostics can be redirected to an output file
debug: using the additional environment variable:
debug: LD_DEBUG_OUTPUT=file
debug: The output file is given the specified name and the process id as a
debug: suffix.
debug:
< ..... >
This article was posted by Matty on 2007-01-13 10:15:00 -0400 -0400