1833888 Members
2013 Online
110063 Solutions
New Discussion

Re: lazyload of

 
SOLVED
Go to solution
kenneth kahn_4
Occasional Contributor

lazyload of

Assume the following shared library (testlib.c)

#include <STDIO.H>
#include <STDLIB.H>

extern int fct1(void);
int fct2(void);

int fct1() {
#ifdef x1
printf("x1\n");
#else
printf("x2\n");
#endif
return fct2();
}

int fct2() {
#ifdef x1
printf("x1\n");
return 11;
#else
printf("x2\n");
return 22;
#endif
}

> aCC +z -b -o x1 -Dx1 testlib.c
> aCC +z -b -o x2 testlib.c

and the following executable (testx.c)

/* testx.c */
#include <STDLIB.H>
#include <STDIO.H>
#include <STRINGS.H>
#include <UNISTD.H>

extern int fct1(void);

int main(int ArgC,char *ArgV[]) {
/*------------------------------------------*
! Remove existing copy of libx.so softlink !
*------------------------------------------*/
remove("libx.sl");
/*------------------------------------------*
! create new instance of libx.so softlink !
*------------------------------------------*/
symlink(((ArgC > 1) &&!strcmp("x1",ArgV[1])) ?
"x1" : "x2","libx.sl");
printf("fct2=%d\n",fct1());
}

> ln -fs x2 libx.sl
> aCC -o testx -L. -lx testx.c

If I build these same executables on a Sun 5.7 system using CC and specifying

> CC -o testx -zlazyload -L. -lx test.C

running "testx1 x1" will *always* produce the output

x1
x1
fct2=11

even if the softlink starts off as "libx.so -> x2", verifying that the lazyload binding for fct1() has indeed occured as expected (and as I
need it to).

However, under HP-UX, if the softlink again starts off as "libx.so -> x2", running "testx
x1" will initially result in

x2
x2
fct2=22

and then on subsequent runs

x1
x1
fct2=11

This appears to me that the lazyload binding of fct1() is *not* occuring; i.e. the new softlink for libx.so to x1 is not being picked up until
the next invocation of "testx x1".

According to the documention, lazyload binding should be the default; I've tried adding the -Wl,-Bdeferred" switch with the same results.

Am I missing something, or doing something wrong? Shouldn't this work as the same on Solaris and HP-UX?

 

 

 

Moved from HP-UX Technical Documentation to HP-UX > languages

4 REPLIES 4
kenneth kahn_4
Occasional Contributor

Re: lazyload of

To simplify my question, take the case of the following program:

#include
#include
extern int so_fct(void);
int main() {
system("sleep 30");
printf("so_fct=%d",so_fct);
}

> aCC -o testx -L. -z -Wl,-Bdeferred -lx testx.c

The function so_fct is part of the libx.sl shared library. According to my understanding of things, libx shouldn't be loaded until the so_fct is actually referenced. If I start this test program then issue an "fuser -u libx.sl" before the sleep expires, I get

libx.sl: ####m(userid)

showing that libx has already loaded *before* the reference to so_fct has occured. Isn't this counter to the way lazyload should work?

If I try this on a Solaris system, fuser shows that libx is not loaded until so_fct is actually referenced, which is what I want.

Am I misunderstanding how Lazyload should be working? Is there someway to resolve this (i.e. not have libx loaded until so_fct is
referenced)? I'm having the same problem on HP-UX, so perhaps Solaris is the *only* system that properly implements lazyload???

Robert-Jan Goossens
Honored Contributor
Solution

Re: lazyload of

kenneth kahn_4
Occasional Contributor

Re: lazyload of

Robert-Jan, that's exactly what I was looking for; 'real' lazyloading is now working.

Much thanks.
Hemanth Gurunath Basrur
Honored Contributor

Re: lazyload of

Hello Kenneth,

You wrote:

According to the documention, lazyload binding should be the default; I've tried adding the -Wl,-Bdeferred" switch with the same results.

Which documentation did you refer to from http://docs.hp.com? Your feedback can help us improve the documentation.

Thanks,
Hemanth