search    
HP-UX Linker and Libraries User's Guide
Hewlett-Packard
Linker Tools for Itanium-Based Systems

This chapter describes the linker toolset for Itanium-based system. This toolset provides several tools to help you find symbols, display and modify object files, and determine link order. These tools are specific to ELF (executable and linking format) object file type.

The following lists the linker toolset.

Tool Description
chatr

Displays or modifies the internal attributes of an object file. See Changing a Program's Attributes with chatr(1).

elfdump

Displays the contents of an ELF object file. See Viewing the Contents of an Object File with elfdump(1).

fastbind

Improves start-up time of programs that use shared libraries. See Improving Program Start-up with fastbind(1).

ldd

Lists dynamic dependencies of executable files and shared libraries. Viewing library dependencies with ldd(1).

lorder

Finds ordering relationship for an object library. See Finding Object Library Ordering Relationships with lorder(1).

nm

Displays the symbol table of an object file. See Viewing Symbols in an Object file with nm(1).

pldd

Lists the dynamic libraries linked into each process, including shared objects explicitly attached using dlopen/shl_load.

pstack

Prints a stack trace (hex+symbolic) for each lwp in each process and core file.

size

Prints sizes of object file elements. See Viewing the Size of Object File Elements with size(1).

strip

Strips symbol and debugging information from an object file, executable, or archive library. See Reducing Storage Space with strip(1).

Changing a Program's Attributes with chatr(1)

The chatr command (see chatr(1)) allows you to change various program attributes that were determined at link time. When run without any options, chatr displays the attributes of the specified file.

The chatr command supports two different command syntaxes. One is provided for the easy manipulation of simple files. Use it to modify files that have only a single text segment and data segment. The second command syntax allows you to specify selected segments to modify. The following sections list the additional IPF/PA-64 mode options for the chatr command. See the chatr(1) manpage for more information about formats.

The following summarizes the options you can use to change various attributes:

To do this Use the option

Indicate that the specified shared library is subject to run-time path lookup if directory path lists are provided (see +s and +b).

-l libname

Perform operations silently.

-s

Enable run-time dereferencing of null pointers to produce a SIGSEGV signal. (This is the complement of the -Z option.)

-z

Use immediate binding for all libraries loaded at program start-up.

-B immediate

Use deferred binding for all libraries loaded at program start-up.

-B deferred

Disable run-time dereferencing of null pointers. (This is the complement of the -z option.)

-Z

Control the address space model to be used by the kernel. Possible values for mode are default, share_magic, exec_magic, shmem_magic, and mpas. The default value is currently equivalent to share_magic. In order to set the mode to any value other than the default, the binary must be built with the -N compiler option to ensure that the text and data segments are contiguous.

+as mode

Control whether the embedded path list stored when the program (if any) was built can be used to locate shared libraries needed by the program. The two flag values, enable and disable, respectively enable and disable use of the embedded path list. However, you cannot use disable on an ELF file, and a warning message is issued.

If +b enable and +s enable are both specified, the order in which they appear determines which search path is used first. See the +s option.

+b flag

Format 2 only: Enable or disable the code bit for a specified segment. If this is enabled, it is denoted by the +c flag for the segment listing in the chatr output.

+c flag

Enable or disable the code bit for the file's data segment(s). If this is enabled, it is denoted by the +c flag for the segment listing in the chatr output.

+cd flag

Enable or disable the code bit for the file's text segments(s). If this is enabled, it is denoted by the +c flag for the segment listing.

+ci flag

Enable or disable the ability to run a program, and, after it is running, attach to it with a debugger and set breakpoints in its dependent shared libraries. For shared libraries, this flag makes the text segment mapped private and writable.

+dbg flag

Format 2 only: Enable or disable lazy swap allocation for dynamically allocated segments (such as the stack or heap).

+dz flag

Control the ability of user code to execute from stack with the flag values, enable and disable. See the "Restricting Execute Permission on Stacks" section of the chatr(1) manpage for additional information related to security issues.

+es flag

Control whether the global symbol table hash mechanism is used to look up values of symbol import/export entries. The two flag values, enable and disable, respectively enable and disable use of the global symbol table hash mechanism. The default is disable.

+gst flag

Request a particular hash array size using the global symbol table hash mechanism. The value can vary between 1 and MAXINT. The default value is 1103. Use this option with +gst enable. This option works on files linked with the +gst option.

