6.4. Linker[21][21] Refer to http://people.redhat.com/drepper/dsohowto.pdf for a good reference on writing shared libraries in Linux. Both HP-UX and GNU compilers support sending options directly to the linker. This is done by using -Wl,option, which can appear as many times as needed on the command line. Although some command-line switches for HP-UX and GNU ld are similar, it is recommended that linker command-line arguments be inspected thoroughly as to their intended purpose.[22] [22] Refer to GNU ld documentation at www.gnu.org/software/binutils/manual/ld-2.9.1/ld.html. Table 6-8 compares some HP-UX and GNU ld linker options. Table 6-8. HP-UX and Linux Linker Options Comparison TableHP-UX ld Option | GNU ld Equivalent | Description |
---|
Most options starting with +. | Not supported | HP-UX ld options that start with a +. | For example, +b, | | | +vtype, +s. | | | -a {archive | shared | default | archive_shared | shared_archive} | -a {archive | shared | default} -Bdynamic|-dy| -call_shared -Bstatic|-dn| -non_shared|-static | Tells the linker what type of library to link to. | -B [immediate| restricted| symbolic] | None | Changes binding behavior of application to linked libraries at startup time. | -e entry | -e entry | Use entry as the explicit symbol for beginning execution of your program, rather than the default entry point. | +e | -E|-export-dynamic | Exports symbols. | -h | None[23] | Hides symbols. | -Ldir | -rpath path | Specifies the search direction to the runtime linker. | -Ldir | -Ldir | Augments system default search directories with directories specified with the -L flag. | -l: | None | In HP-UX, specifies the full base-name of the library to link with. For example, -l:libfoo.a. | -r | -r | Generates relocatable output (that is, generates an output file that can in turn serve as input to ld). | -s | -s | Omits all symbol information from the output file. | -t | -t | Prints the names of the input files as ld processes them. | -u symbol | -u symbol | Enters symbol as an undefined symbol in the symbol table. | -v | None | Displays verbose messages during linking. | -V | -V, -v | Displays the version number for ld. | -G | -S | Strips all unloadable data (such as debug information). | -x | -x | Deletes all temporary local symbols. | -y symbol | -y symbol | Prints the name of each linked file in which symbol appears. | -Z | None | Allows dereferencing of null pointers (HP-UX only). |
[23] Use the export maps through the -version-script option in GNU ld. Refer to Chapter 3 for information on library versioning available on Linux. 6.4.1. Export Map Export maps enable users to tell the linker explicitly which symbols to export from the generated object. The GNU linker supports export maps. To generate a shared object with this method, the user has to pass the name of the map file with the -version-script option of the linker: $ gcc -shared -o bar.so bar.c -fPIC -Wl,--version-script=bar.map The file bar.map can contain text such as this: { global: index; local: *; }; Chapter 3 has more information on using export maps on Linux. 6.4.2. Linker Tools Some application makefiles make use of linker tools that are present in HP-UX. These tools are used to examine object files and manipulate them to create the final object file or executable on HP-UX. Table 6-9 compares other HP-UX linker tools and their equivalents on Linux. Table 6-9. HP-UX and Linux Linker Tools Comparison TableHP-UX Tool | Linux Equivalent | Description |
---|
chatr | None | Displays or modifies the internal attributes of an object file. | elfdump | objdump | Displays the contents of an ELF object file. | fastbind | None | Improves startup time of programs that use shared libraries. | ldd | ldd | Lists dynamic dependencies of executable files and shared libraries. | lorder | None | Finds ordering relationship for an object library. | nm | nm | Displays the symbol table of an object file. | odump | objdump | Displays the contents of a 32-bit native code object file (HP-UX). | size | size | Prints sizes of object file elements. | strip | strip | Strips symbol and debugging information from an object file, executable, or archive library. |
See Chapter 2 for more information on the GNU binutils. |