Example 2 Using the nm command

Display which object files have undefined references for the symbol leap: nm -rup *.o grep leap

Display which object files have a definition for the text symbol leap:

nm -rP *.o awk '{ if ($3 == "T" && $2 == "leap" ) { print $0 } }'

To view the symbols defined in an object file, use the nm command. The following 32-bit mode example shows output from running nm -pon the func.o and main.o object files.

$ nm -p func.o

0000000000

u

 

 

0000000000

r

.HP.opt_annot

 

0000000000

r

.IA_64.unwind_info

 

0000000000

r

.text

 

0000000000

a

func.c

 

0000000000

T

sum_n

//Global definitions of sum_n.

$ nm -p main.o

 

 

0000000000

U

$global$

//Other symbols created from compiling.

0000000000

u

 

 

0000000000

r

.HP.opt_annot

 

0000000000

r

.IA_64.unwind_info

 

0000000000

r

.data

 

0000000000

r

.sdata

 

0000000000

r

.text

 

0000000000

a

main.c

 

0000000000

T

main

//Global definition of main.

0000000000

U

printf

 

0000000000

U

scanf

 

0000000000

U

sum_n

 

Viewing the Contents of an Object File with elfdump(1)

The elfdump(1) command displays information contained in ELF format object files, archives, and shared libraries. Use the following options to select the information you want to display:

To view this

Use the option

 

 

Archive headers from an archive library.

-a

 

 

String table(s).

-c

 

 

The .note section which contains the compilation unit dictionary and linker footprint. This

-d

option has the same effect as elfdump -dc-dl.

 

 

 

The compilation unit dictionary of the .note section.

-dc

 

 

The linker footprint of the .note section. The linker footprint has information on the linker

-dc

used to generate the file as well as the link time.

 

 

 

File header.

-f

 

 

Global symbols from an archive.

-g

 

 

Section headers.

-h

 

 

The run-time interpreter path name for a.out (usually the location of the dynamic loader

+interp

and microloader). Only shared bound executables have this string. To change the setting,

 

use the ld+interp command.

 

 

 

The object dictionary for one or more executable files, if the source file was compiled with

-j

the +objdebug option. The object dictionary entry contains the name of the object file that

 

contributed to a particular section, the relative offset within the section, size of the object

 

file's contribution, and attributes of the entry.

 

 

 

The CTTI section headers according to the directory member relationship.

-k

 

 

58 Linker Tools for Itanium-Based Systems