General
cancel
Showing results for 
Search instead for 
Did you mean: 

Overriding a function and .so priority setting.

SOLVED
Go to solution
Wkdunreal
Advisor

Overriding a function and .so priority setting.

Hello again,

Q1)

Is there a way to override self written functions on HP ux 11.31 ia64?

for example:

in file.c suppose there is function hello()
now I want to override this function which I myself had written by another hello().

System calls can be overrided by using LD_PRELOAD and at run time calling our own .so library.

But the same does notseem work for overriding self written fucntions.

Reason for this:
a particular function was written quite a few years ago .. and now changes cannot be made to it cause many clients have the old version of the function.

So need is to develop a patch with our own new library which overrides the same function.

I have been tryign to fiddle around with "chatr" and using SHLIB_PATH (had got a hint this path might help) but am unable to get the desired results.

Q2)
suppose I have 2 .so
2)lib1.so
2)lib2.so

and the lets say calling function is call.cxx
when I create a executable using the command

gcc -g call.cxx lib1.so lib2.so -o executable

Is there a way to give lib1.so a higer priority than lib2.so so that if there are common functions in lib1.so and lib2.so with similar definitions but different implementations, the fucntion in lib1.so be used and not the lib2.so .

for example:

lib1.so ----> add() // returns 3
lib2.so ----> add() // returns 4

how can i make the executable so that the add() from lib1.so is used?
(trying to override the function this way too :) just an idea though)

Thank you all very much in advance :)
Regards
5 REPLIES
Wkdunreal
Advisor

Re: Overriding a function and .so priority setting.

current values:
32-bit ELF executable
shared library dynamic path search:
LD_LIBRARY_PATH enabled first
SHLIB_PATH enabled second
embedded path enabled third /usr/local/lib/gcc/ia64-hp-hpux11.23/4.0.2:/usr/ccs/bin:/usr/ccs/lib:/usr/local/lib
shared library list:
./library.so
arbasic.so
libc.so.1
shared library binding:
deferred
global hash table disabled
global hash table size 1103
shared library mapped private disabled
shared library segment merging disabled
shared vtable support disabled
explicit unloading disabled
linkage table protection disabled
segments:
index type address flags size
8 text 04000000 z---c- D (default)
9 data 40010000 ---m-- D (default)
executable from stack: D (default)
kernel assisted branch prediction enabled
lazy swap allocation for dynamic segments disabled
nulptr dereferences trap enabled
address space model: default
caliper dynamic instrumentation disabled
new values:
32-bit ELF executable
shared library dynamic path search:
LD_LIBRARY_PATH enabled first
SHLIB_PATH enabled second
embedded path enabled third /usr/local/lib/gcc/ia64-hp-hpux11.23/4.0.2:/usr/ccs/bin:/usr/ccs/lib:/usr/local/lib
shared library list:
./library.so
arbasic.so
libc.so.1
shared library binding:
deferred
global hash table disabled
global hash table size 1103
shared library mapped private disabled
shared library segment merging disabled
shared vtable support disabled
explicit unloading disabled
linkage table protection disabled
segments:
index type address flags size
8 text 04000000 z---c- D (default)
9 data 40010000 ---m-- D (default)
executable from stack: D (default)
kernel assisted branch prediction enabled
lazy swap allocation for dynamic segments disabled
nulptr dereferences trap enabled
address space model: default
caliper dynamic instrumentation disabled


This is the page that i get when I set the SHLIB_PATH using

export SHLIB_PATH

and then do the

chatr enable +s final (on the ELF file final 32 bit)

but as you see against the SHLIB_PATH , nonew path is set even after setting the SHLIB_PATH.


any ideas why this might be happening?

Regards and thanks :)
Dennis Handly
Acclaimed Contributor
Solution

Re: Overriding a function and .so priority setting.

>by using LD_PRELOAD ... But the same does not seem work for overriding self written functions.

Why not? Note: If your function is called from the same file, you can't override it.

>Is there a way to give lib1.so a higher priority than lib2.so

Only by ordering lib1 before lib2.

On Integrity, you should use LD_LIBRARY_PATH instead of SHLIB_PATH.

>but as you see against the SHLIB_PATH, no new path is set even after setting the SHLIB_PATH.

LD_LIBRARY_PATH amd SHLIB_PATH were already enabled, so chatr did nothing.

You need to export LD_LIBRARY_PATH and see what ldd shows you:
ldd final
Wkdunreal
Advisor

Re: Overriding a function and .so priority setting.

Hi Dennis,

I checked up creating ELf file by changing the order of the .so files and Viola it indeed did work :)

Thanks a bunch. This has made my headache soothe :D

Also LD_PRELOAD did work on hp ux..

Though on AIX LDR_PRELOAD or LDR_PRELOAD64 didnt seem to work.
( am doing the same thing on HP-UX 11.31 AIX 5.3 & solaris 10)

Could you explain the last part about exporting LD_LIBRARY_PATH in a bit more detail please? I didnt seem to get it right..

I had exported SHLIB_PATH.

thanks a lot again.
Was a great help :D
Dennis Handly
Acclaimed Contributor

Re: Overriding a function and .so priority setting.

>Could you explain the last part about exporting LD_LIBRARY_PATH in a bit more detail please? I had exported SHLIB_PATH.

Which part? Basically SHLIB_PATH is the obsolete PA32 way of doing things whereas LD_LIBRARY_PATH is standard.

If you export them, ldd will tell you which shlibs it will use when you are running the application.

You can read all about ld, dld and shlibs in:
http://docs.hp.com/en/14640/OnlineHelp/linkhelp.html

>thanks a lot again. Was a great help :D

Pleased read the following about how to assign points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33
Wkdunreal
Advisor

Re: Overriding a function and .so priority setting.

Thanks a lot once again.
:)

LD_LIBRARY_PATH des the trick..

Sorry I thought I had clicked on submit points after I had assignd points :|

Regards