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

This chapter describes the linker toolset, which provides several tools to help you find symbols, display and modify object files, and determine link order. Some of these tools are specific to a particular object file type. Others are available in both 32-bit and 64-bit mode.

The following table lists the linker toolset.

Tool Mode Description

chatr

32-bit/64-bit

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

elfdump

64-bit

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

fastbind

32-bit/64-bit

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

ldd

32-bit/64-bit

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

lorder

32-bit/64-bit

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

nm

32-bit/64-bit

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

odump

32-bit

Displays the contents of a SOM object file. See the odump(1).

size

32-bit/64-bit

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

strip

32-bit/64-bit

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.


Using chatr for 32-bit Program Attributes

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

To Use the option

32-bit mode only: Set the file's magic number to SHARE_MAGIC.

-n

32-bit mode only: Set the file's magic number to DEMAND_MAGIC.

-q

32-bit mode only: Change the file's magic number from EXEC_MAGIC to SHMEM_MAGIC.

-M

32-bit mode only: Change the file's magic number from SHMEM_MAGIC to EXEC_MAGIC.

-N

Use immediate binding for all libraries loaded at program startup.

-B immediate

Use deferred binding for all libraries loaded at program startup.

-B deferred

Use nonfatal binding. Must be specified with -B immediate or -B deferred.

-B nonfatal

Use restricted binding. Must be specified with -B immediate or -B deferred.

-B restricted

Enable run-time use of the path list specified with the +b option at link time.

+b enable

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

Disable run-time use of the path list specified with the +b option at link time.

+b disable

Enable the use of the SHLIB_PATH environment variable to perform run-time path list lookup of shared libraries.

+s enable

Disable the use of the SHLIB_PATH environment variable to perform run-time path list lookup of shared libraries.

+s disable

32-bit mode only: Use default library path stored in the executable even if path lists are provided. That is, prevent a library from looking up a path list.

+l libname

32-bit mode only: Subject a library to path list lookup if directory path lists are provided. Useful for libraries that were specified with a full path name at link time.

-l libname

Set the virtual memory page size for data segments.

+pd size

Set the virtual memory page size for instructions.

+pi size

Assist branch prediction on PA-RISC 2.0 systems. Programs must be linked with +Ostaticprediction.

+k

Request static branch prediction.

+r

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


Using chatr for 64-bit Program Attributes

In 64-bit mode, chatr supports two different command syntaxes. One is compatible with the 32-bit command. Use it to modify files that have only a single text segment and data segment. The second command syntax allows you specify selected segments to modify. The following sections list the additional 64-bit mode options for the chatr command.

For the 32-bit compatible syntax

To Use the option

Set the modification bit for the file's data segment(s).

+md

Set the modification bit for the file's text segment(s).

+mi

Set the code bit for the file's data segment(s).

+cd

Set the code bit for the file's text segment(s).

+ci

Enable lazy swap on all data segments. Do not use with non-data segments.

+z

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

-z

For the 64-bit only syntax

To Use the option

Set the code bit for a specified segment.

+c

Enables or disables lazy swap allocation for dynamically allocated segments (such as the stack or heap).

+dz

Set the modification bit for a specified segment.

+m

Set the page size for a specified segment.

+p

Identify a segment using a segment index number.

+si

Identify a segment using an address.

+sa

Use all segments in the file for a set of attribute modifications.

+sall

Enable lazy swap on a specific segment (using the second command syntax). Do not use with non-data segments.

+z

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

-z

Viewing Symbols in an Object file with nm(1)

The nm 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 Use the option

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

-A

64-bit mode ELF files only: 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.

A

absolute

B

bss symbol

C

common symbol

D

data symbol

R

section region

S

tstorage symbol (32-bit mode SOM files only) If the symbol is local (nonexternal), the type letter is in lowercase. If the symbol is a secondary definition, the type letter is followed by the letter S. Note that -p is not compatible with -P.

T

text symbol

U

undefined

-p

Display information in a portable output format to standard output. Note that -p is not compatible with -P.

-P

32-bit mode SOM files only: Silence some warning messages.

-q

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

-r

64-bit mode ELF files only: Print the section index instead of the section name.

-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

32-bit mode SOM files only: Truncate every name that would otherwise overflow its column and place an asterisk as the last character in the displayed name to mark it as truncated. If -A or -r is also specified, the file prefix is truncated first.

By default, nm prints the entire name of the symbols listed. Because object files can have symbol names with an arbitrary number of characters, a name that is longer than the width of the column set aside for names overflows its column, forcing every column after the name to be misaligned.

-T

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

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


Note

The elfdump command works on 64-bit executables or shared libraries.


The elfdump 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 Use the option

Symbol table entries.

-t

Archive headers from an archive library.

-a

String table(s).

-c

File header.

-f

Global symbols from an archive.

-g

Section headers.

-h

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

-L

Optional headers (program headers).

-o

Relocations.

-r

Section contents.

-s

Unwind table.

-U

Versioned symbols.

-tv

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

Option Modifies Causes elfdump to

-H

all

Select output format in hexadecimal, octal, or decimal.

-p

all

Suppress title printing.

-S

-h,-o

Display headers in short format.

-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.

+s name

-c, -t

Display the section specified by name.

-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.

-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.

Viewing library dependencies with ldd(1)

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

Executable

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

Shared library

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

The ldd command uses the same algorithm as the dynamic loader (/usr/lib/dld.sl and /usr/lib/pa20_64/dld.sl) 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 the optional list of symbol resolution problems to stderr.

To Use the option

32-bit mode only: Used in conjunction with -d and/or -r, force dld.sl to bind all dependent libraries and report unsats. By default the smartbind mechanism in dld.sl only binds libraries whose symbols are explicitly referenced.

-b

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

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

The size 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 display information for your specified files:

To display Use the option

Sizes in decimal (default).

-d

Sizes in octal.

-o

Sizes in hexadecimal.

-x

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 size, physical address, and virtual address.

-v

64-bit mode only: Size of each allocatable section.

-f

64-bit mode only: Size and permission bits of each loadable segment=.

-F

64-bit mode only: Sizes of non loadable segments or non allocatable sections.

-n

Reducing Storage Space with strip(1)

The strip 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

Do not strip static or external symbol information.

-x

32-bit mode only: Reset the relocation indexes into the symbol table. This option allows strip to be run on relocatable files, in which case the effect is also to strip only symbolic debugging information and unloadable data.

-r

Print the version of the strip command to stderr.

-V


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. strip 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/dld.sl for 32-bit mode or /usr/lib/pa20_64/dld.sl for 64-bit mode) detects that this information is available, and uses it to bind the executable instead of using the standard search method for binding the symbols.

Because fastbind writes the fastbind information in the executable file, 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 fastbind on the executable again. The fastbind command automatically erases the old fastbind information and generate the new one.

To 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. When you invoke fastbind with the -u option however, it allows unresolved symbols.

-u

The 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 performance, see Improving Shared Library Start-Up Time with fastbind .

Examples

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