This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Shared libraries on Alpha
- To: gcc at gcc dot gnu dot org
- Subject: Shared libraries on Alpha
- From: "K. Holcomb" <kholcomb at cs dot virginia dot edu>
- Date: Wed, 23 Feb 2000 10:18:14 -0500 (EST)
Hello,
I am sending this to the general list because we are not certain whether this
is a bug in gcc or something else, or even a problem on our part. We have a
large, complex application that is failing on Alpha systems upgraded to
RedHat 6.1 with a further upgrade to gcc 2.95.2, but which works on older
systems as well as on upgraded Intels. The problem *seems* to be that
gettimeofday returns different results depending on whether it is called via
a statically linked or a dynamic library. The static linking works; dynamic
does not. It appears that dynamic libraries are using a 32-bit implementation
of gettimeofday, whereas the other cases invoke a 64-bit implementation.
We'd be grateful for any suggestions or information; has anybody else seen
anything similar on Alphas?
The attached short test program reproduces the problem:
----------------------------------------------------------------------------
test_get_time.c:
----------------
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
extern struct timeval get_time();
int main(int argc, char **argv)
{
struct timeval now;
int ret, i;
char time_array[16];
for (i = 0; i < 16; i++)
{
time_array[i] = 0;
}
ret = gettimeofday(&now, 0);
fprintf(stderr, "Time in main program:\nret = %d\n", ret);
fprintf(stderr, "now = %ld.%ld\n", now.tv_sec, now.tv_usec);
fprintf(stderr, "now = %d.%d\n", now.tv_sec, now.tv_usec);
ret = gettimeofday((struct timeval *) time_array, 0);
fprintf(stderr, "IN test_get_time(): ret = %d. Char array = \n", ret);
for (i = 0; i < 16; i++)
{
fprintf(stderr, "byte %d = %x\n", i, time_array[i]);
}
now = get_time();
fprintf(stderr, "Time from function call:\n");
fprintf(stderr, "now = %ld.%ld\n", now.tv_sec, now.tv_usec);
fprintf(stderr, "now = %d.%d\n", now.tv_sec, now.tv_usec);
}
---------------------------------------
get_time_func.c:
----------------
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
struct timeval get_time()
{
struct timeval now;
int ret, i;
char time_array[16];
ret = gettimeofday(&now, 0);
fprintf(stderr, "IN get_time(): ret = %d\n", ret);
fprintf(stderr, "now = %ld.%ld\n", now.tv_sec, now.tv_usec);
fprintf(stderr, "now = %d.%d\n", now.tv_sec, now.tv_usec);
for (i = 0; i < 16; i++)
{
time_array[i] = 0;
}
ret = gettimeofday((struct timeval *) time_array, 0);
fprintf(stderr, "IN get_time(): ret = %d. Char array = \n", ret);
for (i = 0; i < 16; i++)
{
fprintf(stderr, "byte %d = %x\n", i, time_array[i]);
}
return now;
}
-----------------------------------------
makefile:
--------
CC = gcc
RM = /bin/rm -f
SRC_DIR = .
BIN_DIR = .
LIB_DIR = .
OBJ_DIR = .
CFLAGS = -I. -v
BINARIES = $(BIN_DIR)/test_get_time
OBJECTS = $(OBJ_DIR)/get_time_func.o
LIBRARY = $(LIB_DIR)/libGetTime.a
SHARED_LIBRARY = $(LIB_DIR)/libGetTime.so
all:
make $(OBJECTS)
make $(LIBRARY)
make $(SHARED_LIBRARY)
make $(BINARIES)
clean:
-$(RM) $(LIBRARY)
-$(RM) $(SHARED_LIBRARY)
-$(RM) $(OBJECTS)
-$(RM) $(BINARIES)
$(LIBRARY): $(OBJECTS)
ar crv $(LIBRARY) $(OBJECTS)
$(SHARED_LIBRARY): $(OBJECTS)
-ld -o $(SHARED_LIBRARY) -shared $(OBJECTS) $(SO_LIB_FLAGS)
$(OBJ_DIR)/get_time_func.o: $(SRC_DIR)/get_time_func.c
$(CC) $(CFLAGS) -fpic -c $(SRC_DIR)/get_time_func.c -o $@
$(BIN_DIR)/test_get_time: $(OBJ_DIR)/get_time_func.o $(SRC_DIR)/test_get_time.c
$(CC) $(CFLAGS) $(SRC_DIR)/test_get_time.c -L. -lGetTime -o $@