dlsym call fails
manish kumar
deliver2manish at gmail.com
Thu Jul 21 09:52:16 UTC 2011
Hi,
#mipsel-linux-uclibc-gcc -g -W -Wall -lpthread -o free_twice
free_twice.cpp wrapper.c
(test case is attached in-line to this mail)
The attached test case fails with this version of uClibc based toolchain:
$ mipsel-linux-uclibc-gcc -v
Using built-in specs.
COLLECT_GCC=mipsel-linux-uclibc-gcc
COLLECT_LTO_WRAPPER=/home3/vdlguest/BCM_support/stbgcc-4.5.3-1.0/bin/../libexec/gcc/mipsel-linux-uclibc/4.5.3/lto-wrapper
Target: mipsel-linux-uclibc
Configured with: ../gcc-4.5.3/configure --target=mipsel-linux-uclibc
--enable-multilib
--prefix=/var/tmp/stbgcc-4.5.3-1.0-root-root//opt/toolchains/stbgcc-4.5.3-1.0
--with-local-prefix=/var/tmp/stbgcc-4.5.3-1.0-root-root//opt/toolchains/stbgcc-4.5.3-1.0/mipsel-linux-uclibc/sys-root
--with-sysroot=/var/tmp/stbgcc-4.5.3-1.0-root-root//opt/toolchains/stbgcc-4.5.3-1.0/mipsel-linux-uclibc/sys-root
--enable-threads=posix --enable-long-long --enable-c99
--enable-__cxa_atexit --with-gmp=/usr/src/redhat/BUILD/prereq
--with-mpfr=/usr/src/redhat/BUILD/prereq
--with-mpc=/usr/src/redhat/BUILD/prereq
--with-libelf=/usr/src/redhat/BUILD/prereq --disable-nls
--enable-symvers=gnu --enable-languages=c,c++ --enable-target-optspace
--with-pkgversion='Broadcom stbgcc-4.5.3-1.0'
--with-host-libstdcxx='-Wl,-Bstatic,-lstdc++,-Bdynamic -lm'
--with-mips-plt --with-arch=mips32 --with-float=hard
Thread model: posix
gcc version 4.5.3
=>uClibc v0.9.32-rc3
Output:
# ./free_twice
[wrapper] free [ 6226.611000] do_page_fault() : sending SIGSEGV to
free_twice, PID:202
called [0x0]
But the same test case passes with this toolchain:
$mipsel-linux-uclibc-gcc -v
Using built-in specs.
Target: mipsel-linux-uclibc
Configured with: ../gcc-4.2.0-20070124/configure
--prefix=/opt/toolchains/crosstools_sf-linux-2.6.18.0_gcc-4.2-10ts_uclibc-nptl-0.9.29-20070423_20080721/
--build=mipsel-linux --host=mipsel-linux --target=mipsel-linux-uclibc
--with-build-sysroot=/usr/src/redhat/BUILD/build_uClibc
--enable-languages=c,c++ --disable-__cxa_atexit
--enable-target-optspace --with-gnu-ld --with-float=soft
--enable-threads
--infodir=/opt/toolchains/crosstools_sf-linux-2.6.18.0_gcc-4.2-10ts_uclibc-nptl-0.9.29-20070423_20080721/info
--mandir=/opt/toolchains/crosstools_sf-linux-2.6.18.0_gcc-4.2-10ts_uclibc-nptl-0.9.29-20070423_20080721/man
--with-arch=mips32 --disable-libmudflap --disable-nls --with-gnu-plts
Thread model: posix
gcc version 4.2.0 20070124
=> uclibc-nptl-0.9.29
Output:
# ./free_twice
[wrapper] free called [0x0]
[wrapper] malloc called size = 40 Address = 0x402008
[wrapper] free called [0x402008]
[wrapper] free called [0x402008]
CPU:MIPS 74Kc V4.12 FPU V0.0
This test case works well with glibc based toolchain. Is this a bug in
uClibc or am I missing something?
free_twice.cpp:
-----------------------
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i = 0;
int *ptr = (int*) malloc ( 10* sizeof(int));
for ( i = 0 ; i < 10; i++)
ptr[i] = i;
free(ptr);
free(ptr);
}
wrapper.c:
----------------
#include <stdio.h>
#define __USE_GNU
#include <dlfcn.h>
#include <string.h>
static void* (*libc_malloc)(size_t) = 0;
static void (*libc_free)(void *) = 0;
void * malloc(size_t size)
{
if(!libc_malloc)
libc_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc"); dlerror();
void *ptr = NULL;
printf(" [wrapper] malloc called size = %d ",size);
ptr = libc_malloc(size);
printf(" Address = 0x%x \n",ptr);
return ptr;
}
void free(void *ptr)
{
if(!libc_free)
libc_free = (void (*)(void *))dlsym(RTLD_NEXT, "free"); dlerror();
printf(" [wrapper] free called [0x%x] \n",ptr);
libc_free(ptr);
return;
}
Regards,
Manish
More information about the uClibc
mailing list