Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU linker: alternative to --version-script to list exported symbols at the command line?

On Linux with the GNU toolchain, I know how to control exported symbols from a shared library with a version script (gcc -Wl,--version-script=symbols.map), but I would like to list exported symbols on the command line instead. IOW, I would like the equivalent of

link /EXPORT:foo 

from the MS toolchain. Is it possible ?

EDIT:

My question may not be very clearn: if I have a library libfoo.so, and I want to only export libraries foo1 and foo2, I can go create a version script foo.linux as follows

libfoo.so
{
global:
    foo1;
    foo2;
local:
    *;
}

And do

gcc -shared foo.c -Wl,--version-script=foo.linux -o libfoo.so -soname libfoo.so

I would like to be able to do something like this instead:

gcc -shared foo.c -Wl,--export-symbol=foo1 -Wl,--export-symbol=foo2 -o libfoo.so -soname libfoo.so
like image 552
David Cournapeau Avatar asked Apr 27 '09 03:04

David Cournapeau


People also ask

What is the linker command in Linux?

The link command creates a hard link named FILE2, which shares the same index node as the existing file FILE1. Since FILE1 and FILE2 share the same index node, they point to the same data on the disk, and modifying one is functionally the same as modifying the other.

How does the GNU linker work?

GNU linker GNU ld runs the linker, which creates an executable file (or a library) from object files created during compilation of a software project. A linker script may be passed to GNU ld to exercise greater control over the linking process. The GNU linker is part of the GNU Binary Utilities (binutils).

How do you write a script linker?

You write a linker script as a series of commands. Each command is either a keyword, possibly followed by arguments or an assignment to a symbol. You may separate commands using semicolons. Whitespace is generally ignored.

What is LD command?

Description. The ld command, also called the linkage editor or binder, combines object files, archives, and import files into one output object file, resolving external references. It produces an executable object file that can be run.


1 Answers

I'm not sure that you can do this like you want. One way is with the linker version script like you mentioned. Another way is to add in your source code __attribute__ ((visibility("default"))) for whatever you want exported and compile everything with -fvisibility=hidden

like image 109
Unknown Avatar answered Nov 01 '22 03:11

Unknown