Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding a symbol to the dynamic symbol table

196 views
Skip to first unread message

hakon...@gmail.com

unread,
Feb 20, 2009, 5:16:45 AM2/20/09
to
I want to add a specific symbol to the dynamic symbol table. I can use
--export-dynamic or -Bdynamic, but these switches add all symbols to
the dynamic symbol table.

Using RHEL4's ld (2.15.92.0.2), it is stated in the documentation that
"If the output format supports the version script, you can also use it
to add the symbols needed by the dynamic object to the dynamic symbol
table." Since this version of ld supports the --version-script switch,
I assume the pre-requisites to use a version script to add a symbol to
the dynamic symbol table is in place.

With newer versions of ld, I can use the --dynamic-list switch, and a
script which simply contains:

{foo;};

But what does the corresponding version script look like, in order to
get this to work with ld 2.15 ?


Thanks,

Jens Thoms Toerring

unread,
Feb 21, 2009, 2:27:35 PM2/21/09
to

> {foo;};

It's actually rather simple:

SOMENAME {
global:
foo;
bar;
local:
*;
};

That tells the linker that 'foo' and 'bar' are to be exported
and anything else not. I usually use the name of the library
for 'SOMENAME', but you can get a lot more fancy when you need
to support several versions of your library. You can use wild-
cards in the names of the variables, so e.g. 'foo_*' would mean
all symbols with names starting with 'foo_'. The '*' in local
simply means all symbols not yet set to global.

Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de

hakon...@gmail.com

unread,
Feb 23, 2009, 8:26:00 AM2/23/09
to
On 21 Feb, 20:27, j...@toerring.de (Jens Thoms Toerring) wrote:
> It's actually rather simple:
>
> SOMENAME {
>     global:
>              foo;
>              bar;
>     local:
>              *;
>
> };
>
> That tells the linker that 'foo' and 'bar' are to be exported
> and anything else not. I usually use the name of the library
> for 'SOMENAME', but you can get a lot more fancy when you need
> to support several versions of your library. You can use wild-
> cards in the names of the variables, so e.g. 'foo_*' would mean
> all symbols with names starting with 'foo_'. The '*' in local
> simply means all symbols not yet set to global.


Well, I figured that out. The problem is that this way, I do not get a
_dynamic_ symbol. If I do what you suggest Jens, the symbol will be
placed in the _normal_ symbol table (objdump -t) like:

0000000000400860 g F .text 000000000000008c foo

But if I do a -Wl,--export-dynamic, it (and most other symbols as
well, sigh!) will be placed in the dynamic symbol table (objdump -T):

0000000000400860 g DF .text 000000000000008c Base foo

(note the "F" versus "DF").

So, my interpretation of the ld documentation indicates there should
be a way, but I am still asking how...


Thanks, Håkon


Jens Thoms Toerring

unread,
Feb 24, 2009, 5:03:45 PM2/24/09
to
hakon...@gmail.com wrote:
> On 21 Feb, 20:27, j...@toerring.de (Jens Thoms Toerring) wrote:
> > It's actually rather simple:
> >
> > SOMENAME {
> >     global:
> >              foo;
> >              bar;
> >     local:
> >              *;
> >
> > };
> >
> > That tells the linker that 'foo' and 'bar' are to be exported
> > and anything else not. I usually use the name of the library
> > for 'SOMENAME', but you can get a lot more fancy when you need
> > to support several versions of your library. You can use wild-
> > cards in the names of the variables, so e.g. 'foo_*' would mean
> > all symbols with names starting with 'foo_'. The '*' in local
> > simply means all symbols not yet set to global.

> Well, I figured that out. The problem is that this way, I do not get a
> _dynamic_ symbol. If I do what you suggest Jens, the symbol will be
> placed in the _normal_ symbol table (objdump -t) like:

> 0000000000400860 g F .text 000000000000008c foo

> But if I do a -Wl,--export-dynamic, it (and most other symbols as
> well, sigh!) will be placed in the dynamic symbol table (objdump -T):

> 0000000000400860 g DF .text 000000000000008c Base foo

> (note the "F" versus "DF").

Sorry for the misunderstanding. I don't use '-Wl,--export-dynamic'
but just

gcc -shared -fpic -Wl,--version-script=foo.map ...

and then the symbols declared as 'global' in the version script
appear in the output of 'objdump -T', all having 'DF' or 'DOI' set.
Loading the symbols after dlopen() (or getting proper backtraces)
poses no problems at all. If I look at them with 'objdump -t' they
are marked with 'g' and 'F' or 'O'. Looks to me like the option
'-Wl,--export-dynamic' is a bit too "strong" and overrules what
you put into the version script (the info page says "instructs
the linker to add all symbols"...)

0 new messages