+gstsize size

Controls the preference of physical memory for the data segment. This is important only on ccNUMA (Coherent Non-Uniform Memory Architecture) systems. The flag value may be either enable or disable. When enabled, the data segment uses interleaved memory. When disabled (the default), the data segment uses cell local memory. This behavior is inherited across a fork() but not an exec. For more information on ccNUMA, see pstat_getlocality(2).

+id flag

Request kernel assisted branch prediction. The flags, enable and disable, turn this request on and off, respectively.

+k flag

Do not subject a library to path list lookup, even if path lists are provided. That is, use default library path stored in the executable.

+l libname

Format 2 only: Enable or disable the modification bit for a specified segment. If this is enabled, it is denoted by the +m flag for the segment listing in the chatr output.

+m flag

Enable or disable the modification bit for the file's data segment(s). If this is enabled, it is denoted by the +m flag for the segment listing in the chatr output.

+md flag

Enable or disable the shared library segment merging features. When enabled, all data segments of shared libraries loaded at program start-up are merged into a single block. Data segments for each dynamically loaded library are merged with the data segments of its dependent libraries. Merging of these segments increases run-time performance by allowing the kernel to use larger size page table entries.

+mergeseg flag

Enable or disable the modification bit for the file's text segment(s). If this is enabled, it is denoted by the +m flag for the segment listing in the chatr output.

+mi flag

Enable or disable the DF_ORIGIN flag to control use of $ORIGIN in calculating the absolute path of the load module directory. Enabling the flag instructs the dynamic loader to calculate the absolute path of the parent module (object module, shared library, or executable) when it is first loaded. The loader then uses this path for all occurrences of $ORIGIN. If there are no occurrences of $ORIGIN, you should disable the DF_ORIGIN flag, to avoid calculating the absolute path. By default, if $ORIGIN is not present, the DF_ORIGIN flag is disabled.

+o flag

Format 2 only: Set the page size for a specified segment.

+p size

Request a particular virtual memory page size that must be used for data. Sizes of 4K, 16K, 64K, 256K, 1M, 4M, 16M, 64M, 256M, 1G, 4G, D, and L are supported. A size of D results in using the default page size. A size of L results in using the largest page size available. The actual page size may vary if the requested size cannot be fulfilled.

+pd size

Request a particular virtual memory page size that should be used for text (instructions). See the +pd option for additional information.

+pi size

Request static branch prediction when executing this program. The flags enable and disable this request. If this request is enabled, it is denoted by the +r flag for the segment listing in the chatr output.

+r flag

Control whether the directory path list specified with the LD_LIBRARY_PATH and SHLIB_PATH environment variables can be used to locate shared libraries needed by the program. The two flag values, enable and disable, respectively enable and disable use of the environment variable. If both +s and +b are used, their relative order on the command line indicates which path list is searched first. See the +b option.

+s flag

Format 2 only: Specify a segment using an address for a set of attribute modifications.

+sa address

Format 2 only: Use all segments in the file for a set of attribute modifications.

+sall

Format 2 only: Specify a segment using a segment index number for a set of attribute modifications.

+si index

Enable or disable lazy swap on all data segments (using Format 1) or on a specific segment (using Format 2). The flags enable and disable, this request. Cannot be used with non-data segments.

+z flag

Enable or disable dynamic instrumentation by /opt/langtools/bin/caliper. If enabled, the dynamic loader (see dld.so(5)) automatically invokes caliper upon program execution to collect profile information.

+I flag

Disable linkage table protection. Once you disable, you cannot use +protect to enable linkage table protection. You have to relink the executable to turn on the linkage table protection.

+protect disable flag

Viewing Symbols in an Object file with nm(1)

The nm(1) command displays the symbol table of each specified object. The file can be a relocatable object file or an executable object file, or an archive of relocatable or executable object files.

The nm command provides three general output formats: the default (neither -p nor -P specified), -p, and -P. See the nm(1) man page for a detailed description of the output formats.

To do this Use the option

Prefix each output line with the name of the object file or archive file. Equivalent to -r.

-A

Demangle C++ names before printing them.

-C

Display the value and size of a symbol in decimal. This is the default for the default format or the -p format. Equivalent to -t d.

-d

Display only external and static symbols. This option is ignored (see
-f).

