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
$ elfdump
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
The
You can use
The syntax of the
Example Using
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
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
Tips on Using
You must not run
The linker command line gets lengthy and difficult to read if several such options are specified. In fact, you exceed the maximum
Using Linker Commands 39