bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stat() problem in shared libraries (yes /usr/lib/libc.so is correct)


From: Michael F. Brown
Subject: stat() problem in shared libraries (yes /usr/lib/libc.so is correct)
Date: Thu, 20 Sep 2001 11:22:08 -0400 (EDT)

Hi,

I've read the glibc FAQ as well as searched this lists archives for
an answer on this issue.

We ship a shared object which uses stat, and on more recent versions
of glibc (2.2.2) when running with our library we get the error
message:

"error while loading shared libraries: /usr/lib/libmy_stat.so:
undefined symbol: stat"

Yes, /usr/lib/libc.so looks like:

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a )

This is reproducible on various linux hosts.

Here's a sample program and Makefile:

---- Makefile ----

all: my_main

my_main: my_main.c /lib/libmy_stat.so
        gcc -Wall -g -o my_main my_main.c -lmy_stat

/lib/libmy_stat.so: my_stat.o
        ld -G -dy -o /lib/libmy_stat.so my_stat.o

my_stat.o: my_stat.c my_stat.h
        gcc -Wall -g -o my_stat.o -c my_stat.c


clean:
        rm -f /lib/libmy_stat.so my_stat.o my_main

---- my_stat.h ----

extern int my_stat(const char *file_name, struct stat *buf);

---- my_stat.c ----

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

int my_stat(const char *file_name, struct stat *buf)
{
   return stat (file_name, buf);
}

---- my_main.c ----

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

#include <stdio.h>

#include "my_stat.h"

int main (int argc, char **argv)
{
   struct stat stat_buffer;

   if (my_stat ("/etc/passwd", &stat_buffer) == -1)
   {
      perror ("my_stat failed");
      return 1;
   }

   return 0;
}

----  ----

On earlier versions of glibc (2.1.1) the above program compiles
and runs fine.  On later versions (2.2.2) the runtime error appears.

If we add -lc or -lc_nonshared to the ld line in the Makefile, this
fixes the issue on recent versions, but this causes stat to be
statically linked into our shared object.  Is this correct behavior?

Thanks, please reply to me directly as I'm not subscribed to the list.


-Michael F. Brown, Sym API - EMC Corp.

email:  address@hidden

"In theory, there is no difference between theory and practice,
 but in practice, there is."       - Jan L.A. van de Snepscheut




reply via email to

[Prev in Thread] Current Thread [Next in Thread]