public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* correct fn defn
       [not found] <455a2bc10903230834m74d6775btebce5f1a796c7660@mail.gmail.com>
@ 2009-03-23 15:48 ` R
  2009-03-23 15:56   ` John (Eljay) Love-Jensen
  0 siblings, 1 reply; 3+ messages in thread
From: R @ 2009-03-23 15:48 UTC (permalink / raw)
  To: gcc-help

Hi folks,

I wanted to know what happens in gcc in the following scenario.

Say, there is a function by the name jellyfish() defined in libc6.so
Now I compile a binary(say bigben) which also contains jellyfish() defined.

This binary(bigben) of mine has the capability to load a .so at run time..

Now I create a bridge.so which uses jellyfish(), but during compile
time, I link it to another static library(say libpapa.a) which defines
jellyfish(), and if I do an nm on the module, I can see that
jellyfish() is defined in it.

Now I presume that at runtime when bride.so calls jellyfish after
being loaded to bigben, it should actually use the definition which is
present in libpapa.a.

But I see that tracing the code using a debugger shows that it is
actually using the definition from libc6.so.

How can I prevent this from happening and actually ensure that
jellyfish definition is picked up from libpapa.a and neither from
bigben or from libc6.so.

Thanks
Ryan.

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

* Re: correct fn defn
  2009-03-23 15:48 ` correct fn defn R
@ 2009-03-23 15:56   ` John (Eljay) Love-Jensen
  2009-03-23 20:28     ` R
  0 siblings, 1 reply; 3+ messages in thread
From: John (Eljay) Love-Jensen @ 2009-03-23 15:56 UTC (permalink / raw)
  To: R, GCC-help

Hi Ryan,

If you resolve linkage of your bridge.so such that internal symbols are
pre-linked (prebind), then bridge.so will use jellyfish() from libpapa.a
which it has linked against.

If you do not resolve linkage of your bridge.so, then the jellyfish() symbol
in there is a candidate symbol, but the .so will defer to the main
application¹s jellyfish() if one is already present.  This is called "weak
linkage".

This is not a GCC issue.  GCC is a compiler and a tool-chain driver, it is
not a linker or link-loader.  It¹s is an operating system, linker, and
link-loader issue.  Other platforms may do it differently*.  If your code is
cross-platform, these different subtleties and nuances can be a source of
cross-platform frustration.

Sincerely,
--Eljay

* Hence my above mentioned explanation may not be applicable on other
platforms.  From your description, it seems to me that the platform you are
working on that this is the correct explanation.

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

* Re: correct fn defn
  2009-03-23 15:56   ` John (Eljay) Love-Jensen
@ 2009-03-23 20:28     ` R
  0 siblings, 0 replies; 3+ messages in thread
From: R @ 2009-03-23 20:28 UTC (permalink / raw)
  To: John (Eljay) Love-Jensen, gcc-help

Hi John,

Thanks a lot for your response.

> If you resolve linkage of your bridge.so such that internal symbols are
> pre-linked (prebind), then bridge.so will use jellyfish() from libpapa.a
> which it has linked against.
Doesnt look like that is happening for me right now. If I do an nm on
bridge.so, I can see the symbol defined(pre-linked). But during
runtime if I connect gdb and trace the code, looks like it is going to
the jellyfish() defined in libc6.so.

> * Hence my above mentioned explanation may not be applicable on other
> platforms.  From your description, it seems to me that the platform you are
> working on that this is the correct explanation.
I am using gcc3.4.6 on RedHat E4.

Thanks
Ryan.

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

end of thread, other threads:[~2009-03-23 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <455a2bc10903230834m74d6775btebce5f1a796c7660@mail.gmail.com>
2009-03-23 15:48 ` correct fn defn R
2009-03-23 15:56   ` John (Eljay) Love-Jensen
2009-03-23 20:28     ` R

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).