Hello,
I have overridden system "stat" fucntion in a static library say "libmylib1".
And my shared library "libmylib2" is calling the "stat" function. My "test" program is linked with both the libraries. I have a stat call in test program as well. This "stat" is calling the one defined in libmylib1 but the stat call in libmylib2 is not calling the re-defined stat function, it's calling the standard system call.

Below are the contents of this static library libmylib1
--------------------------------------------------------------------
Makefile:-
%cat Makefile
LIB= mylib1
NOSHARED=yes
CFLAGS+=-O2 -g -Wall -Werror
SRCS= mapfile.c

.include <bsd.lib.mk>
---------------- mapfile.c --------
% cat mapfile.c

#include <sys/types.h>
#include <sys/param.h>
#include <pal/stat.h>
#include <sys/syscall.h>
#include <fcntl.h>
#include <stdio.h>
#define _stat(path, buf) syscall(pal_SYS_stat, path, buf)

int
stat(const char *path, struct stat *sb)
{
char *p;
// doing some processing on the path
printf("Stat function in mylib1..... \n");
return _stat((p) ? p : path, sb);
}

----------------------------------------------------------------------
Shared library libmylib2 contents :-

Makefile :-
% cat Makefile
LIB =mylib2
CFLAGS+=-Wall -Wimplicit -Werror -g -I$(.OBJDIR)
SRCS= f1.c


.include <bsd.lib.mk>
--------------------- f1.c --------------------

% cat f1.c

#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include "f1.h"
void myfunc(char *name)
{

struct stat buf;
stat(name,&buf);

}

----------f1.h ----------------

%cat f1.h

extern void myfunc(char *name);
-----------------------------------------

finally my test program:-
%cat test.c

#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

#include "f1.h"


int main()
{
struct stat buf;
char *path="/tmp/name";
stat("/tmp/xxx", &buf);
myfunc(path);
return 0;
}

-------------------- Makefile -----------

% cat Makefile

PROG= test

CFLAGS+= -Wall -Wimplicit -g -DDEBUG -Werror
CFLAGS += -I${.CURDIR}/../../lib/libmylib2


LDADD= -lmylib2 -lmylib1

NOMAN= 1
SRCS= test.c

.include <bdb.mk>
.include <bsd.prog.mk>

-----------------------------------------------------
Here is the output of the program
%./test
Stat function in mylib1.....

==> So the stat function in libmylib2 is not calling the re-defined stat fucntion in libmylib1


GDB session for the same:-
(gdb) b main
Breakpoint 1 at 0x80484df: file /home/rnaik/build/src/mira/usr.bin/test/test.c, line 11.
(gdb) r
Starting program: /home/rnaik/build/src/mira/usr.bin/test/test

Breakpoint 1, main () at /home/rnaik/build/src/mira/usr.bin/test/test.c:11
warning: Source file is more recent than executable.

11 char *path="/tmp/name";
(gdb) n
12 stat("/tmp/xxx", &buf);
(gdb) s
*stat64 (path=0x8048636 "/tmp/xxx", sb=0xbffecaa0) at /home/rnaik/build/src/mira/lib/libmylib1/mapfile.c:15
warning: Source file is more recent than executable.

15 printf("Stat function in mylib1..... \n");
(gdb) n
Stat function in mylib1.....
16 return _stat((p) ? p : path, sb);
(gdb) n
17 }
(gdb) n
main () at /home/rnaik/build/src/mira/usr.bin/test/test.c:13
13 myfunc(path);
(gdb) s
myfunc (name=0x804862c "/tmp/name") at /home/rnaik/build/src/mira/lib/libmylib2/f1.c:10
warning: Source file is more recent than executable.

10 stat(name,&buf); ---------==> didn't step into libmylib1 stat
(gdb) s
12 }
(gdb) s
main () at /home/rnaik/build/src/mira/usr.bin/test/test.c:14
14 return 0;



I am not able to figure out wht's causing the problem. Any help would be highly appreciated.

Thanks
Rhehan