HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 16 (of 101)
Chapter 11 Software Development
October 29, 2013
Also, on IA, the type of executable the compiler creates is either ELF-32 or ELF-64 IA. Either
of these types is incompatible with files of type PA-RISC1.1 or PA-RISC2.0 (both are 32-bit) or
ELF-64 PA (64-bit).
Building shared Libraries
One major difference between an executable and a shared library is that at runtime the
executable will always be loaded to the same virtual address 0x0, while shared libraries must be
loadable at any virtual address.
Objects that will be linked into a shared library must contain Position Independent Code (PIC).
Position independency means that the symbol address calculation will be done only at runtime,
when the shared library is loaded. To generate PIC objects, the +z compiler option must be used.
Compared to relocatable objects, PIC objects use one more stage of indirection when
dereferencing symbol addresses, by using a symbol address table.
Linking Archived
We can also link against the archive library libc.a. To achieve this we must change the linker's
library search order:
$ cc -o HelloWorld HelloWorld.o -Wl,-a,archive_shared
-Wl can be used to pass the attached comma separated options list to the linker. -Wl,-
a,archive_shared passes "-a archive_shared" to the linker. -a changes the library search
order. In our case we tell ld to search now first for the archive version of libc.
Executables
Dynamically Linked Executables
These executables are linked against shared libraries. Just like with objects, we can look at the
symbol tables of programs and libraries with nm(1):
$ nm HelloWorld
On PA:
Symbols from HelloWorld:
Name Value Scope Type Subspace
:
main | 10400|extern|entry |