Bug 55611

Summary: Dynamic linked libs don't work properly in RH7.1
Product: [Retired] Red Hat Linux Reporter: steve moss <steve_moss>
Component: binutilsAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-11-02 21:24:25 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description steve moss 2001-11-02 21:24:20 UTC
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:
Always

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 2.10.91.0.2)
mylanta[5] gcc main.o libtest.so
setenv LD_LIBRARY_PATH .
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:

---------
main.cxx
----------
#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] );
   else
      printf("Missing argument\n");
   exit(0);
}
--------
st.c
---------
#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,
buffer.st_blksize);
   else
      printf("Error stating %s\n", filename);
   return 0;
}

---------

Comment 1 Jakub Jelinek 2001-11-03 00:08:14 UTC
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.