HP-UX Linker and Libraries User's Guide
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(). If you use
+hideallsymbols, the linker cannot export the following routines in the a.out.
$ ld main.o +hideallsymbols -L. -lfoo -lc
$ elfdump -t a.out
a.out:
...
.symtab
index Type Bind Other Sect Value Size Name
1 FUNC LOCL 0 0xb 0x4000000000001104 0 test
...
10 FUNC LOCL 0 0xb 0x4000000000001200 0 func
Hiding Symbols with -h
The -h option allows you to hide symbols. Hiding a symbol makes the symbol a local definition,
accessible only from the object module or library in which it is defined. Use -h if you want to hide
a few symbols
You can use -h option when building a shared library (with -b) and when linking to create an
a.out file. When combining .o files with -r, you can use the -h option.
The syntax of the -h option is: -h symbol The -h option hides symbol. Other global symbols
remain exported unless hidden with -h.
Example Using -h
Suppose you want to build a shared library from an object file that contains the following symbol
definitions as displayed by the nm command:
$ nm -p sem.o
0000000000 U $global$
1073741824 d $THIS_DATA$
1073741864 b $THIS_BSS$
0000000004 cS sem_val
0000000000 T check_sem_val
0000000036 T foo
0000000000 U printf
0000000088 T bar
0000000140 T sem
In this example, check_sem_val, foo, bar, and sem are all global definitions. To create a
shared library where check_sem_val is a hidden, local definition, you can do the following:
$ ld -b -h check_sem_val sem.o
Tips on Using -h
You must not run -h and +e options on the same command line. For instance, suppose you specify
+e sem. This exports the symbol sem and hides all other symbols. Additional -h options becomes
unnecessary. If both -h and +e are used on the same symbol, the -h overrides the +e option.
The linker command line gets lengthy and difficult to read if several such options are specified. In
fact, you exceed the maximum HP-UX command line length if you specify too many options. To
get around this, use ld linker option files, described under “Passing Linker Options in a file with
-c” (page 44) . You can specify any number of -h or +e options in this file.
Using Linker Commands 39