Bug 5434 - Problem with FILEs and/or shared libraries
Problem with FILEs and/or shared libraries
Product: Red Hat Linux
Classification: Retired
Component: libc (Show other bugs)
i386 Linux
high Severity high
: ---
: ---
Assigned To: Cristian Gafton
Depends On:
  Show dependency treegraph
Reported: 1999-09-29 08:05 EDT by armand.bendanan
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 1999-10-05 02:34:48 EDT
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 armand.bendanan 1999-09-29 08:05:08 EDT
It seams that I have found a bug related with shared
libraries and/or FILEs (I don't know).

The program is composed with :

- inlib.c	a little function 'read_file' that open a file and
close it
- inlib.h	declaration of the function
- main.c	main program that calls the function, plus
something ...

the something is to test if a FILE variable 'msgf' is NULL
or not.
This produce a crash in some conditions :

1 - if inlib.o is put in a library : the program crash
otherwise not.
2 - if I open the FILE variable (as it is done in the
'read_file' function)
		BEFORE calling the 'read_file' function, the program
works, otherwise not.
3 - if I don't try to test the FILE variable 'msgf' at the
end of the main
		the program works, otherwise not.

You will find in the tar file 'BUG_LINUX.tar', the following
- file.txt		any text file just for opening it
- inlib.c		the 'read_file' function
- inlib.h		a header for the 'read_file' function
- main.c		the main program
- makefile		for building the main program
- README.txt	this file

PS : how to send you a tar file ???????????????????

Here is the linux (Mandrake 6.0) version:

>>>> uname -a
Linux pcabe 2.2.5-15 #1 Mon Apr 19 23:00:46 EDT 1999 i686

Here is the gcc version:

>>>> gcc --version

As it is, the main program produces a core dump.
Here is the command to launch my program, and the trace of
the core dump:

>>>> make clean; make && (main || gdb main core)
rm core inlib.o main.o libalib.so main 2> /dev/null
gcc  -g  -c inlib.c -o inlib.o
gcc  -g  -c main.c -o main.o
ld -o libalib.so -G inlib.o
gcc -o main main.o libalib.so
GNU gdb with Linux support
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public
License, and you are
welcome to change it and/or distribute copies of it under
certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show
warranty" for details.
This GDB was configured as "i386-redhat-linux"...
Core was generated by `main'.
Program terminated with signal 11, Erreur de segmentation.
Reading symbols from /tmp/traj/src/prst/./libalib.so...done.
Reading symbols from /lib/libc.so.6...done.
Reading symbols from /lib/ld-linux.so.2...done.
#0  0x400721f1 in _IO_old_file_close_it (fp=0x8049848) at
oldfileops.c:143: Aucun fichier ou ripertoire de ce type.
(gdb) bt
#0  0x400721f1 in _IO_old_file_close_it (fp=0x8049848) at
#1  0x4006e595 in _IO_old_fclose (fp=0x8049848) at
#2  0x40014259 in read_file (file_name=0x80486e0 "file.txt")
at inlib.c:12
#3  0x80485f6 in main (argc=1, argv=0xbffff864) at main.c:23
#4  0x40032cb3 in __libc_start_main (main=0x80485e0 <main>,
argc=1, argv=0xbffff864,
    init=0x8048470 <_init>, fini=0x804868c <_fini>,
rtld_fini=0x4000a350 <_dl_fini>,
    stack_end=0xbffff85c) at

Here are the libraries linked with my program :

>>>> ldd main
        libalib.so => ./libalib.so (0x40014000)
        libc.so.6 => /lib/libc.so.6 (0x4001b000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2

>>>> ls -l  /lib/libc.so.6
lrwxrwxrwx   1 root     root           13 Sep 14 13:39
/lib/libc.so.6 -> libc-2.1.1.so*

>>>> ls -l /lib/libc-2.1.1.so
-rwxr-xr-x   1 root     root      4016683 Apr 17 00:48

>>>> ls -l /lib/ld-linux.so.2
lrwxrwxrwx   1 root     root           11 Sep 14 13:39
/lib/ld-linux.so.2 -> ld-2.1.1.so*

>>>> ls -l /lib/ld-2.1.1.so
-rwxr-xr-x   1 root     root       342206 Apr 17 00:49

Comment 1 armand.bendanan 1999-09-29 08:20:59 EDT
I am sorry, it is not a mandrake version, but a red hat 6.0 version.

As I don't know how to send you my files, here they are :

------------------------- file : makefile:
CC			= gcc

LIBRARY			= libalib.so
PROGRAM			= main
OBJECTS			= inlib.o main.o

all			: $(TARGETS)

clean			:
	rm core $(TARGETS) 2> /dev/null

$(PROGRAM)		: main.o $(LIBRARY)
	$(CC) -o $@ main.o $(LIBRARY)

$(LIBRARY)		: inlib.o
	ld -o $@ -G inlib.o

inlib.o			: inlib.c
main.o			: main.c inlib.h

------------------------- file : inlib.h
#ifndef _IN_LIB_H_
#define _IN_LIB_H_

extern int read_file (char *file);

------------------------- file : inlib.c:
#include <stdio.h>
#include "inlib.h"

extern int read_file (char	*file_name)
	FILE	*fd = fopen(file_name, "r");
	if (fd == NULL) {
		printf("error opening file:%s\n", file_name);
		return 1;
	fclose (fd);
	return 0;
------------------------- file : main.c:
#include <stdio.h>
#include "inlib.h"

FILE    *msgf		= NULL;

int main (int argc, char **argv)
	char    *file_name = "file.txt";

	 * if I uncomment the following lines, the program works ??? !!!
	FILE	*fd = fopen(file_name, "r");
	if (fd == NULL) {
		printf("error opening file:%s\n", file_name);
		return 1;
	fclose (fd);

	if (read_file (file_name) != 0) {
		printf ("Exit\n");
		exit (1);

	 * if I comment the following 3 lines, the program works ??? !!!
    if (msgf == NULL) {
        msgf = fopen ("/dev/null", "w");

	printf ("################### WON ==============\n");
	fflush (stdout);

	return 0;
Comment 2 Cristian Gafton 1999-10-05 02:34:59 EDT
Works for me, provided that you are actually using -fPIC compiler
option and -shared linker option to generate correctly the shared

I don't know about Mandrake - one thing I know for sure is that their
optimized compiler is screwing up big time glibc on their system (and
not only that, but we won't get into that)

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