public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Shared Objects and Symbol Overrides
@ 1999-09-30 17:46 Eric Todd
  1999-09-30 23:56 ` Eric Todd
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Eric Todd @ 1999-09-30 17:46 UTC (permalink / raw)
  To: help-gcc

How do you keep functions in a dynamically loaded library from making calls
to functions defined in the executable to which the library is being linked?

In particular, I'm having the following problem, and have checked every
source I can find (gcc man page, gcc docs, usenet, simple test program,
etc...) but can find no good solution. Any help would be greatly
appreciated.

I have an executable, say called 'program', which statically links a .o file
that defines a function f(). This version of f() prints a message that says
"program\n".

 I also have a dynamically linkable library called 'libA.so' which defines a
function f() and a function calls_f(). The function calls_f() unsurprisingly
calls the function f(), while the version of f() found in the library prints
a message reading "library\n". This library is not linked in any way (static
or dynamic) at compilation of 'program'.

In the main of 'program', I call dlopen to load libA.so, and then use dlsym
to get a pointer to calls_f(). I then execute the function pointer so
returned. Surprisingly, the result that I get is 'program'! It seems like
what's going on is that when dlopen causes relocation to occur, f() is bound
to the executable's version for both the executable and the library.

Is there any way I can keep this from happening? The desired behavior is for
the library's f() to be called when calls_f() (also in the library) is
called.

FYI, I'm using Solaris 2.7 and GCC 2.95.1. Yes,, I'm using -fPIC. No, I'm
not using it on the .o files the executable is linking in.





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

end of thread, other threads:[~1999-10-31 13:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-30 17:46 Shared Objects and Symbol Overrides Eric Todd
1999-09-30 23:56 ` Eric Todd
1999-10-01  0:00 ` Eric Todd
1999-10-01 16:52 ` Arthur Gold
1999-10-04 10:35   ` Eric Todd
1999-10-04 16:32     ` Eric Todd
1999-10-31 13:57       ` Eric Todd
1999-10-31 13:57     ` Eric Todd
1999-10-31 13:57   ` Arthur Gold

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