-e

Display full output. This option is in force by default.

-f

Display only external (global) symbol information.

-g

Do not display the output header data.

-h

Distinguish between weak and global symbols by appending * to the key letter of weak symbols. Only takes effect with -p and/or -P.

-l

Sort symbols by name, in ascending collation order before they are printed. This is the default. To turn off this option, use -N.

-n

Display symbols in the order in which they appear in the symbol table.

-N

Display the value and size of a symbol in octal. Equivalent to -t o.

-o

Display information in a blank-separated output format. Each symbol name is preceded by its value (blanks if undefined) and one of the letters.

Lower case letters indicate local values. Upper case letters indicate global values.

absolute

a, A

bss symbol

b, B

common symbol

c, C

data symbol

d, D

milli symbol

m, M

no type

n, N

section region

r, R

text symbol

t, T

undefined symbol

u, U

-p

Display information in a portable output format to standard output. See the nm(1) manpage for format information. Note that -p is not compatible with -P.

-P

Prefix each output line with the name of the object file or archive file. Equivalent to -A.

-r

Print the section index instead of the section name (ELF only). -s

Display each numeric value in the specified format. The format can be one of:

d

Display the value and size of a symbol in decimal. This is the default for the default format or the -p format. Equivalent to -d.

o

Display the value and size of a symbol in octal. Equivalent to
-o.

x

Display the value and size of a symbol in hexadecimal. This is the default for the -P format. Equivalent to -x.

-t format

Display undefined symbols only.

-u

Print the usage menu.

-U

Sort symbols by value before they are printed.

-v

Display the executing version of the nm command on standard error.

-V

Displays the value and size of a symbol in hexadecimal. this is the default for the -P format. Equivalent to -t x.

-x

Examples

  • 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 -p on 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 option has the same effect as elfdump -dc -dl.

-d

The compilation unit dictionary of the .note section.

-dc

The linker footprint of the .note section. The linker footprint has information on the linker used to generate the file as well as the link time.

-dl

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 and microloader). Only shared bound executables have this string. To change the setting, use the ld +interp command.

+interp

The object dictionary for one or more executable files, if the source file was compiled with 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.

-j

The CTTI section headers according to the directory member relationship.

-k

The .dynamic section in shared libraries and dynamically linked program files.

-L

The .linkmap section, which is only created when the incremental linker is used (with the ld +ild command).

+linkmap

The .linkmap_bss section, which is only created when the incremental linker is used (with the ld +ild command).

+linkmap_bss

The .linkmap_file section, which is only created when the incremental linker is used (with the ld +ild command).

+linkmap_file

Optional headers (program headers).

-o

Relocations.

-r

Sections beginning with .objdebug_ as a string table.

+objdebug

Section contents.

-s

Symbol table entries.

-t

Dumps the value of st_shndx in symbol table, in addition to information dump from -t option. This option is useful in verifying the data stored in the symbol table.

-tx

Prints versioned symbols.

-tv

 

 

Usage message.

-u

Unwind table.

-U

Version number for elfdump.

-V

The elfdump command provides the following additional options to modify your selections:

Option Modifies Causes elfdump to

-C

-c, -r, -s, -t

Demangle C++ symbol names before displaying them.

  • With -H, ignored.

  • With -n name, display the symbol whose unmangled name matches name, and prints its symbol name as a demangled name.

-D num

-h, -s

Display the section whose index is num.

+D num2

-h, -s

Display the sections in the range 1 to num2.

  • With -D, display the sections in the range num to num2.

-D num

-r

Display the relocation whose index is num.

+D num2

-r

Display only the relocations which apply to the section(s) in the range.

-H

all

Select output format in hexadecimal, octal, or decimal.

-n name

-h, -r, -s

Display information about the section specified by name.

-n name

-t

Display information about the symbol entry specified by name.

-p

all

Suppress title printing.

-q

-k

Suppress printing CTTI section headers.

+s name

-c, -t

Display the section specified by name.

-S

-h,-o

Display headers in short format.

-T num

-t

Display the symbol whose index is num.

+T num2

-t

Display the symbols in the range 0 to num2.

  • With-T, display the symbols in the range num to num2.

-v

-k

Verify the CTTI section headers before printing.

Viewing Library Dependencies with ldd(1)

