ldd segfault

Natanael Copa natanael.copa at gmail.com
Tue May 5 13:30:06 UTC 2009


Hi,

While trying make asterisk 1.6.2.0-beta1 running on uclibc I hit a bug
in ldd. I suspsect that asterisk 1.6.2 branch is doing som linker magic
that pulls in ld-uClibc for the .so modules which makes ldd go nuts.

A simplified testcase:

/* dummy.c */
#include <stdio.h>
extern void _dl_getenv(void);
void foo(void)
{
	printf("foo: %x\n", &_dl_getenv);
}

Compile and link the .so:
gcc -shared -o dummy.so dummy.c

Verify that ld-uClibc got linked in:
$ readelf -d dummy.so | grep NEEDED
 0x00000001 (NEEDED)                     Shared library: [libc.so.0]
 0x00000001 (NEEDED)                     Shared library: [ld-uClibc.so.0]


Now, lets segfault ldd:
ldd ./dummy.so 
checking sub-depends for '/lib/libc.so.0'
Segmentation fault


It will segfault around row 522:
           tmp1 = tmp2 = cur->name;
           while (*tmp1) {

due to cur->name beeing NULL.

It is set to NULL in find_elf_interpreter() around row 577:

                for (cur = lib_list; cur; cur = cur->next) {
                        /* Check if this library is already in the list */
                        if (strcmp(cur->name, tmp1) == 0) {
                                printf("find_elf_interpreter is replacing '%s' (already in list)\n", cur->name);
                                newlib = cur;
                                free(newlib->name);
                                if (newlib->path != not_found) {
                                        free(newlib->path);
                                }
                                newlib->name = NULL;
                                newlib->path = NULL;
                                return NULL;
                        }
                }


where it seems to be supposed to replace the libray in the lib_list if
its already there but code does not even try to unlink the element. It
just set the name and path to NULL and returns.

I checked the history and it seems like it have been like this the
beginning.

Now, I'm not really sure which is the way to fix this. I can get it not
segfault by testing i cur->name is NULL before using it and skip
printing those entries. But that does not look correct either.

Ideas?

-nc



More information about the uClibc mailing list