public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* redefining dynamic symbols???
@ 2002-07-16 19:31 Jorge Luis Williams
  2002-07-17  3:47 ` Alan Modra
  0 siblings, 1 reply; 8+ messages in thread
From: Jorge Luis Williams @ 2002-07-16 19:31 UTC (permalink / raw)
  To: binutils


A while back sombody brought up the idea of using objcopy to redefine
dynamic symbols. This is a feature that I would find most useful.  Has
anybody been working on this?
Seeing as objcopy doesn't support this feature is it possible to do this
with ld -- or someother way?
What would be the work involved??


Thanx,

jOrGe W.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: redefining dynamic symbols???
  2002-07-16 19:31 redefining dynamic symbols??? Jorge Luis Williams
@ 2002-07-17  3:47 ` Alan Modra
  2002-07-17  6:04   ` Jorge Luis Williams
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Modra @ 2002-07-17  3:47 UTC (permalink / raw)
  To: Jorge Luis Williams; +Cc: binutils

On Tue, Jul 16, 2002 at 07:34:29PM -0700, Jorge Luis Williams wrote:
> 
> A while back sombody brought up the idea of using objcopy to redefine
> dynamic symbols. This is a feature that I would find most useful.  Has
> anybody been working on this?

Not that I'm aware of.

> Seeing as objcopy doesn't support this feature is it possible to do this
> with ld -- or someother way?

You could edit the file string table with a binary editor.  ;-)

> What would be the work involved??

You'd need to examine the existing code in objcopy that does
--redefine-sym and switch symbol table reading and writing to use
the dynamic symbol table.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: redefining dynamic symbols???
  2002-07-17  3:47 ` Alan Modra
@ 2002-07-17  6:04   ` Jorge Luis Williams
  2002-07-17  6:42     ` Alan Modra
  0 siblings, 1 reply; 8+ messages in thread
From: Jorge Luis Williams @ 2002-07-17  6:04 UTC (permalink / raw)
  To: amodra; +Cc: jorgew, binutils

> You'd need to examine the existing code in objcopy that does
> --redefine-sym and switch symbol table reading and writing to use
> the dynamic symbol table.
>

I thought about doing this, however I was under the understanding that
this wouldn't work because I would also need to recompute the .hash
section otherwise the dynamic linker wouldn't be able to find the newly
defined dynamic symbol. Is this still true -- or does BFD now do this for
me automatically?

If I do need to recompute the .hash section -- well I  have like zero
knowledge in this dept, any pointer to documentation, code, or any advise
on  how to do this would be really appreciated.

Thanx,

jOrGe W.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: redefining dynamic symbols???
  2002-07-17  6:04   ` Jorge Luis Williams
@ 2002-07-17  6:42     ` Alan Modra
  2002-07-17  7:17       ` redefining dynamic symbols??? -- why I want to Jorge Luis Williams
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Modra @ 2002-07-17  6:42 UTC (permalink / raw)
  To: Jorge Luis Williams; +Cc: binutils

On Wed, Jul 17, 2002 at 05:49:52AM -0700, Jorge Luis Williams wrote:
> > You'd need to examine the existing code in objcopy that does
> > --redefine-sym and switch symbol table reading and writing to use
> > the dynamic symbol table.
> >
> 
> I thought about doing this, however I was under the understanding that
> this wouldn't work because I would also need to recompute the .hash
> section

Ouch.  I didn't think of that.  You'll find you need to copy/write
quite a lot of code to do what you want.  Much easier to recompile
whatever applications/shared libs you're trying to tweak.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 8+ messages in thread

* redefining dynamic symbols??? -- why I want to.
  2002-07-17  6:42     ` Alan Modra
@ 2002-07-17  7:17       ` Jorge Luis Williams
  2002-07-17  8:39         ` H. J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Jorge Luis Williams @ 2002-07-17  7:17 UTC (permalink / raw)
  To: amodra; +Cc: jorgew, binutils

> On Wed, Jul 17, 2002 at 05:49:52AM -0700, Jorge Luis Williams wrote:
>> > You'd need to examine the existing code in objcopy that does
>> > --redefine-sym and switch symbol table reading and writing to use
>> > the dynamic symbol table.
>> >
>>
>> I thought about doing this, however I was under the understanding that
>> this wouldn't work because I would also need to recompute the .hash
>> section
>
> Ouch.  I didn't think of that.  You'll find you need to copy/write
> quite a lot of code to do what you want.  Much easier to recompile
> whatever applications/shared libs you're trying to tweak.
>

Damn -- I'm trying to avoid translating and recompiling c code. Let me
explain what I'm trying to do -- maybe there's a fancy ld flag that will
work.

I  have three libraries lib_b, lib_c, lib_c_copy. lib_c and lib_c_copy
both define the same dynamic symbols. In fact they are true copies --
generated from the same code.


exe_a is dynamicly linked to lib_c and lib_b
lib_b is dynamicly linked to lib_c_copy



It seems that when I run exe_a both exe_a and lib_b use the same copy of
lib_c which causes some problems for what I'm trying to do.   I've tried
linker flag -Bsymbolic which I understood would prevent this from
happening, but this doesn't seem to work.


Another technique is statically linking exe_a to lib_c and lib_b to
lib_c_copy. This works under linux -- however it's not enough to fool the
dynamic linker/loader under solaris as here we still use the same copy of
lib_c.