The ldd(1) command lists the dynamic dependencies of executable files or shared libraries. The ldd command displays verbose information about dynamic dependencies and symbol references:

Executable

All shared libraries loaded as a result of executing the file.

Shared library

All shared libraries loaded as a result of loading the library.

The ldd command uses the same algorithm as the dynamic loader (/usr/lib/hpux32/dld.so and /usr/lib/hpux64/dld.so) to locate the shared libraries.

The ldd command does not list shared libraries explicitly loaded using dlopen(3C) or shl_load(3X).

The ldd command prints the record of shared library path names to stdout. It prints a list of symbol resolution problems to stderr.

To do this Use the option

Check reference to data symbols.

-d

Check reference to data and code symbols.

-r

Displays the search path used to locate the shared libraries.

-s

Display all dependency relationships.

-v

Examples

  • By default, ldd prints simple dynamic path information, including the dependencies recorded in the executable (or the shared library) followed by the physical location where the dynamic loader finds these libraries.

    $ ldd a.out

    	./libx.so =>	./libx.so
    		libc.so.1 =>	/usr/lib/hpux32/libc.so.1
    		libdl.so.1 =>	/usr/lib/hpux32/libdl.so.1
    	
  • The -v option causes ldd to print the dependency relationships along with the dynamic path information.

    $ ldd -v a.out

    	find library=./libx.so; required by a.out 
    		./libx.so =>	./libx.so 
    	find library=libc.so.1; required by a.out 
    		libc.so.1 =>	/usr/lib/hpux32/libc.so.1
    	find library=libdl.so.1; required by usr/lib/hpux32/libc.so.1
    		libdl.so.1 =>	/usr/lib/hpux32/libdl.so.1 
    	
  • The -r option to causes it to analyze all symbol references and print information about unsatisfied code and data symbols.

    $ldd -r a.out

    	./libx.sl	=>	./libx.sl
    	libc.so.1	=>	/usr/lib/hpux32/libc.so.1
    	libdl.1	=>	/usr/lib/hpux32/libdl.so.1
    	symbol not found: val1 (./libx.so)
    	symbol not found: count (./libx.so)
    	symbol not found: func1 (./libx.so)
    	symbol not found: func2 (./libx.so)
    	

Listing Dynamic Libraries with pldd(1)

Given a process ID (PID) or a corefile, the pldd command prints a list of shared libraries loaded including those loaded explicitly with dlopen() and shl_load(). The pldd command works by attaching to the process to read its memory. Mismatch between executable and corefile may result in unpredictable behavior.

The pldd command searches for the executable file in the current directory and $PATH. The executable path can be specified along with the pid/corepath, separated by a colon (:) character.

Use the -h option to print the usage menu.

The following exit values are returned:
0: Successful operation
non-zero: An error has occurred.

Printing a Stack Trace with pstack(1)

Given the PID of a running process or the full path to a corefile, the pstack command prints the stack trace for each lwp thread in the process. To obtain symbol information, pstack searches load modules (executable/shared libraries) in the current directory, $PATH, $LD_LIBRARY_PATH, and $SHLIB_PATH. The executable path can be specified along with the PID/core-file-path, separated by a colon (:) character. If a load module is not found, symbol information for frames in that module is not displayed.

The pstack command works by attaching to the running process and reading its registers, memory, and stack. Mismatch between executable and corefile may result in unpredictable behavior.

The following exit values are returned:
0: Successful operation
non-zero: An error has occurred.

Viewing the Size of Object File Elements with size(1)

The size(1) command produces section size information for each section in your specified object files. It displays the size of the text, data, and bss (uninitialized data) sections with the total size of the object file. If you specify an archive file, the information for all archive members is displayed.

Use the following options to view information for your specified files:

To view this Use the option

Sizes in decimal (default).

-d

Size of each allocatable section.

-f

Size and permission bits of each loadable segment.

-F

Sizes of nonloadable segments or nonallocatable sections.

-n

Sizes in octal.

-o

Display the usage message.

-u

Version information about the size command.

-V

Verbose list of the subspaces in the object files. Each subspace is listed on a separate line with its name, size, and virtual address.

-v

Sizes in hexadecimal.

-x

Reducing Storage Space with strip(1)

The strip(1) command removes the symbol table and line number information from object files, including archives. Thereafter, no symbolic debugging access is available for that file. The purpose of this command is to reduce file storage overhead consumed by the object file. Use this command on production modules that have been debugged and tested. The effect is nearly identical to using the -s option of ld.

