dynamic link question

I have three dynamic link file:

libwelcome.so

libwelcome2.so

testFunction.so

and a executable file:

testMain

testFunction.so depends on libwelcome2.so

testMain depends on testFunction.so and libwelcome.so

CC -G -o testFunction.so libwelcome2.so testFunction.o

CC -o testMain libwelcome.so testFunction.so

ldd testFunction.so

libwelcome2.so =>.//libwelcome2.so

ldd testMain

libwelcome.so => .//libwelcome.so

testFunction.so =>.//testFunction.so

libCstd.so.1 => /usr/lib/libCstd.so.1

libCrun.so.1 => /usr/lib/libCrun.so.1

libm.so.2 =>/lib/libm.so.2

libc.so.1 =>/lib/libc.so.1

libwelcome2.so =>.//libwelcome2.so

/usr/lib/cpu/sparcv8plus/libCstd_isa.so.1

/platform/SUNW,Sun-Blade-1500/lib/libc_psr.so.1

There is a same function(char* welcome(char*)) in welcome.cc and welcome2.cc

testFunction.cc invokes it of welcome2.cc by "dlopen" and "dlsym"

testMain.cc invokes it of welcome.cc by "dlopen" and "dlsym"

I use dlopen as

dlopen(NULL, RTLD_NOW);

but if I execute the program ./testMain

actually, both testMain and testFunction will use the function "welcome" of welcome.cc

How can I force testFunction.cc to find the symbol in the dynamic link file which name indicated during the compiling time( welcome2.so)

[1413 byte] By [shock_ua] at [2007-11-27 1:35:16]
# 1

Your program is built with explicit dependencies on libwelcome.so and libwelcome2.so. All symbol references are resolved at program start time, before your program begins to run. You have defined 2 global functions "welcome", but only the first one the linker sees is in the symbol table. (You can have only one instance of a global symbol.)

When you dlopen with a null pathname pointer, the current symbol table is used, so only one "welcome" is visible to the dlsym function.

clamage45a at 2007-7-12 0:43:32 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
So how can I solve this problem?The 3rd part Application supply the API and I should compile my code with the dynamic link from the 3rd part, if there is the same symbol in both my dynamic library and the 3rd part, how can I deal with this?
shock_ua at 2007-7-12 0:43:32 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

This is a good question for tools-linking@opensolaris.org

The best answer is not to write your application that way.

I think you can do what you want if you find the right

options to dlopen and dlsym. But I'm not sure exactly

what the right combination is.

--chris

ChrisQuenellea at 2007-7-12 0:43:32 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4

My guess is that you need to use dlsym(3C) with RTLD_NEXT special handle. This is an excerpt from man page:

RTLD_NEXT

Instructs dlsym() to search for the named symbol in the objects that were loaded following the object from which the dlsym() call is being made.

Of course, this is a bad practice and use of dlsym() with RTLD_NEXT should be limited, if possible, to a scenario when you're writing an interposer, which, after doing its job, is supposed to call original function.

MaximKartasheva at 2007-7-12 0:43:32 > top of Java-index,Development Tools,Solaris and Linux Development Tools...