exporting symbols, help with export list
H. J. Lu
hjl@lucon.org
Mon Aug 2 20:10:00 GMT 2004
On Mon, Aug 02, 2004 at 02:54:09PM -0400, Robert Schweikert wrote:
> Attached is a small example that demonstrates my problem.
>
> The goal:
>
> My goal is to give the linker a list of symbol names that I'd like to
> have accessible (global) from outside a shared library. All names not
> specified in the list should be treated as local. If a local symbol is
> called from outside the shared object the linker should issue an error
> and stop linking.
>
> My approach:
>
> (a) My first attempt is to use a file (export.lst in the tarball) that
> simply lists the symbols I want accessible from outside the shared
> object and pass it to the linker with the -retain-symbols-file. This
> does not work, i.e. calling a symbol not listed in the file from outside
> the .so does not trigger a link error.
>
-retain-symbols-file is used for striping the symbol table. It has no
effect on symbol visibility. You can do "strip libfoo.so" without
effecting the dynamic linker at the run-time.
> (b) My second approach is to use a version script (xportScript_1.txt in
> the tarball) specifying the global and local symbols and passing the
> script with -version-script to the linker. This works, i.e. calling a
> symbol not listed as global generates a link error.
>
> (c) My third approach is to use a version script (xportScript_2.txt in
> the tarball) specifying only the global symbols and passing the script
> with -version-script to the linker. This does not work, i.e. calling a
> symbol not listed in the file from outside the .so does not trigger a
> link error.
>
By default, all symbols are global. You need to list the symbols you
don't want to export. You can use
local: *;
global:
x1;
x2;
...
H.J.
More information about the Binutils
mailing list