[uClibc]Question on building shared objects -- possible bug

David Koo nothing2n at yahoo.com
Fri Oct 11 03:52:17 UTC 2002


Hi All,

> I've finally had some success in building a shared object to use
> with dlopen() on a mipsel system. I still get into trouble
> (segfault) when I try to call a function

    I don't have a solution, but I'd like to say that I'm facing a
similar problem on a mips big-endian machine. The programs in question
are in the "test/ldso" (dltest, etc) directory of the uclibc directory.

    A few things to note though ...

    I had to modify the Rules.mak file in the "test" directly and
change LDFLAGS and CFLAGS so that they don't include the
"--uclibc-build-dir" switch. I'm using a cross compiler and so the
final installation path is what I want to use, not the build directory
paths. I don't know if this contributes anything to the problem
though.

    A second thing to note is that the "dlopen" in test/ldso/dltest.c
seems to be failing - a printf message just after the dlopen doesn't
come. In fact, I changed the printf() to an "open()" and used "strace"
to see if it gets to the "open()" call (which will obviously fail, but
thats ok - at least I know its gone past dlopen). The "open()" call
hasn't yet been traced when the segfault happens. I'm pasting a copy
of the modified dltest.c and the strace output at the end of this mail
... anybody has any clues?

    Thanks.

Koo
--
Windows - just another pane.

------------ dltest.c ---------
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

extern void _dlinfo();

int main(int argc, char **argv) {
        void *handle;
        int (*myhowdy)(const char *s);
        char *error;

        handle = dlopen ("./libhowdy.so", RTLD_LAZY);
#if 1
        /* this doesn't come in strace output! */
        open("opened libhowdy.so", 0);
#endif

        if (!handle) {
                fputs (dlerror(), stderr);
                exit(1);
        }

        myhowdy = dlsym(handle, "howdy");
        if ((error = dlerror()) != NULL)  {
                fputs(error, stderr);
                exit(1);
        }

        myhowdy("hello world!\n");

#ifdef __UCLIBC__
        _dlinfo();   /* not supported by ld.so.2 */
#endif

        dlclose(handle);

        return EXIT_SUCCESS;
}


------------ strace dump ------------

# strace ./dltest
execve("./dltest", ["./dltest"], [/* 5 vars */]) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
0, 0) = 0x2aaae000
mprotect(0x2aaa8000, 22208, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mprotect(0x400000, 2960, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
readlink("/lib/ld-uClibc.so.0", "ld-uClibc-0.9.15.so", 1024) = 19
open("/lib/libdl.so.0", O_RDONLY)       = 3
read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\10\0\0\0\1\0\0\7"...,
4096) = 4096
old_mmap(NULL, 270336, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x2aaee000
old_mmap(0x2aaee000, 6896, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,
3, 0) = 0x2aaee000
old_mmap(0x2ab2f000, 2980, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, 3, 0x1000) = 0x2ab2f000
close(3)                                = 0
mprotect(0x2aaee000, 6896, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
open("/lib/libc.so.0", O_RDONLY)        = 3
read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\10\0\0\0\1\0\0\223"...,
4096) = 4096
old_mmap(NULL, 622592, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x2ab30000
old_mmap(0x2ab30000, 342080, PROT_READ|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x2ab30000
old_mmap(0x2abc3000, 11224, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, 3, 0x53000) = 0x2abc3000
old_mmap(0x2abc6000, 8152, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2abc6000
close(3)                                = 0
mprotect(0x2ab30000, 342080, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mprotect(0x400000, 2960, PROT_READ|PROT_EXEC) = 0
mprotect(0x2aaee000, 6896, PROT_READ|PROT_EXEC) = 0
mprotect(0x2ab30000, 342080, PROT_READ|PROT_EXEC) = 0
mprotect(0x2aaa8000, 22208, PROT_READ|PROT_EXEC) = 0
ioctl(0, 0x540d, {B9600 opost isig icanon echo ...}) = 0
ioctl(1, 0x540d, {B9600 opost isig icanon echo ...}) = 0
open("./libhowdy.so", O_RDONLY)         = 3
read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\10\0\0\0\1\0\0\10"...,
4096) = 4096
old_mmap(NULL, 266240, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x2abc8000
old_mmap(0x2abc8000, 3128, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,
3, 0) = 0x2abc8000
old_mmap(0x2ac08000, 3244, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x2ac08000
close(3)                                = 0
mprotect(0x2abc8000, 3128, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
brk(0x100030a0)                         = 0x100030a0
brk(0x10004000)                         = 0x10004000
brk(0x10005000)                         = 0x10005000
brk(0x10006000)                         = 0x10006000
brk(0x10007000)                         = 0x10007000
brk(0x10008000)                         = 0x10008000
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
#




More information about the uClibc mailing list