Page 2 - Legal Notices
2 Legal Notices The information contained in this document is subject to change withoutnotice. Hewlett-Packard makes no warranty of any kind with regard to thismanual, including, but not limited to, the implied warranties ofmerchantability and fitness for a particular purpose. Hewlett-Packardshall n...
Page 5 - Contents; What Happens When You Compile and Link a Program
Contents 5 Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Printing History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15 1. What's New in Recent Releases PA-RISC Changes in Hardware Compatib...
Page 8 - Creating and Using Libraries
8 Contents 4. Linker Tools Changing a Program's Attributes with chatr(1) . . . . . . . . . . . . . . . . . . 104 Using chatr for 32-bit Program Attributes . . . . . . . . . . . . . . . . . . . . 104Using chatr for 64-bit Program Attributes . . . . . . . . . . . . . . . . . . . . 105 Viewing Symbols ...
Page 10 - Shared Library Management Routines
10 Contents Using Shared Libraries in 64-bit mode . . . . . . . . . . . . . . . . . . . . . . . . . 176 Internal Name Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176Dynamic Path Searching for Shared Libraries . . . . . . . . . . . . . . . . . 177Shared Library Symbol...
Page 11 - Ways to Improve Performance
Contents 11 The dlsym Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .245The dlget Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248The dlmodinfo Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...
Page 15 - Preface; Printing History
15 Preface This Guide covers the following topics: • Chapter 1, “What's New in Recent Releases,” lists new features added in recent releases. • Chapter 2, “What Happens When You Compile and Link a Program,” provides details on compiling and linking programs. • Chapter 3, “Linker Tasks,” lists many w...
Page 19 - Chapter 1; What's New in Recent Releases; For This Release
Chapter 1 19 What's New in Recent Releases 1 What's New in Recent Releases This section contains information about recent releases of the HP-UXlinker toolset: For This Release The HP-UX 11.00 linker toolset contains new features: If you use the 32-bit mode linker toolset, see the following items: • ...
Page 20 - For Previous Releases
20 Chapter 1 What's New in Recent Releases • “The dlopen Shared Library Management Routines” on page 240 describes the dl* family of shared library management routines for 64-bit mode. • “BIND_BREADTH_FIRST Modifier” on page 222 describes the flag added to the shl_load routine to modify search behav...
Page 21 - PA-RISC Changes in Hardware Compatibility; NOTE
Chapter 1 21 What's New in Recent Releases PA-RISC Changes in Hardware Compatibility PA-RISC Changes in HardwareCompatibility The HP-UX 10.20 release introduced HP 9000 systems based on thePA-RISC 2.0 architecture. Also, beginning with that release, HPcompilers by default generate executable code fo...
Page 24 - 4-bit Mode ELF Object File Format; Option
24 Chapter 1 What's New in Recent Releases 64-bit Mode ELF Object File Format 64-bit Mode ELF Object File Format Starting with HP-UX release 11.00, the 64-bit linker toolset supports theELF (executable and linking format) object file format. The 64-bit linkertoolset provides new tools to display and...
Page 25 - New Features for 64-bit Mode Linking; 4-bit Mode Linker Options
Chapter 1 25 What's New in Recent Releases New Features for 64-bit Mode Linking New Features for 64-bit Mode Linking This section introduces new features of the 64-bit linker for HP-UXrelease 11.00. 64-bit Mode Linker Options The ld(1) command supports the following new options in 64-bit mode: Optio...
Page 26 - Symbol
26 Chapter 1 What's New in Recent Releases New Features for 64-bit Mode Linking 64-bit Mode Linker-defined Symbols The 64-bit linker reserves the following symbol names: a. The linker accepts but ignores this option in 32-bit mode. It creates an executable (a.out). +noenvvar Instructs the dynamic lo...
Page 28 - Option or
28 Chapter 1 What's New in Recent Releases 64-bit Mode Link-time Differences 64-bit Mode Link-time Differences The 64-bit mode linker toolset does not support the following 32-bit modefeatures. Option or Behavior Description -A name Specifies incremental loading. 64-bit applicationsmust use shared l...
Page 30 - 4-bit Mode Run Time Differences; Linker and Loader
30 Chapter 1 What's New in Recent Releases 64-bit Mode Run Time Differences 64-bit Mode Run Time Differences Applications compiled and linked in 64-bit mode use a run-time dynamicloading model similar to other SVR4 systems. There are two main areaswhere program startup changes in 64-bit mode: • Dyna...
Page 32 - Changes in Future Releases
32 Chapter 1 What's New in Recent Releases Changes in Future Releases Changes in Future Releases The following changes are planned in future releases. • Support of ELF 32 object file format A future release will support the ELF 32 object file format. • Future of ld +compat option The +compat linker ...
Page 33 - Online Help for Linker and Libraries; Accessing Help with ld +help; Accessing Help with the HP CDE Front Panel; Accessing Help with the charhelp Command
Chapter 1 33 What's New in Recent Releases Online Help for Linker and Libraries Online Help for Linker and Libraries The Linker and Libraries Online User Guide is available for HP 9000Series 700 and 800 systems. The online help comes with HP C, HP C++,HP aC++, HP Fortran, HP Pascal, and HP Micro Foc...
Page 35 - Chapter 2
Chapter 2 35 What Happens When You Compile and Link a Program 2 What Happens When YouCompile and Link a Program This chapter describes the process of compiling and linking a program. • “Compiling Programs on HP-UX: An Example” provides an overview of compiling on HP-UX. • “Looking “inside” a Compile...
Page 37 - High-Level View of the Compiler
Chapter 2 37 What Happens When You Compile and Link a Program Compiling Programs on HP-UX: An Example sum += n; /* add n to sum */ return sum; /* return the value of sum */} main() /* begin main program */{ int n; /* number to input from user */ printf("Enter a number: "); /* prompt for numb...
Page 38 - Looking “inside” a Compiler; Looking “inside” a Compiler
38 Chapter 2 What Happens When You Compile and Link a Program Looking “inside” a Compiler Looking “inside” a Compiler On the surface, it appears as though an HP-UX compiler generates an a.out file by itself. Actually, an HP-UX compiler is a driver that calls other commands to create the a.out file. ...
Page 40 - What is an Object File?; Local Definitions; Global Definitions; External References
40 Chapter 2 What Happens When You Compile and Link a Program What is an Object File? What is an Object File? An object file is basically a file containing machine languageinstructions and data in a form that the linker can use to create anexecutable program. Each routine or data item defined in an ...
Page 41 - Compiler-Linker Interaction
Chapter 2 41 What Happens When You Compile and Link a Program Compiler-Linker Interaction Compiler-Linker Interaction As described in “Looking “inside” a Compiler”, the compilersautomatically call ld to create an executable file. To see how the compilers call ld , run the compiler with the -v (verbo...
Page 42 - Linking Programs on HP-UX; Matching the External Reference to sum_n
42 Chapter 2 What Happens When You Compile and Link a Program Linking Programs on HP-UX Linking Programs on HP-UX The HP-UX linker, ld , produces a single executable file from one or more input object files and libraries. In doing so, it matches externalreferences to global definitions contained in ...
Page 43 - The crt0.o Startup File; The Program's Entry Point
Chapter 2 43 What Happens When You Compile and Link a Program Linking Programs on HP-UX The crt0.o Startup File Notice in the example in “Compiler-Linker Interaction” that the firstobject file on the linker command line is /opt/langtools/lib/crt0.o , even though this file was not specified on the co...
Page 44 - Magic Numbers
44 Chapter 2 What Happens When You Compile and Link a Program Linking Programs on HP-UX In 64-bit mode for dynamically bound executables, the entry point,defined by the symbol $START$ in the dynamic loader ( dld.sl ). The a.out File The information contained in the resulting a.out file depends on wh...
Page 45 - File Permissions; To set the magic
Chapter 2 45 What Happens When You Compile and Link a Program Linking Programs on HP-UX Table 2-1 32-bit Mode Magic Number Linker Options An executable file's magic number can also be changed using the chatr command (see “Changing a Program's Attributes with chatr(1)” on page104). However, chatr can...
Page 46 - Linking with Libraries; Library Naming Conventions; Default Libraries
46 Chapter 2 What Happens When You Compile and Link a Program Linking with Libraries Linking with Libraries In addition to matching external references to global definitions in objectfiles, ld matches external references to global definitions in libraries. A library is a file containing object code ...
Page 47 - The Default Library Search Path
Chapter 2 47 What Happens When You Compile and Link a Program Linking with Libraries $ f77 -v sumnum.f ... /usr/ccs/bin/ld -x /opt/langtools/lib/crt0.o \ sumnum.o -lcl -lisamstub -lc The Default Library Search Path By default, ld searches for libraries in the directory /usr/lib . (If the -p or -G co...
Page 48 - Running the Program; Loading Programs: exec; entry point — usually in; Binding Routines to a Program
48 Chapter 2 What Happens When You Compile and Link a Program Running the Program Running the Program An executable file is created after the program has been compiled andlinked. The next step is to run or load the program. Loading Programs: exec When you run an executable file created by ld , the p...
Page 49 - Deferred Binding is the Default
Chapter 2 49 What Happens When You Compile and Link a Program Running the Program Deferred Binding is the Default To accelerate program startup time, routines in a shared library are notbound until referenced. (Data items are always bound at programstartup.) This deferred binding of shared library r...
Page 50 - Linker Thread-Safe Features
50 Chapter 2 What Happens When You Compile and Link a Program Linker Thread-Safe Features Linker Thread-Safe Features Beginning with the HP-UX 10.30 release, the dynamic loader ( dld.sl ) and its application interface library ( libdld.sl ) are thread-safe. Also, beginning with the HP-UX 10.30 releas...
Page 51 - Chapter 3; Linker Tasks
Chapter 3 51 Linker Tasks 3 Linker Tasks You have a great deal of control over how the linker links your programor library by using ld command-line options. • Using the Compiler Command • “Changing the Default Library Search Path with -Wl, -L” • “Getting Verbose Output with -v” • “Passing Linker Opt...
Page 53 - Using the Compiler to Link
Chapter 3 53 Linker Tasks Using the Compiler to Link Using the Compiler to Link In many cases, you use your compiler command to compile and linkprograms. Your compiler uses options that directly affect the linker. Changing the Default Library Search Pathwith -Wl, -L By default, the linker searches t...
Page 54 - Getting Verbose Output with -v
54 Chapter 3 Linker Tasks Using the Compiler to Link The LPATH environment variable provides another way to override the default search path. For details, see “Changing the Default LibrarySearch Path with -L and LPATH”. Getting Verbose Output with -v The -v option makes a compiler display verbose in...
Page 55 - Renaming the Output File with -o; Specifying Libraries with -l; Linking with the crt0.o Startup File in 32-bit mode
Chapter 3 55 Linker Tasks Using the Compiler to Link Renaming the Output File with -o The -o name option causes ld to name the output file name instead of a.out . For example, to compile a C program prog.c and name the resulting file sum_num : $ cc -Aa -o sum_num prog.c Compile using -o option. $ su...
Page 57 - Using Linker commands; Linking with the 32-bit crt0.o Startup File
Chapter 3 57 Linker Tasks Using Linker commands Using Linker commands This section describes linker commands for the 32-bit and 64-bit linker. NOTE Unless otherwise noted, all examples show 32-bit behavior. Linking with the 32-bit crt0.o Startup File In 32-bit mode, you must always include crt0.o on...
Page 58 - Augmenting the Default Linker Search Path with -L; Example Using -B immediate
58 Chapter 3 Linker Tasks Using Linker commands Augmenting the Default Linker Search Path with -L The -L option to ld also allows you to add additional directories to the search path. If -L libpath is specified, ld searches the libpath directory before the default places. For example, suppose you ha...
Page 59 - Nonfatal Shared Library Binding with -B nonfatal; Restricted Shared Library Binding with -B restricted
Chapter 3 59 Linker Tasks Using Linker commands Nonfatal Shared Library Binding with -B nonfatal The linker also supports nonfatal binding, which is useful with the -B immediate option. Like immediate binding, nonfatal immediate binding causes all required symbols to be bound at program startup. The...
Page 60 - Example Using -B symbolic
60 Chapter 3 Linker Tasks Using Linker commands • The program calls shl_definesym to define a symbol that is already defined in a library that was loaded at program startup. If such a program is linked with -B immediate , references to symbols will be bound at program startup, regardless of whether ...
Page 62 - Direct call path
62 Chapter 3 Linker Tasks Using Linker commands Figure 3-1 Symbols inside a Shared Library Visible with -B symbolic Case 2: Building a Shared Library with -h or +e. The -h (hide symbol) and +e (export symbol) options can also optimize the call path in a shared library for symbols that are explicitly...
Page 63 - Choosing Archive or Shared Libraries with -a; Option Settings to -a
Chapter 3 63 Linker Tasks Using Linker commands In both cases, main2 will not be able to resolve its reference togal_to_liter() because only the convert_rtn() symbol is exported as shown below: Choosing Archive or Shared Libraries with -a If both an archive and shared version of a particular library...
Page 65 - Overview of Dynamic Linking
Chapter 3 65 Linker Tasks Using Linker commands Dynamic Linking with -A and -R This section describes how to do dynamic linking — that is, how to addan object module to a running program. Conceptually, it is very similar toloading a shared library and accessing its symbols (routines and data).In fac...
Page 66 - Step 3: Link the module from the running application.
66 Chapter 3 Linker Tasks Using Linker commands 8. Get the addresses of routines and data that are referenced in the module. Step 1: Determine how much space is required to load themodule. There must be enough contiguous memory to hold the module's text, data, and bss segments. You can make a libera...
Page 67 - Step 5: Read the text and data into the allocated space.
Chapter 3 67 Linker Tasks Using Linker commands The useful members of the som_exec_auxhdr structure are: .exec_tsize Size of text (code) segment. .exec_tmem Address at which to load the text (already adjusted foroffset specified by the -R linker option). .exec_tfile Offset into file (location) where...
Page 68 - An Example Program
68 Chapter 3 Linker Tasks Using Linker commands Use an assembly language routine named flush_cache (see “The flush_cache Function” in this chapter). You must assemble this routineseparately (with the as command) and link it with the main program. Step 8: Get the addresses of routines and data that a...
Page 69 - The Build Environment.; Makefile Used to Create Dynamic Link Files
Chapter 3 69 Linker Tasks Using Linker commands The Build Environment. Before seeing the program's source code, it may help to see how the program and the various object files werebuilt. The following shows the makefile used to generate the variousfiles. Makefile Used to Create Dynamic Link Files CF...
Page 70 - dynprog.c — Example Dynamic Link and Load Program
70 Chapter 3 Linker Tasks Using Linker commands Note that the line CFLAGS =… causes any C files to be compiled in ANSI mode ( -Aa ) and causes the compiler to search for routines that are defined in the Posix standard ( -D_POSIX_SOURCE ). For details on using make refer to make(1). Source for dynpro...
Page 72 - Include Directives for dynload.c
72 Chapter 3 Linker Tasks Using Linker commands glorp(“foo”); (*counter_ptr) ++; /* update counter indirectly with globalpointer */} void bar(){ glorp(“bar”); counter ++; /* update counter directly */} /**************************************************************** * file2.c - Global counter varia...
Page 75 - C Source for dyn_load Function
Chapter 3 75 Linker Tasks Using Linker commands The base_prog, obj_files, and dest_file parameters are the sameparameters supplied to alloc_load_space . The addr parameter is the address returned by alloc_load_space , and the entry_pt parameter specifies a symbol name that you want to act as the ent...
Page 78 - Assembly Language Source for flush_cache Function
78 Chapter 3 Linker Tasks Using Linker commands /*----------------------------------------------------------------- * STEP 6: Return a pointer to the entry point specified by -e: */ entry_pt_addr = (unsigned int) aux_hdr.exec_entry; return ((void *) entry_pt_addr);} The flush_cache Function . Since ...
Page 79 - Exporting Symbols with +e
Chapter 3 79 Linker Tasks Using Linker commands copy %arg1,%arg3 ; Copy offset from GR25 to GR23 fdc %arg1(0,%arg0) ; Flush data [email protected]+offsetloop1 addib,>,n -16,%arg1,loop1 ; Decrement offset by cache linesize fdc %arg1(0,%arg0) ; Flush data [email protected]+offset ; flush first word...
Page 81 - Exporting Symbols with +ee; Hiding Symbols with -h
Chapter 3 81 Linker Tasks Using Linker commands Exporting Symbols with +ee Like the +e option, the +ee option allows you to export symbols. Unlike the +e option, the option does not alter the visibility of any other symbols in the file. It exports the specified symbol, and does not hide any of thesy...
Page 84 - Moving Libraries after Linking with +b
84 Chapter 3 Linker Tasks Using Linker commands As mentioned previously in the section “Exporting Symbols from mainwith -E”, the -E option forces the export of all symbols from the program, regardless of whether they are referenced by shared libraries on thelinker command line. The +e option allows ...
Page 85 - Specifying a Path List with +b; The Path List
Chapter 3 85 Linker Tasks Using Linker commands Specifying a Path List with +b The syntax of the +b option is +b path_list where path_list is the list of directories you want the dynamic loader tosearch at run time. For example, the following linker command causesthe path .:/app/lib:: to be stored i...
Page 86 - Specifying a Path List with +s and SHLIB_PATH; Passing Linker Options in a file with -c
86 Chapter 3 Linker Tasks Using Linker commands the previous example were /apps/lib::xyz , the dynamic loader would search for /apps/lib/libfoo.sl , /usr/local/lib/libfoo.sl , then ./xyz/libfoo.sl . If the dynamic loader cannot find a required library in any of thedirectories specified in the path l...
Page 87 - Passing Linker Options with LDOPTS
Chapter 3 87 Linker Tasks Using Linker commands +e reverse_tree+e preorder_traversal+e shift_reduce_parse ... Note that the linker ignores lines in that option file that begin with apound sign ( # ). You can use such lines as comment lines or to temporarily disable certain linker options in the file...
Page 90 - Using 64-bit Mode Linker Options
90 Chapter 3 Linker Tasks Using 64-bit Mode Linker Options Using 64-bit Mode Linker Options This section introduces 64-bit-only linker options. Using the 64-bit Mode Linker with +compat or+std In the HP-UX 11.0 release, the linker toolset supports extended featuresfor linking in 64-bit mode. Since c...
Page 91 - Using the 64-bit Linker with +std for Standard Mode
Chapter 3 91 Linker Tasks Using 64-bit Mode Linker Options • +b first means dld looks at the RPATH first when searching for dependent shared libraries. To get the default RPATH , you must specify ld +b . This instructs the linker to construct a default RPATH consisting of the -L directories and LPAT...
Page 93 - Linking Shared Libraries with -dynamic
Chapter 3 93 Linker Tasks Using 64-bit Mode Linker Options • Looks at the environment variables first, followed by RPATH , and the default directories by default when doing dynamic path searching forstandard-mode dependentshared libraries. Linking Shared Libraries with -dynamic Use the -dynamic opti...
Page 95 - Changing Mapfiles with -k and +nodefaultmap
Chapter 3 95 Linker Tasks Using 64-bit Mode Linker Options Hiding Symbols from export with+hideallsymbols Use the +hideallsymbols option to hide all symbols to prevent the linker from exporting them in a shared link. In the following example, main() exports func() and test() . Using +hideallsymbols ...
Page 96 - Linking in 32-bit Mode Style with +compat
96 Chapter 3 Linker Tasks Using 64-bit Mode Linker Options Ignoring Dynamic Path EnvironmentVariables with +noenvvar Use the +noenvvar to instruct the dynamic loader not to look at the environment variables relating to dynamic path searching at runtime. Itignores LD_LIBRARY_PATH and SHLIB_PATH envir...
Page 97 - Selecting Verbose Output with +vtype; Parameter
Chapter 3 97 Linker Tasks Using 64-bit Mode Linker Options Selecting Verbose Output with +vtype Use the +vtype option to get verbose output about specified elements of the link operation. The following values specify the type: Parameter Description files Dump information about each object file loade...
Page 98 - Linking with the 64-bit crt0.o Startup File
98 Chapter 3 Linker Tasks Using 64-bit Mode Linker Options ld main.o +vtype all -L. -lfile1 -lfile2 -lcLoading main.o:main.o:main is DEFINED GLOBAL FUNCprintf is UNDEF GLOBAL FUNClib1_func is UNDEF GLOBAL FUNClib2_func is UNDEF GLOBAL FUNCmain.o: section .text PROG_BITS AX 116 8 added to textsegment...
Page 99 - Linker Compatibility Warnings
Chapter 3 99 Linker Tasks Linker Compatibility Warnings Linker Compatibility Warnings Beginning with the HP-UX 10.20 release, the linker generatescompatibility warnings. These warnings include HP 9000 architectureissues, as well as linker features that may change over time.Compatibility warnings can...
Page 103 - Linker Tools; Tool
103 4 Linker Tools This chapter describes the linker toolset, which provides several tools tohelp you find symbols, display and modify object files, and determine linkorder. Some of these tools are specific to a particular object file type;others are available in both 32-bit and 64-bit mode. The fol...
Page 104 - Chapter 4; Using chatr for 32-bit Program Attributes
104 Chapter 4 Linker Tools Changing a Program's Attributes with chatr(1) Changing a Program's Attributes withchatr(1) The chatr command (see chatr(1)) allows you to change various program attributes that were determined at link time. When run without anyoptions, chatr displays the attributes of the ...
Page 105 - Using chatr for 64-bit Program Attributes
Chapter 4 105 Linker Tools Changing a Program's Attributes with chatr(1) a. If +b enable and +s enable are both specified, the order in which they appear determines which search path is used first. Using chatr for 64-bit Program Attributes In 64-bit mode, chatr supports two different command syntaxe...
Page 107 - Viewing Symbols in an Object file with nm(1); To
Chapter 4 107 Linker Tools Viewing Symbols in an Object file with nm(1) Viewing Symbols in an Object file withnm(1) The nm(1) command displays the symbol table of each specified object.file can be a relocatable object file or an executable object file, or anarchive of relocatable or executable objec...
Page 111 - Viewing the Contents of an Object File with elfdump(1); To view the contents.
Chapter 4 111 Linker Tools Viewing the Contents of an Object File with elfdump(1) Viewing the Contents of an Object Filewith elfdump(1) NOTE The elfdump command works on 64-bit executables or shared libraries. The elfdump(1) command displays information contained in ELF formatobject files, archives,...
Page 115 - Viewing the Size of Object File Elements with size(1)
Chapter 4 115 Linker Tools Viewing the Size of Object File Elements with size(1) Viewing the Size of Object File Elementswith size(1) The size(1) command produces section size information for each sectionin your specified object files. It displays the size of the text, data and bss(uninitialized dat...
Page 118 - To do this
118 Chapter 4 Linker Tools Improving Program Start-up with fastbind(1) Improving Program Start-up withfastbind(1) The fastbind(1) command prepare an incomplete executable for fasterprogram start-up. It can improve the start-up time of programs that useshared libraries (incomplete executables) by sto...
Page 119 - Example
Chapter 4 119 Linker Tools Improving Program Start-up with fastbind(1) The 32-bit mode fastbind command does not work with EXEC_MAGIC executables. fastbind effectively enforces the binding modes bind-restricted and bind-immediate. For example, consider an executable linkedbind-deferred, which calls ...
Page 120 - Finding Object Library Ordering Relationships with lorder(1)
120 Chapter 4 Linker Tools Finding Object Library Ordering Relationships with lorder(1) Finding Object Library OrderingRelationships with lorder(1) The lorder command finds the ordering relation for an object library. Youcan specify one or more object or archive library files (see ar(1)) on thecomma...
Page 121 - Chapter 5; Creating and Using Libraries
Chapter 5 121 Creating and Using Libraries 5 Creating and Using Libraries Many libraries come with HP-UX. You can also create and use your ownlibraries on HP-UX. This chapter provides information on the followingtopics: • General Information about Shared and Archive Libraries • “Overview of Shared a...
Page 122 - Overview of Shared and Archive Libraries
122 Chapter 5 Creating and Using Libraries Overview of Shared and Archive Libraries Overview of Shared and ArchiveLibraries HP-UX supports two kinds of libraries: archive and shared. A sharedlibrary is also called a dll (dynamically linked library), particularly inthe context of the 64-bit mode link...
Page 125 - What are Archive Libraries?; Linking with an Archive Library
Chapter 5 125 Creating and Using Libraries What are Archive Libraries? What are Archive Libraries? An archive library contains one or more object files and is created withthe ar command. When linking an object file with an archive library, ld searches the library for global definitions that match up...
Page 126 - What are Shared Libraries?; The Dynamic Loader dld.sl
126 Chapter 5 Creating and Using Libraries What are Shared Libraries? What are Shared Libraries? Like an archive library, a shared library contains object code. However, ld treats shared libraries quite differently from archive libraries. When linking an object file with a shared library, ld does no...
Page 127 - Caution on Using Dynamic Library Searching
Chapter 5 127 Creating and Using Libraries What are Shared Libraries? Default Behavior When Searching forLibraries at Run Time By default, if the dynamic loader cannot find a shared library from thelist, it generates a run-time error and the program aborts. For example,in 32-bit mode, suppose that d...
Page 128 - Example Program Comparing Shared and Archive Libraries; Two Processes Sharing libc
128 Chapter 5 Creating and Using Libraries Example Program Comparing Shared and Archive Libraries Example Program Comparing Sharedand Archive Libraries As an example, suppose two separate programs, prog1 and prog2 , use shared libc routines heavily. Suppose that the a.out portion of prog1 is 256Kb i...
Page 130 - Shared Libraries with Debuggers, Profilers, and Static Analysis
130 Chapter 5 Creating and Using Libraries Shared Libraries with Debuggers, Profilers, and Static Analysis Shared Libraries with Debuggers,Profilers, and Static Analysis As of the HP-UX 10.0 release, debugging of shared libraries is supportedby the HP/DDE debugger. For details on how to debug shared...
Page 131 - Creating Archive Libraries; relocatable object code.; Overview of Creating an Archive Library
Chapter 5 131 Creating and Using Libraries Creating Archive Libraries Creating Archive Libraries Two steps are required to create an archive library: 1. Compile one or more source files to create object files containing relocatable object code. 2. Combine these object files into a single archive lib...
Page 132 - Contents of an Archive File
132 Chapter 5 Creating and Using Libraries Creating Archive Libraries Figure 5-4 summarizes the procedure for creating archive libraries fromthree C source files ( file1.c , file2.c , and file3.c ). The process is identical for other languages, except that you would use a differentcompiler. Figure 5...
Page 133 - Example of Creating an Archive Library; length.c - Routine to Convert Length Units; volume.c - Routine to Convert Volume Units
Chapter 5 133 Creating and Using Libraries Creating Archive Libraries cosh.o Object modules are displayed. erf.ofabs.ofloor.o . . . . This indicates that the library was built from object files named cosh.o , erf.o , fabs.o , floor.o , and so forth. In other words, module names are the same as the n...
Page 134 - Replacing or Adding an Object Module
134 Chapter 5 Creating and Using Libraries Creating Archive Libraries Then combine the .o files by running ar with the r key, followed by the library name (say libunits.a ), followed by the names of the object files to place in the library: $ ar r libunits.a length.o volume.o mass.oar: creating libu...
Page 135 - Deleting an Object Module
Chapter 5 135 Creating and Using Libraries Creating Archive Libraries Deleting an Object Module To delete an object module from a library, use the d key. For example, to delete volume.o from libunits.a : $ ar d libunits.a volume.o Delete volume.o. $ ar t libunits.a List the contents. length.omass.o ...
Page 136 - Archive Library Location
136 Chapter 5 Creating and Using Libraries Creating Archive Libraries $ ar tv libunits.arw-rr 265/ 20 230 Feb 2 17:19 1990 length.o rw-rr 265/ 20 228 Feb 2 16:25 1990 mass.o rw-rr 265/ 20 230 Feb 2 16:24 1990 volume.o The next example replaces length.o in libunits.a , only if length.o is more recent...
Page 138 - Creating Shared Libraries
138 Chapter 5 Creating and Using Libraries Creating Shared Libraries Creating Shared Libraries Two steps are required to create a shared library: 1. “Creating Position-Independent Code (PIC)” by compiling with +z . 2. “Creating the Shared Library with ld” by linking with -b . Shown below are the com...
Page 139 - Creating the Shared Library with ld
Chapter 5 139 Creating and Using Libraries Creating Shared Libraries Example Using +z Suppose you have some C functions, stored in length.c , that convert between English and Metric length units. To compile these routines andcreate PIC object files with the C compiler, you could use this command: $ ...
Page 140 - Shared Library Dependencies
140 Chapter 5 Creating and Using Libraries Creating Shared Libraries $ cc -Aa -c +z length.c volume.c mass.clength.c:volume.c:mass.c:$ ld -b -o libunits.sl length.o volume.o mass.o Once the library is created, be sure it has read and execute permissionsfor all users who will use the library. For exa...
Page 143 - Placing Loaded Libraries in the Search List
Chapter 5 143 Creating and Using Libraries Creating Shared Libraries 3. mark A , load A 4. mark D , load D 5. mark Q , load Q 6. traverse D 7. D is already marked, so skip D 8. traverse Q 9. Q is already marked, so skip Q 10. traverse Q 11. Q is already marked, so skip Q 12. traverse B 13. mark B , ...
Page 144 - Updating a Shared Library; Incompatible Changes to a Shared Library; Shared Library Location
144 Chapter 5 Creating and Using Libraries Creating Shared Libraries libP → libA → libD → libQ → libB → <current search list> Updating a Shared Library The ld command cannot replace or delete object modules in a shared library. Therefore, to update a shared library, you must relink the library...
Page 145 - Improving Shared Library Performance; Using Profile-Based Optimization on Shared Libraries
Chapter 5 145 Creating and Using Libraries Creating Shared Libraries Prior to the HP-UX 9.0 release, moving a shared library caused anyprograms that were linked with the library to fail when they tried to loadthe library. Prior to 9.0, you were required to relink all applications thatused the librar...
Page 146 - Placing Frequently-Called Routines Together
146 Chapter 5 Creating and Using Libraries Creating Shared Libraries You may be surprised to find that a shared library exports many moresymbols than necessary for code that uses the library. These extrasymbols add to the size of the library's symbol table and can evendegrade performance (since the ...
Page 148 - Making Shared Libraries Non-Writable; Using the +ESlit Option to cc
148 Chapter 5 Creating and Using Libraries Creating Shared Libraries y.od.o Notice that d.o is now closer to x.o and y.o , which call it. However, this is still not the best information to use because a.o and b.o are separated from x.o and y.o by the module e.o , which is not called by any modules. ...
Page 149 - Version Control with Shared Libraries; When to Use Shared Library Versioning
Chapter 5 149 Creating and Using Libraries Version Control with Shared Libraries Version Control with Shared Libraries HP-UX provides two ways to support incompatible versions of sharedlibrary routines. “Library-Level Versioning” describes how you createmultiple versions of a shared library. “Intra-...
Page 150 - Maintaining Old Versions of Library Modules; How to Use Library-Level Versioning
150 Chapter 5 Creating and Using Libraries Version Control with Shared Libraries • As a general rule, when an exported function is changed such that calls to the function from previously compiled object files shouldnot resolve to the new version, the change is incompatible. If thenew version can be ...
Page 151 - Creating a New, Incompatible Version of the Library
Chapter 5 151 Creating and Using Libraries Version Control with Shared Libraries 1. Name the first version of your shared library with an extension of .0 (that's the number zero), for example libA.0 . Use the +h option to designate the internal name of the library, for example, libA.0 : ld -b *.o -o...
Page 152 - The +h Option and Internal Names
152 Chapter 5 Creating and Using Libraries Version Control with Shared Libraries When you run a program that uses shared libraries and was linkedbefore HP-UX 10.0, the dynamic loader first attempts to open the sharedlibrary ending in .0 . If it cannot find that library, it attempts to open the libra...
Page 154 - Intra-Library Versioning
154 Chapter 5 Creating and Using Libraries Version Control with Shared Libraries Figure 5-6 With these links in place, the loader will load /X/libapp.0 when running the a.out file created above. New applications will link and run with /X/libapp.1 . NOTE Renaming the old version of the .0 version lib...
Page 155 - The Version Number Compiler Directive; Shared Library Dependencies and Version Control
Chapter 5 155 Creating and Using Libraries Version Control with Shared Libraries • “Shared Library Dependencies and Version Control” • “Adding New Versions to a Shared Library” • “Specifying a Version Date” The Version Number Compiler Directive With intra-library versioning, you assign a version num...
Page 156 - Adding New Versions to a Shared Library
156 Chapter 5 Creating and Using Libraries Version Control with Shared Libraries If a shared library lists a second shared library as a dependency, dld.sl will generate an error if the second shared library has a version numberwhich is older than the version number recorded with the dependency.This ...
Page 157 - Specifying a Version Date
Chapter 5 157 Creating and Using Libraries Version Control with Shared Libraries Specifying a Version Date When adding modules to a library for a particular release of the library,it is best to give all modules the same version date. For example, if youcomplete file1.o on 04/93, file2.o on 05/93, an...
Page 158 - Switching from Archive to Shared Libraries; Library Path Names; Relying on Undocumented Linker Behavior
158 Chapter 5 Creating and Using Libraries Switching from Archive to Shared Libraries Switching from Archive to SharedLibraries There are cases where a program may behave differently when linkedwith shared libraries than when linked with archive libraries. These arethe result of subtle differences i...
Page 159 - Absolute Virtual Addresses
Chapter 5 159 Creating and Using Libraries Switching from Archive to Shared Libraries More commonly, programmers may take advantage of undocumentedlinker behavior to minimize the size of routines copied into the a.out files from archive libraries. This is no longer necessary if all libraries areshar...
Page 160 - Stack Usage; Version Control
160 Chapter 5 Creating and Using Libraries Switching from Archive to Shared Libraries rearrange data in shared libraries, this is no longer guaranteed. Anotherexample is a function that assumes variables it declares statically (forexample, C static variables) reside below the reserved symbol _end in...
Page 161 - Debugger Limitations
Chapter 5 161 Creating and Using Libraries Switching from Archive to Shared Libraries Debugger Limitations Shared libraries can be debugged just like archive libraries with fewexceptions. For details on debugging shared libraries, refer to theHP/DDE Debugger User's Guide or the HP-UX Symbolic Debugg...
Page 162 - Summary of HP-UX Libraries
162 Chapter 5 Creating and Using Libraries Summary of HP-UX Libraries Summary of HP-UX Libraries What libraries your system has depends on what components werepurchased. For example, if you didn't purchase Starbase Display List,you won't have the Starbase Display List library on your system. HP-UX l...
Page 164 - Caution When Mixing Shared and Archive Libraries; Example 1: Unsatisfied Symbols
164 Chapter 5 Creating and Using Libraries Caution When Mixing Shared and Archive Libraries Caution When Mixing Shared andArchive Libraries Mixing shared and archive libraries in an application is notrecommended and should be avoided. That is, an application should useonly shared libraries or only a...
Page 166 - Problem
166 Chapter 5 Creating and Using Libraries Caution When Mixing Shared and Archive Libraries Figure 5-10 Compile the new f3() and rebuild the shared library lib3.sl : $ cc -c +z f3.c Compile to relocatable code . $ ld -b -o lib3.sl f3.o Create a new shared library. Figure 5-11 Problem Here's where th...
Page 171 - Example 3: Hidden Definitions
Chapter 5 171 Creating and Using Libraries Caution When Mixing Shared and Archive Libraries Example 3: Hidden Definitions This example shows how mixing archive libraries and shared librariescan lead to multiple definitions in the application and unexpectedresults. If one of the definitions happens t...
Page 176 - Using Shared Libraries in 64-bit mode; Internal Name Processing
176 Chapter 5 Creating and Using Libraries Using Shared Libraries in 64-bit mode Using Shared Libraries in 64-bit mode In the HP-UX 11.00 release, HP provides an industry-standard linkertoolset for programs linked in 64-bit mode. The new toolset consists of alinker, dynamic loader, object file class...
Page 177 - Dynamic Path Searching for Shared Libraries
Chapter 5 177 Creating and Using Libraries Using Shared Libraries in 64-bit mode • If the dependent library’s internal name contains a relative path, the internal name is inserted at the end of the path where the sharedlibrary is found at link time, replacing the library’s filename in the DT_HP_NEED...
Page 178 - Shared Library Symbol Binding Semantics; Link-Time Symbol Resolution in Shared Libraries
178 Chapter 5 Creating and Using Libraries Using Shared Libraries in 64-bit mode LD_LIBRARY_PATH and the SHLIB_PATH environment variable to add directories to the run time search path for shared libraries, unless the ld +noenvvar option is set. In the 32-bit mode of the linker toolset (selected by t...
Page 180 - Resolution of Unsatisfied Shared Library References
180 Chapter 5 Creating and Using Libraries Using Shared Libraries in 64-bit mode At link time, there is an outstanding unsatisfied symbol for afunc() when libB is found. The exported symbol for afunc() is not remembered after libA.sl is scanned. At run time, the afunc() symbol that is called is the ...
Page 181 - Promotion of Uninitialized Global Data Items
Chapter 5 181 Creating and Using Libraries Using Shared Libraries in 64-bit mode If these files are compiled and linked as: cc -c main.ccc -c +z lib1.c lib2.cld -b lib1.o lib2.o -o liba.slcc main.o liba.sl -o test2 Using the 32-bit mode linker, test2 executes without error. The module in liba.sl cre...
Page 182 - Symbol Searching in Dependent Libraries
182 Chapter 5 Creating and Using Libraries Using Shared Libraries in 64-bit mode cc -c main.ccc -c +z a.c b.cld -b a.o -o libA.slld -b b.o -o libB.slcc main.o libA.sl libB.sl -o test3 The 32-bit mode linker toolset produces: $ test3 object is 1 The 32-bit mode linker toolset defines the object globa...
Page 184 - Mixed Mode Shared Libraries
184 Chapter 5 Creating and Using Libraries Using Shared Libraries in 64-bit mode 1. First, the dependent shared libraries for libA are built. (Other libraries are also built.) ld -b libD.o -o libD.sl libA dependent shared library ld -b libE.o -o libE.sl libA dependent shared library ld -b libF.o -o ...
Page 186 - 4-bit Mode Library Examples
186 Chapter 5 Creating and Using Libraries Using Shared Libraries in 64-bit mode mode library. The loader uses 64-bit mode search techniques on alllibraries except for libfile3.sl , in which case it uses 32-mode search techniques. NOTE Embedded path inheritance is not applied to any mixed mode share...
Page 190 - Library Example: Using; pathlist
190 Chapter 5 Creating and Using Libraries Using Shared Libraries in 64-bit mode +-->lib2a.sl| +-->lib2.sl-->lib2b.sl| lib1.sl-->lib3.sl-->lib3a.sl-->lib3aa.sl | | | +-->lib3b.sl +-->lib4.sl In breadth-first searching, the load order is siblings before children: lib1.sl->l...
Page 191 - Library Example: Linking to Libraries with
Chapter 5 191 Creating and Using Libraries Using Shared Libraries in 64-bit mode Library Example: Linking to Libraries with +b path_list in 64-bit Mode. In this example, the program main calls a shared library routine in libbar.sl . The routine in libbar.sl in turn calls a routine in the shared libr...
Page 195 - Chapter 6
Chapter 6 195 Shared Library Management Routines 6 Shared Library ManagementRoutines You can explicitly load and use shared libraries from your program. Thelinker toolset provides two families of load routines, shl_load and dlopen . The shl_load routines support the shared library mechanisms provide...
Page 196 - Shared Library Management Routine Summaries; The shl_load Routine Summary; Routine
196 Chapter 6 Shared Library Management Routines Shared Library Management Routine Summaries Shared Library Management RoutineSummaries The following sections introduce the shared library managementroutines available for the HP-UX 11.00 release. The shl_load Routine Summary The shl_load family of sh...
Page 197 - The dlopen Routines Summary
Chapter 6 197 Shared Library Management Routines Shared Library Management Routine Summaries Except for shl_get and shl_gethandle , all these routines are thread safe. These routines are described in the shl_load(3x) man page. The dlopen Routines Summary The dlopen family of shared library managemen...
Page 198 - Related Files and Commands; Action
198 Chapter 6 Shared Library Management Routines Shared Library Management Routine Summaries All the dlopen routines are thread-safe. These routines are described in the dl*(3C) man pages. Related Files and Commands These commands and files provide more information about using sharedlibrary manageme...
Page 199 - Shared Library Header Files
Chapter 6 199 Shared Library Management Routines Shared Library Header Files Shared Library Header Files The shl_load family of shared library management routines use some special data types (structures) and constants defined in the C-languageheader file /usr/include/dl.h . When using these function...
Page 200 - Using Shared Libraries with cc and ld Options
200 Chapter 6 Shared Library Management Routines Using Shared Libraries with cc and ld Options Using Shared Libraries with cc and ldOptions In 32-bit mode, you can access the shl_load family of routines specifying the -ldld option on the cc(1) or ld(1) command line. In 64-bit mode, you can access th...
Page 201 - Initializers for Shared Libraries; Styles of Initializers
Chapter 6 201 Shared Library Management Routines Initializers for Shared Libraries Initializers for Shared Libraries A shared library can have an initialization routine—known as aninitializer—that is called when the load module (a shared library orexecutable) is loaded (initializer) or explicitly un...
Page 202 - Init/Fini Style Initializers
202 Chapter 6 Shared Library Management Routines Initializers for Shared Libraries $ ld -b foo.o +I my_10x_init -o libfoo.sl #include <dl.h> void my_10x_init(shl_t handle, int loading) { /* handle is the shl_load API handle for the shared library beinginitialized. */ /* loading is non-zero at ...
Page 203 - 2-bit Mode Initializers; Declaring the Initializer with the +I Option
Chapter 6 203 Shared Library Management Routines Initializers for Shared Libraries The ld command supports the +fini option to specify theterminator. 32-bit Mode Initializers The 32-bit mode linker supports HP-UX 10.X style initializers. This section contains the following topics: • Using HP-UX 10.X...
Page 204 - Order of Execution of Multiple Initializers .; Initializer Syntax
204 Chapter 6 Shared Library Management Routines Initializers for Shared Libraries For example, to create a shared library named libfoo.sl that uses an initializer named init_foo , use this linker command line: $ ld -b -o libfoo.sl libfoo.o +I init_foo Order of Execution of Multiple Initializers . M...
Page 205 - Example: An Initializer for Each Library
Chapter 6 205 Shared Library Management Routines Initializers for Shared Libraries Accessing Initializers' Addresses . Prior to the HP-UX 10.0 release, initializer's addresses could be accessed through the initializerfield of the shared library descriptor which is returned from a call to shl_get() ....
Page 206 - C Source for testlib
206 Chapter 6 Shared Library Management Routines Initializers for Shared Libraries C Source for libfoo.sl #include <stdio.h>#include <dl.h>/* * This is the local initializer that is called when the libfoo.sl * is loaded and unloaded: */void init_foo(shl_t hndl, int loading){ if (loading)...
Page 207 - Output of testlib; Example: A Common Initializer for Multiple Libraries
Chapter 6 207 Shared Library Management Routines Initializers for Shared Libraries if (shl_findsym(&hndl_foo, “in_to_cm”, TYPE_PROCEDURE, (void *) &in_to_cm)) perror(“shl_findsym: error finding in_to_cm”), exit(1); if (shl_findsym(&hndl_foo, “gal_to_l”, TYPE_PROCEDURE, (void *) &gal_...
Page 209 - C Source for testlib2
Chapter 6 209 Shared Library Management Routines Initializers for Shared Libraries C Source for libtwo.sl #include <stdio.h>void load() /* called after libtwo.sl loaded */{ printf(“libtwo.sl loaded\n”);}void unload() /* called after libtwo.sl unloaded*/{ printf(“libtwo.sl unloaded\n”);} extern...
Page 210 - Output of testlib2; 4-bit Mode Initializers
210 Chapter 6 Shared Library Management Routines Initializers for Shared Libraries TYPE_PROCEDURE, (void *) &oz_to_g)) perror(“shl_findsym: errror finding oz_to_g”), exit(1); /* * Load libtwo.sl and find the required symbols: */ if ((hndl_two = shl_load(“libtwo.sl”, BIND_IMMEDIATE, 0)) ==NULL) p...
Page 211 - Init and Fini Usage Example
Chapter 6 211 Shared Library Management Routines Initializers for Shared Libraries • Init/Fini style: see “Init/Fini Style Initializers” and the topics described in this section: • “Init and Fini Usage Example” • “Ordering Within an Executable or Shared Library” • “Ordering Among Executables and Sha...
Page 212 - Ordering Within an Executable or Shared Library
212 Chapter 6 Shared Library Management Routines Initializers for Shared Libraries C source for lib3.sl (file lib3.c): lib3(){ printf(“lib3\n”); } #pragma init “lib3_init” voidlib3_init(){ printf(“lib3_init\n”); } #pragma fini “lib3_fini” voidlib3_fini(){ printf(“lib3_fini\n”); } Commands used to bu...
Page 213 - Ordering Among Executables and Shared Libraries
Chapter 6 213 Shared Library Management Routines Initializers for Shared Libraries • HP-UX 10.X style initializers are called in forward order of the +I options specified on the link line when loading a shared library. Theyare then called in reverse order when unloading the library. • HP-UX 10.X sty...
Page 215 - The shl_load Shared Library Management Routines; Syntax; Parameters
Chapter 6 215 Shared Library Management Routines The shl_load Shared Library Management Routines The shl_load Shared LibraryManagement Routines This section describes the shl_load family of shared library management routines. NOTE You can use these routines in both 32-bit and 64-bit mode. Support fo...
Page 217 - Return Value
Chapter 6 217 Shared Library Management Routines The shl_load Shared Library Management Routines Causes the dependent libraries to be loaded breadthfirst. By default, the 64-bit mode shl_load loads dependent libraries depth-first. These flags are discussed in detail in“shl_loadExample”. address Spec...
Page 219 - load_lib — Function to Load a Shared Library
Chapter 6 219 Shared Library Management Routines The shl_load Shared Library Management Routines Once a library is explicitly loaded, use the shl_findsym routine to get pointers to functions or data contained in the library; then call orreference them through the pointers. This is described in detai...
Page 220 - BIND_NONFATAL Modifier; BIND_VERBOSE Modifier
220 Chapter 6 Shared Library Management Routines The shl_load Shared Library Management Routines } /* * Dynamically load the shared library using BIND_IMMEDIATEbinding: */ lib_handle = shl_load( lib_path, BIND_IMMEDIATE, 0); if (lib_handle == NULL) perror(“shl_load: error loading library”), exit(1);...
Page 221 - DYNAMIC_PATH Modifier
Chapter 6 221 Shared Library Management Routines The shl_load Shared Library Management Routines BIND_FIRST is typically used when you want to make the symbols in a particular library more visible than the symbols of the same name inother libraries. Compare this with the default behavior, which is t...
Page 222 - Binding Flags Examples; The shl_findsym Routine
222 Chapter 6 Shared Library Management Routines The shl_load Shared Library Management Routines BIND_FIRST | BIND_TOGETHER causes the library being loaded and its dependent libraries to be bound all at the same time, thereby resolvinginterdependencies. If you are not using BIND_FIRST , libraries ar...
Page 225 - Load a Shared Library and Call Its Routines and Access Its Data
Chapter 6 225 Shared Library Management Routines The shl_load Shared Library Management Routines 1. declare a pointer to a data structure of the same type as the data structure to access in the library 2. using shl_findsym with the type parameter set to TYPE_DATA , find the symbol in the shared libr...
Page 229 - Description; show_loaded_libs — Display Library Information
Chapter 6 229 Shared Library Management Routines The shl_load Shared Library Management Routines Description To obtain information on currently loaded libraries, use the shl_get function. If you are programming in a threaded environment, use thethread-safe version shl_get_r which is the same as shl_...
Page 230 - show_lib_info — Display Information for a Shared Library
230 Chapter 6 Shared Library Management Routines The shl_load Shared Library Management Routines The shl_gethandle and shl_gethandle_rRoutines Returns descriptor information about a loaded shared library. Syntax int shl_gethandle( shl_t handle , struct shl_descriptor ** desc ) Parameters handle The ...
Page 231 - The shl_definesym Routine
Chapter 6 231 Shared Library Management Routines The shl_load Shared Library Management Routines int show_lib_info(shl_t libH){struct shl_descriptor *desc; if (shl_gethandle(libH, &desc) == -1) { fprintf(stderr, "Invalid library handle.\\n"); return -1; } printf("library path: %s\\n&...
Page 232 - The shl_getsymbols Routine
232 Chapter 6 Shared Library Management Routines The shl_load Shared Library Management Routines Return Value If successful, shl_definesym returns 0. Otherwise, it returns − 1 and sets errno accordingly. See shl_definesym(3X) for details. Description The shl_definesym function allows you to add a ne...
Page 235 - The shl_symbol Structure
Chapter 6 235 Shared Library Management Routines The shl_load Shared Library Management Routines ENOSYM Some symbol required by the shared library could notbe found. EINVAL The specified handle is invalid. ENOMEM memfunc failed to allocate the requested memory. The shl_symbol Structure The members o...
Page 236 - show_symbols — Display Shared Library Symbols
236 Chapter 6 Shared Library Management Routines The shl_load Shared Library Management Routines type The type of symbol you want to display. This is thesame as the type parameter to shl_getsymbols and can have these values: TYPE_PROCEDURE , TYPE_DATA , or TYPE_UNDEFINED . If it is TYPE_UNDEFINED , ...
Page 238 - The shl_unload and cxxshl_unload Routines
238 Chapter 6 Shared Library Management Routines The shl_load Shared Library Management Routines printf PROCEDURE shl_get PROCEDURE shl_getsymbols PROCEDURE __d_trap PROCEDURE TOTAL SYMBOLS: 9 Exports: environ DATA 0x40001018 errno STORAGE 0x400011CC _SYSTEM_ID DATA 0x40001008 __dld_loc STORAGE 0x40...
Page 240 - The dlopen Shared Library Management Routines; The dlopen Routine; Parm
240 Chapter 6 Shared Library Management Routines The dlopen Shared Library Management Routines The dlopen Shared LibraryManagement Routines This section describes the dl* family of shared library management routines. NOTE Use these routines in 64-bit mode only The dlopen Routine Opens a shared libra...
Page 241 - Return Values; Mode
Chapter 6 241 Shared Library Management Routines The dlopen Shared Library Management Routines Return Values A successful dlopen call returns to the process a handle which the process can use on subsequent calls to dlsym and dlclose . This value should not be interpreted in any way by the process. d...
Page 244 - The dlerror Routine
244 Chapter 6 Shared Library Management Routines The dlopen Shared Library Management Routines The symbols introduced by dlopen operations and available through dlsym are those which are “exported” as symbols of global scope by the shared library. For shared libraries, such symbols are typically tho...
Page 245 - The dlsym Routine
Chapter 6 245 Shared Library Management Routines The dlopen Shared Library Management Routines Description dlerror returns a null-terminated character string (with no trailing newline character) that describes the last error that occurred duringdynamic linking processing. If no dynamic linking error...
Page 247 - Examples
Chapter 6 247 Shared Library Management Routines The dlopen Shared Library Management Routines necessary information, and use dlsym with RTLD_NEXT to find the “real” malloc , which would perform the actual memory allocation. Of course, this “real” malloc could be another user-defined interface that ...
Page 248 - The dlget Routine
248 Chapter 6 Shared Library Management Routines The dlopen Shared Library Management Routines The dlget Routine Retrieves information about a loaded module (program or sharedlibrary). Syntax void *dlget(unsigned int index, struct load_module_desc *desc, size_t desc_size); Parameters Return Values I...
Page 249 - The dlmodinfo Routine
Chapter 6 249 Shared Library Management Routines The dlopen Shared Library Management Routines struct load_module_desc { unsigned long text_base; unsigned long text_size; unsigned long data_base; unsigned long data_size; unsigned long unwind_base; unsigned long linkage_ptr; unsigned long phdr_base; ...
Page 252 - The dlgetname Routine
252 Chapter 6 Shared Library Management Routines The dlopen Shared Library Management Routines The dlgetname Routine Retrieves the name of a load module given a load module descriptor. Syntax char *dlgetname(struct load_module_desc *desc,size_t desc_size,void *(*read_tgt_mem)(void* buffer, unsigned ...
Page 253 - The dlclose Routine
Chapter 6 253 Shared Library Management Routines The dlopen Shared Library Management Routines Return Values dlgetname returns the pathname of a load module represented by desc. If desc does not describe a loaded module, dlgetname returns NULL. Description dlgetname is one of a family of routines th...
Page 256 - Dynamic Loader Compatibility Warnings
256 Chapter 6 Shared Library Management Routines Dynamic Loader Compatibility Warnings Dynamic Loader CompatibilityWarnings Starting with the HP-UX 10.20 release, the dynamic loader generatescompatibility warnings. These warnings include linker toolset featuresthat may change over time. To display r...
Page 259 - Chapter 7; Position-Independent Code
Chapter 7 259 Position-Independent Code 7 Position-Independent Code This chapter discusses • “What Is Relocatable Object Code?” • “What is Absolute Object Code?” • “What Is Position-Independent Code?” • “Generating Position-Independent Code” This chapter is useful mainly to programmers who want to w...
Page 260 - What Is Relocatable Object Code?
260 Chapter 7 Position-Independent Code What Is Relocatable Object Code? What Is Relocatable Object Code? Relocatable object code is machine code that is generated bycompilers and assemblers and stored in relocatable object files, or .o files. A relocatable object file contains symbolic references t...
Page 261 - What is Absolute Object Code?
Chapter 7 261 Position-Independent Code What is Absolute Object Code? What is Absolute Object Code? Absolute object code is machine code that contains references toactual addresses within the program's address space. When the linkercombines relocatable object files to build a program file, or a.out ...
Page 263 - Generating Position-Independent Code; linker generates stubs that ensure
Chapter 7 263 Position-Independent Code Generating Position-Independent Code Generating Position-Independent Code To be position-independent, object code must restrict all references tocode and data to either PC-relative or indirect references, where allindirect references are collected in a single ...
Page 264 - For More Information:
264 Chapter 7 Position-Independent Code Generating Position-Independent Code NOPLDW -24(%sp),%rp ; restore the original rp LDSID (%rp),%r1 MTSP %r1,%sr0 BE,N 0(%sr0,%rp) ; inter-space return For More Information: The remainder of this section describes how compilers generate PIC forthe following add...
Page 265 - Long Calls
Chapter 7 265 Position-Independent Code Generating Position-Independent Code NOTE Any code which is PIC or which makes calls to PIC must follow thestandard procedure call mechanism. When linking files produced by the assembler, the linker exports onlythose assembly language routines that have been e...
Page 266 - Assigned GOTO Statements; Literal References
266 Chapter 7 Position-Independent Code Generating Position-Independent Code LDIL L'target,%r1 BE R'target(%sr4,%r1) For PIC, these two instructions must be transformed into fourinstructions, similar to the long call sequence: BL .+8,%r1 ; get pc into r1 ADDIL L'target-L,%r1 ; add pc-relative offset...
Page 267 - Global and Static Variable References; Procedure Labels
Chapter 7 267 Position-Independent Code Generating Position-Independent Code Global and Static Variable References References to global or static variables currently require two instructionseither to form the address of a variable, or to load or store the contents ofthe variable: ; to form the addre...
Page 269 - Chapter 8; Ways to Improve Performance
Chapter 8 269 Ways to Improve Performance 8 Ways to Improve Performance The linker provides several ways you can improve your applicationperformance. • “Linker Optimizations” describes how the linker -O option removes unnecessary ADDIL instructions and “dead” or unused procedures. • “Options to Impr...
Page 270 - Linker Optimizations
270 Chapter 8 Ways to Improve Performance Linker Optimizations Linker Optimizations The linker supports the -O option which performs the following optimizations at link time: • optimizes references to data by removing unnecessary ADDIL instructions from the object code. • removes procedures that can...
Page 271 - Incompatibilities with other Options
Chapter 8 271 Ways to Improve Performance Linker Optimizations NOTE With the HP-UX 10.0 release, you can also invoke linker optimizations atlevels 2 and 3 by using the +Ofastaccess or +Oprocelim option. See Also: For a brief description of compiler optimization options see “Selecting anOptimization ...
Page 272 - Complete Executables; Affects on Symbolic Debugging
272 Chapter 8 Ways to Improve Performance Linker Optimizations subspaces. Merged subspaces can prevent the removal of deadprocedures. Therefore, it is optimal to have each procedure in its ownsubspace. Complete Executables For complete executables, dead procedure elimination removes anytext subspace...
Page 273 - Options to Improve TLB Hit Rates
Chapter 8 273 Ways to Improve Performance Options to Improve TLB Hit Rates Options to Improve TLB Hit Rates To improve Translation Lookaside Buffer (TLB) hit rates in anapplication running on a PA 8000-based system, use the following linkeror chatr virtual memory page setting options: • +pd size — r...
Page 274 - Profile-Based Optimization; General Information about PBO
274 Chapter 8 Ways to Improve Performance Profile-Based Optimization Profile-Based Optimization In profile-based optimization (PBO), the compiler and linker worktogether to optimize an application based on profile data obtained fromrunning the application on a typical input data set. For instance, i...
Page 275 - When to Use PBO; How to Use PBO
Chapter 8 275 Ways to Improve Performance Profile-Based Optimization When to Use PBO PBO should be the last level of optimization you use when building anapplication. As with other optimizations, it should be performed after anapplication has been completely debugged. Most applications will benefit ...
Page 276 - A Simple Example
276 Chapter 8 Ways to Improve Performance Profile-Based Optimization A Simple Example Suppose you want to apply PBO to an application called sample . The application is built from a C source file sample.c . Discussed below are the steps involved in optimizing the application. Step 1 Instrumentation ...
Page 278 - The Startup File icrt0.o
278 Chapter 8 Ways to Improve Performance Profile-Based Optimization The Startup File icrt0.o The icrt0.o startup file uses the atexit system call to register the function that writes out profile data. (For 64-bit mode, the initializationcode is in /usr/ccs/lib/pa20_64/fdp_init.0 .) That function is...
Page 279 - Code Generation from I-SOMs; Profiling; Choosing Input Data
Chapter 8 279 Ways to Improve Performance Profile-Based Optimization A simpler approach would be to compile foo.c and bar.c with a single cc command: $ cc -v +I -O -o foobar bar.c foo.c/opt/langtools/lbin/cpp bar.c /var/tmp/ctm352/opt/ansic/lbin/ccom /var/tmp/ctm352 bar.o -O2 -I/opt/langtools/lbin/c...
Page 281 - Storing Profile Information for Multiple Programs
Chapter 8 281 Ways to Improve Performance Profile-Based Optimization Storing Profile Information for Multiple Programs A single flow.data file can store information for multiple programs. This allows an instrumented program to spawn other instrumentedprograms, all of which share the same flow.data f...
Page 282 - Sharing the flow.data File Among Multiple Processes
282 Chapter 8 Ways to Improve Performance Profile-Based Optimization Sharing the flow.data File Among Multiple Processes A flow.data file can potentially be accessed by several processes at the same time. For example, this could happen when you run more than oneinstrumented program at the same time ...
Page 284 - Using The flow.data File
284 Chapter 8 Ways to Improve Performance Profile-Based Optimization Using The flow.data File By default, the code generator and linker look for the flow.data file in the current working directory. In other words, the flow.data file created during the profiling phase should be located in the directo...
Page 285 - Selecting an Optimization Level with PBO
Chapter 8 285 Ways to Improve Performance Profile-Based Optimization Specifying a Different Program Name (+pgm) When retrieving a program's profile data from the flow.data file, the linker uses the program's basename as a lookup key. For instance, if aprogram were compiled as follows, the linker wou...
Page 286 - Using PBO to Optimize Shared Libraries
286 Chapter 8 Ways to Improve Performance Profile-Based Optimization +O2 Full optimization within each procedure in a file. (Canalso be invoked as -O .) +O3 Full optimization across all procedures in an object file.Includes subprogram inlining. +O4 Full optimization across entire application, perfor...
Page 288 - Restrictions and Limitations of PBO; Temporary Files; Source Code Changes and PBO
288 Chapter 8 Ways to Improve Performance Profile-Based Optimization Notice in the example above, that the +pgm option was necessary because the output file name differs from the instrumented program file name. NOTE If you are using -r and C++ templates, check "Known Limitations" in the HP C...
Page 290 - I-SOM File Restrictions
290 Chapter 8 Ways to Improve Performance Profile-Based Optimization $ cc +I +O3 -c file.c Create I-SOM for instrumentation. $ cc +I +O3 file.o Link with instrumentation. $ a.out < input_file Run instrumented executable with representative input data. $ cc +P +O3 file.o Perform PBO and HLO. Repla...
Page 291 - Compatibility with 9.0 PBO
Chapter 8 291 Ways to Improve Performance Profile-Based Optimization nm . The nm command works on I-SOM files. However, since code generation has not yet been performed, some of the imported symbolsthat might appear in an ordinary relocatable object file will not appear inan I-SOM file. ar . I-SOM f...
Page 293 - Improving Shared Library Start-Up Time with fastbind; Using fastbind
Chapter 8 293 Ways to Improve Performance Improving Shared Library Start-Up Time with fastbind Improving Shared Library Start-UpTime with fastbind The fastbind tool improves the start-up time of programs that use shared libraries. When fastbind is invoked, it caches relocation information inside the...
Page 294 - Invoking fastbind from the Linker; How to Tell if fastbind Information is Current; Turning off fastbind at Run Time
294 Chapter 8 Ways to Improve Performance Improving Shared Library Start-Up Time with fastbind Invoking fastbind from the Linker To invoke fastbind from ld , pass the request to the linker from your compiler by using the -Wl , +fb options. For example: $ ld -b convert.o volume.o -o libunits.sl Build...
Page 295 - Using Mapfiles
295 A Using Mapfiles The ld command automatically maps sections from input object files onto output segments in executable files. The mapfile option allows youto change the default mapping provided by the linker. NOTE The mapfile option is supported only in 64-bit mode linking. NOTE In most cases, t...
Page 296 - Appendix A; Controlling Mapfiles with the -k Option
296 Appendix A Using Mapfiles Controlling Mapfiles with the -k Option Controlling Mapfiles with the -k Option The -k option to ld specifies a text file containing mapfile directives: ld -k mapfile [ flags ] files ... The ld command automatically maps sections from input object files onto output segm...
Page 298 - Changing Mapfiles with -k filename and +nodefaultmap; mapfile and
298 Appendix A Using Mapfiles Changing Mapfiles with -k filename and +nodefaultmap Changing Mapfiles with -k filename and+nodefaultmap The +nodefaultmap option used with -k option prevents the linker from concatenating the default memory map to the map provided byfilename. If you specify +nodefaultm...
Page 300 - Simple Mapfile
300 Appendix A Using Mapfiles Simple Mapfile Simple Mapfile The following directives show how a simple mapfile would appear: # text segment text = LOAD ?RX; text : .rodata ?A; text : $PROGBITS ?AX; # data segment data = LOAD ?RW; data : $PROGBITS ?AW!S; data : $PROGBITS ?AWS; data : $NOBITS ?AWS; da...
Page 303 - Defining Syntax for Mapfile Directives
Appendix A 303 Using Mapfiles Defining Syntax for Mapfile Directives Defining Syntax for Mapfile Directives A mapfile can have zero or more mapfile directives. There are two typesof mapfile directives: segment declarations and section mappingdirectives. The directives can span across lines and are t...
Page 304 - Defining Mapfile Segment Declarations; Segment Flags; Attribute
304 Appendix A Using Mapfiles Defining Mapfile Segment Declarations Defining Mapfile Segment Declarations A segment declaration can create a new segment with a set of attributesor change the attributes of an existing segment. segment_name = { segment_attribute_value }* ; The segment attributes and t...
Page 305 - Flag
Appendix A 305 Using Mapfiles Defining Mapfile Segment Declarations The default segment_flags for a LOADable segment is ?RWX . Segment declarations support the following special flags: Flag Action R Readable W Writable X Executable Flag Action s Enables static branch prediction on a segment. This fl...
Page 306 - Mapfile Segment Declaration Examples
306 Appendix A Using Mapfiles Defining Mapfile Segment Declarations Mapfile Segment Declaration Examples • The following example declares a segment with segment_type LOAD and segment_flags readable and executable. text = LOAD ?RX; • The following example declares a LOADable segment (default) with se...
Page 307 - Defining Mapfile Section Mapping Directives
Appendix A 307 Using Mapfiles Defining Mapfile Section Mapping Directives Defining Mapfile Section MappingDirectives A section mapping directive specifies how the linker should map theinput section onto output segments. This directive tells the linker whatattributes of a section must be matched in o...
Page 309 - Internal Map Structure; Placement of Segments in an Executable
Appendix A 309 Using Mapfiles Internal Map Structure Internal Map Structure The linker use a default map structure corresponding to the defaultmapfile. When you use the mapfile option with the ld command, the linker appends the default mapfile to the end of your user-specifiedmapfile. (You can overr...
Page 313 - Mapfile Option Error Messages; Fatal Errors
Appendix A 313 Using Mapfiles Mapfile Option Error Messages Mapfile Option Error Messages Fatal Errors The following conditions can result in a fatal error: • Specifying more than one -k option on the command line • Mapfile cannot be opened or read • The linker finds a syntax error in the mapfile • ...
Page 315 - Glossary
Glossary 315 Glossary absolute object code Machinecode that contains absolute virtualaddresses. Created by the linkerwhen it combines relocatableobject files. archive library A library,created by the ar command, which contains one or more objectmodules. By convention, archivelibrary file names end w...
Page 317 - feedback-directed positioning
Glossary 317 Glossary dynamic loading library AnSVR4 term for a shared library. dynamic search path Theprocess that allows the location ofshared libraries to be specified atruntime. entry point The location atwhich a program starts runningafter HP-UX loads it into memory.The entry point is defined b...
Page 318 - implicit address dependency
318 Glossary Glossary header string A string," !<arch>\n ", which identifies a file as an archive created by ar ( \n represents the newline character). hiding a symbol Making asymbol invisible to code outside themodule in which the symbol wasdefined. Accomplished with the -h linker opt...
Page 320 - position-independent code
320 Glossary Glossary is that program executioncontinues even if the dynamicloader cannot resolve symbols. object code See relocatableobject code. object file A file containingmachine language instructions anddata in a form that the linker canuse to create an executableprogram. object module A file ...
Page 321 - relocatable object code
Glossary 321 Glossary profile data obtained from runningthe application on a typical inputdata set. relocatable object code Machine code that is generated bycompilers and assemblers. It isrelocatable in the sense that itdoes not contain actual addresses;instead, it contains symbolscorresponding to a...
Page 322 - standard input/output library; stream A data structure of type
322 Glossary Glossary standard input/output library A collection of routines thatprovide efficient and portableinput/output services for most Cprograms. standard output The defaultstream for sending characteroutput data — usually connectedto the screen. startup file Also known as crt0.o , this is th...
Page 325 - Index
Index Index 325 Symbols $LIT$ text space and performance , 148 $START$ symbol , 43 $TEXT$ space and performance , 148 +b linker option , 176 , 178 +b path_list linker option , 84 , 104 , 145 +cg linker option , 28 +compat linker option , 25 , 90 +DA compiler option , 21 +df compiler and linker optio...