You can control the amount of information stripped from the symbol table by using the following options:

To Use the option

Strip line number information only; do not strip any symbol table information.

-l

Same as the -x option. Obsolete.

-r

Strip the unwind information and annotations.

-u

Print the usage message.

-U

Print the version of the strip command to stderr.

-V

Strip the debug information and line number table.

-x


Note

The -l and -x options are synonymous because the symbol table contains only static and external symbols. Either option strips only symbolic debugging information and unloadable data.


If there are any relocation entries in the object file and any symbol table information is to be stripped, strip issues a message and terminates without stripping the specified file unless the -r option is used.

If you execute strip on an archive file (see ar(4)), it removes the archive symbol table. The archive symbol table must be restored by executing ar with its s operator (see ar(1)) before the ld command (see ld (1)) can use the archive. The strip command issues appropriate warning messages when this situation occurs.

Improving Program Start-up with fastbind(1)

The fastbind(1) command prepares an incomplete executable for faster program start-up. It can improve the start-up time of programs that use shared libraries (incomplete executables) by storing information about needed shared library symbols in the executable file.

The fastbind command performs analysis on the symbols used to bind an executable and all of its dependent shared libraries, and stores this information in the executable file. The next time the executable is run, the dynamic loader (/usr/lib/hpux32/dld.so for 32-bit or /usr/lib/hpux64/dld.so for 64-bit) detects that this information is available, and uses it to bind the executable instead of using the standard search method for binding the symbols.

The fastbind command writes the fastbind information in the executable file. Hence, you must have write permission on the executable file. If the executable file being analyzed is being run as another process or the file is locked against modifications by the kernel, the fastbind command fails.

If the shared libraries that an executable is dependent on are modified after the fastbind information is created, the dynamic loader silently reverts to standard search method for binding the symbols. The fastbind information can be re-created by running the fastbind command on the executable again. The fastbind command automatically erases the old fastbind information and generates the new one.

To do this Use the option

Remove the fastbind information from the executable, returning it to the same state it as was in before you ran fastbind on it.

-n

Normally, if fastbind detects any unsatisfied symbols while building the fastbind information, it generates an error message and does not modify the executable file. However, when you invoke fastbind with the -u option, fastbind allows unresolved symbols.

-u

The PA-32-bit mode fastbind command does not work with EXEC_MAGIC executables.

The fastbind command effectively enforces the binding modes bind-restricted and bind-immediate. For example, consider an executable linked bind-deferred, which calls a function foo() defined in an implicitly loaded library. Before the actual call is made, if it explicitly loads a shared library (using shl_load(3X) with BIND_FIRST) having a definition for foo() when foo() is finally called, it is resolved from the explicitly-loaded library. But after running fastbind, the symbol foo() is resolved from the implicitly-loaded library.

For more information about fastbind and how to improve program start-up time, see Improving Shared Library Start-Up Time with fastbind .

Example
  • To run fastbind on the executable file a.out:

    $fastbind a.out

  • To later remove the fastbind information from the executable file a.out

    $fastbind -n a.out

Finding Object Library Ordering Relationships with lorder(1)

The lorder command finds the ordering relation for an object library. You can specify one or more object or archive library files (see ar(1)) on the command line or read those files from standard input. The standard output is a list of pairs of object file names, meaning that the first file of the pair refers to external identifiers defined in the second.

You can process the output with tsort to find an ordering of a library suitable for one-pass access by ld (see tsort(1) and ld(1)). The linker ld is capable of multiple passes over an archive in the archive format and does not require that you use lorder when building an archive. Using the lorder command may, however, allow for a slightly more efficient access of the archive during the link-edit process.

The symbol table maintained by ar allows ld to randomly access symbols and files in the archive, making the use of lorder unnecessary when building archive libraries (see ar(1)).

The lorder command overlooks object files whose names do not end with .o, even when contained in library archives, and attributes their global symbols and references to some other file.

Examples
  • Build a new library from existing .o files:

    $ar cr library `lorder *.o | tsort`

  • When creating libraries with so many objects that the shell cannot properly handle the *.o expansion, the following technique may prove useful:

    $ls |grep '.o$'|lorder|tsort|xargs ar cq library