tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] dlopen crashes when loading shared object


From: Ryan Mansfield
Subject: [Tinycc-devel] dlopen crashes when loading shared object
Date: Tue, 30 Nov 2004 16:47:12 -0700

Hello, 

I have a problem where when I try to load a shared object created by tcc, it 
crashes in dl_sym. If shared object is built with gcc, the crash does not occur.

tcc version 0.9.20

Testcase:

address@hidden:~/503$ cat reduced.c

#include <stdio.h>
#include <dlfcn.h>

int main() {
    static char *code[] = {
                          "int test(int tmp, int tmp2, char *fp, char *ip, char 
*sp ) {",
                          "int i; i = i + i;", "i++;", "i = i&&i;",
                          "printf(\"hello\");",
                          "}",
                          NULL};
    char filename[] = {"test.c"};
    char *array;
    char **ptr;
    FILE *fd;
    int i;
    fd = fopen("test.c", "w");
    for(ptr=code; *ptr; ptr++) {
      fprintf(fd, "%s\n", *ptr);
    }
    fclose(fd);
    system("tcc -shared -rdyanmic -o test.so test.c");
    void* handle = dlopen("./test.so", RTLD_LAZY);
    if (!handle) {
        printf("Cannot open library: %s\n",dlerror());
        return 1;
    }
    typedef void (*hello_t)();
    hello_t hello = (hello_t) dlsym(handle, "test");
    if (!hello) {
        fprintf(stderr, "Cannot load symbol 'hello': %\n",  dlerror());
        dlclose(handle);
        return 1;
    }
    hello();
    dlclose(handle);
}


address@hidden:~/503$ gcc reduced.c -ldl -g
address@hidden:~/503$ gdb ./a.out
GNU gdb 6.3-debian
Copyright 2004 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-linux"...Using host libthread_db
library "/lib/tls/libthread_db.so.1".

(gdb) run
Starting program: /home/ryan/503/a.out
Detaching after fork from child process 15133.

Program received signal SIGSEGV, Segmentation fault.
0x40011900 in realloc () from /lib/ld-linux.so.2
(gdb) bt
#0  0x40011900 in realloc () from /lib/ld-linux.so.2
#1  0x400076fb in _dl_unload_cache () from /lib/ld-linux.so.2
#2  0x40007def in _dl_lookup_symbol () from /lib/ld-linux.so.2
#3  0x40137d3c in _dl_sym () from /lib/tls/libc.so.6
(gdb)

If I compile the .so with gcc, it works fine. 

address@hidden:~/503$ diff -u reduced.c reducedgcc.c
--- reduced.c   2004-11-30 16:13:28.000000000 -0700
+++ reducedgcc.c        2004-11-30 16:19:45.000000000 -0700
@@ -17,7 +17,7 @@
       fprintf(fd, "%s\n", *ptr);
     }
     fclose(fd);
-    system("tcc -shared -rdynamic -o test.so test.c");
+    system("gcc -shared -o test.so test.c");
     void* handle = dlopen("./test.so", RTLD_LAZY);
     if (!handle) {
         printf("Cannot open library: %s\n",dlerror());

address@hidden:~/503$ gcc -ldl -g reducedgcc.c
address@hidden:~/503$ ./a.out
hello

If anyone could provide any help I would greatly appreciate.it.

Thanks in advance, 

Regards, 

Ryan Mansfield




reply via email to

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