My next attempt was to change the dynamic symbols in lib_b and lib_c_copy
so that they don't match those in lib_c -- we could do this after compile
time as part of the build, however as you just stated this seems to be
more difficult than it's worth.

Regenerating the code for lib_c so that it changes all the dynamic symbols
would not only complacate the code but also significantly increase compile
time (we have more than one library which we need to copy).

Basically, I'm all out of ideas -- any other suggestions??


Thanx,

jOrGe W.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: redefining dynamic symbols??? -- why I want to.
  2002-07-17  7:17       ` redefining dynamic symbols??? -- why I want to Jorge Luis Williams
@ 2002-07-17  8:39         ` H. J. Lu
  2002-07-17  9:18           ` Jorge Luis Williams
  0 siblings, 1 reply; 8+ messages in thread
From: H. J. Lu @ 2002-07-17  8:39 UTC (permalink / raw)
  To: Jorge Luis Williams; +Cc: amodra, binutils

On Wed, Jul 17, 2002 at 06:51:24AM -0700, Jorge Luis Williams wrote:
> > On Wed, Jul 17, 2002 at 05:49:52AM -0700, Jorge Luis Williams wrote:
> >> > You'd need to examine the existing code in objcopy that does
> >> > --redefine-sym and switch symbol table reading and writing to use
> >> > the dynamic symbol table.
> >> >
> >>
> >> I thought about doing this, however I was under the understanding that
> >> this wouldn't work because I would also need to recompute the .hash
> >> section
> >
> > Ouch.  I didn't think of that.  You'll find you need to copy/write
> > quite a lot of code to do what you want.  Much easier to recompile
> > whatever applications/shared libs you're trying to tweak.
> >
> 
> Damn -- I'm trying to avoid translating and recompiling c code. Let me
> explain what I'm trying to do -- maybe there's a fancy ld flag that will
> work.
> 
> I  have three libraries lib_b, lib_c, lib_c_copy. lib_c and lib_c_copy
> both define the same dynamic symbols. In fact they are true copies --
> generated from the same code.
> 
> 
> exe_a is dynamicly linked to lib_c and lib_b
> lib_b is dynamicly linked to lib_c_copy
> 
> 
> 
> It seems that when I run exe_a both exe_a and lib_b use the same copy of
> lib_c which causes some problems for what I'm trying to do.   I've tried
> linker flag -Bsymbolic which I understood would prevent this from
> happening, but this doesn't seem to work.
> 

No. -Bsymbolic offects symbols defined in a DSO.

> 
> Another technique is statically linking exe_a to lib_c and lib_b to
> lib_c_copy. This works under linux -- however it's not enough to fool the
> dynamic linker/loader under solaris as here we still use the same copy of
> lib_c.

You can get the same effect on Linux, but it is not the default. Try

# gcc -o exe_a .... -l_c
# gcc -shared -Wl,-Bsymbolic -o lib_b.so .... -l_c

It should work. If not, file a bug report with a small testcase.


H.J.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: redefining dynamic symbols??? -- why I want to.
  2002-07-17  8:39         ` H. J. Lu
@ 2002-07-17  9:18           ` Jorge Luis Williams
  2002-07-17 10:06             ` H. J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Jorge Luis Williams @ 2002-07-17  9:18 UTC (permalink / raw)
  To: hjl; +Cc: jorgew, amodra, binutils

> Try
>
> # gcc -o exe_a .... -l_c
> # gcc -shared -Wl,-Bsymbolic -o lib_b.so .... -l_c
>
> It should work. If not, file a bug report with a small testcase.
>

I'm sorry, what is -l_c supposed to do -- I have my linker looking for a
library _c??  Or is it a compilation flag??
jOrGe W.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: redefining dynamic symbols??? -- why I want to.
  2002-07-17  9:18           ` Jorge Luis Williams
@ 2002-07-17 10:06             ` H. J. Lu
  0 siblings, 0 replies; 8+ messages in thread
From: H. J. Lu @ 2002-07-17 10:06 UTC (permalink / raw)
  To: Jorge Luis Williams; +Cc: amodra, binutils

On Wed, Jul 17, 2002 at 08:50:18AM -0700, Jorge Luis Williams wrote:
> > Try
> >
> > # gcc -o exe_a .... -l_c
> > # gcc -shared -Wl,-Bsymbolic -o lib_b.so .... -l_c
> >
> > It should work. If not, file a bug report with a small testcase.
> >
> 
> I'm sorry, what is -l_c supposed to do -- I have my linker looking for a
> library _c??  Or is it a compilation flag??
> jOrGe W.
> 
> 

-l_c will look for lib_c.a/lib_c.so. Or you can use

# gcc -o exe_a .... lib_c.so
# gcc -shared -Wl,-Bsymbolic -o lib_b.so .... lib_c.a


H.J.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-07-17 16:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-16 19:31 redefining dynamic symbols??? Jorge Luis Williams
2002-07-17  3:47 ` Alan Modra
2002-07-17  6:04   ` Jorge Luis Williams
2002-07-17  6:42     ` Alan Modra
2002-07-17  7:17       ` redefining dynamic symbols??? -- why I want to Jorge Luis Williams
2002-07-17  8:39         ` H. J. Lu
2002-07-17  9:18           ` Jorge Luis Williams
2002-07-17 10:06             ` H. J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).