Bug 55611 - Dynamic linked libs don't work properly in RH7.1
Dynamic linked libs don't work properly in RH7.1
Product: Red Hat Linux
Classification: Retired
Component: binutils (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2001-11-02 16:24 EST by steve moss
Modified: 2008-05-01 11:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-11-02 16:24:25 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description steve moss 2001-11-02 16:24:20 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; SunOS 5.8 sun4u)

Description of problem:
Dynamic libs which include a reference to stat() will fail to resolve
symbol if linked on RH7.1.  The standard libc /usr/lib/libc.so is a text
file that contains this line:          GROUP ( /lib/libc.so.6
/usr/lib/libc_nonshared.a ) and the stat function is found in the static
lib.  But for some reason if linked using a 7.1 linker the symbol fails to
resolve. If linked on 7.0 or 6.2 it resolves fine.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. See below for source files main.cxx st.c 
2.  gcc -c main.cxx
3.  gcc -c st.c
4.  /usr/bin/ld -v -shared -fPIC -o libtest.so st.o
5. gcc main.o libtest.so
6. setenv LD_LIBRARY_PATH .
7. ./a.out /tmp

Actual Results:  mylanta[2] gcc -c main.cxx
mylanta[3] gcc -c st.c
mylanta[4] /usr/bin/ld -v -shared -fPIC -o libtest.so st.o
GNU ld version 2.10.91 (with BFD
mylanta[5] gcc main.o libtest.so
mylanta[6] ./a.out /tmp
./a.out: error while loading shared libraries: ./libtest.so: undefined
symbol: stat

Expected Results:  Filesystem /tmp uses blocks of size 4096

Additional info:

#include <stdio.h>
#include <stdlib.h>
extern "C" int print_stats( char *);

main (int argc, char ** argv ) {
   if (argc>1)
      for (int i=1; i<argc; i++)
         print_stats( argv[i] );
      printf("Missing argument\n");
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>

int print_stats(char *filename ) {
   struct stat buffer;
   if (stat( filename, &buffer )==0)
      printf("Filesystem %s uses blocks of size %ld\n", filename,
      printf("Error stating %s\n", filename);
   return 0;

Comment 1 Jakub Jelinek 2001-11-02 19:08:14 EST
You should never use ld -shared to link shared library, that's what
gcc -shared is for. It takes care of all necessary libs, options and objects.

Note You need to log in before you can comment on or make changes to this bug.