|
From: Nicholas N. <nj...@ca...> - 2004-03-22 10:29:37
|
On Mon, 22 Mar 2004, RAMPARANY Fano FTRD/DIH/GRE wrote:
> I've tested the simple "valgrind a.out" on a very
> simple program that creates and runs one thread (source
> appended below) and unfortunately, it aborts
> producing the following trace:
>
> ------------
> g-d510-28> valgrind a.out
> =3D=3D2683=3D=3D Memcheck, a.k.a. Valgrind, a memory error detector for x=
86-linux.
> =3D=3D2683=3D=3D Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward=
=2E
> =3D=3D2683=3D=3D Using valgrind-2.0.0, a program supervision framework fo=
r x86-linux.
> =3D=3D2683=3D=3D Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward=
=2E
> =3D=3D2683=3D=3D Estimated CPU clock rate is 2398 MHz
> =3D=3D2683=3D=3D For more details, rerun with: -v
> =3D=3D2683=3D=3D
> =3D=3D2683=3D=3D Warning: segment-override prefix encountered, but thread=
has no LDT
> =3D=3D2683=3D=3D Warning: segment access: virtual addr 0 exceeds segment =
limit of 0
> =3D=3D2683=3D=3D Invalid read of size 4
> =3D=3D2683=3D=3D at 0x40236234: (within /lib/i686/libpthread-0.9.so)
> =3D=3D2683=3D=3D by 0x40232CE6: __pthread_mutex_lock (in /lib/i686/lib=
pthread-0.9.so
> =3D=3D2683=3D=3D by 0x4026BC58: (within /lib/i686/libc-2.2.5.so)
> =3D=3D2683=3D=3D by 0x4026BC78: __cxa_atexit (in /lib/i686/libc-2.2.5.=
so)
> =3D=3D2683=3D=3D Address 0x0 is not stack'd, malloc'd or free'd
> Segmentation fault
> ------------------
>
> Do you know what I should have done wrong?
I don't think the problem is your fault. I tried your program under
Valgrind, and it worked for me (well; I had to add a pthread_join() call
in main() after the pthread_create(), otherwise main() terminates before
the created thread runs).
So it's not a problem with your program; I think it's a problem with
Valgrind or gcc or libc or a combination. Unfortunately, I'm no expert on
the segment-override stuff and can't help your further. I've cc'd the
valgrind-users list in case anyone else knows more.
N
> Note that running "a.out" (without valgrind) is OK
> -------------------
> g-d510-28> cc thread.c -lpthread
> g-d510-28> a.out
> in print_message_function (): 0
> in print_message_function (): 1
> in print_message_function (): 2
> in print_message_function (): 3
> in print_message_function (): 4
> in print_message_function (): 5
> in print_message_function (): 6
> in print_message_function (): 7
> in print_message_function (): 8
> in print_message_function (): 9
> ---------------------
>
> And that my program thread.c is a minimal simple
> Program that create and run one thread.
> ----------------------
> g-d510-28> more thread.c
> #include <stdio.h>
>
> #define NB_ITER 10
>
> void print_message_function ()
> {
> short i;
> for (i=3D0;i<NB_ITER;i++)
> printf ("%s %d\n", "in print_message_function ():", i);
> pthread_exit (0);
> }
>
> int main ()
> {
>
> int procarg;
> pthread_t thread1;
> pthread_attr_t pthread_attr_default;
>
> pthread_attr_init (&pthread_attr_default);
> pthread_create (&thread1, &pthread_attr_default,
> (void *) &print_message_function, (void *) &procarg);
> /*
> */
>
> printf("\n");
> return 0;
> }
> ----------------------
>
>
> -----Message d'origine-----
> De : Nicholas Nethercote [mailto:nj...@he...] De la part de Ni=
cholas Nethercote
> Envoy=E9 : vendredi 19 mars 2004 17:41
> =C0 : RAMPARANY Fano FTRD/DIH/GRE
> Cc : Julian Seward; Jeremy Fitzhardinge; Nicholas Nethercote
> Objet : Re: Pthread problems...
>
>
> On Fri, 19 Mar 2004, RAMPARANY Fano FTRD/DIH/GRE wrote:
>
> > Now, I've got some problem in using valgrind on a multithreaded
> > Program. I've discovered that I should use the libpthread.so Library
> > rather than the one in /usr/lib. However, when compiling and linking
> > my .c file I get the following
> > Error:
> >
> > g-d510-28> cc thread.c
> > /user/nfs2/ramparfa/unix/Util/valgrind-2.0.0/coregrind/libpthread.so
> > /user/nfs2/ramparfa/unix/Util/valgrind-2.0.0/coregrind/valgrind.so
> > /user/nfs2/ramparfa/unix/Util/valgrind-2.0.0/coregrind/valgrind.so:
> > undefined reference to `vgPlain_skin_interface_minor_version'
> > /user/nfs2/ramparfa/unix/Util/valgrind-2.0.0/coregrind/valgrind.so:
> > undefined reference to `vgPlain_skin_interface_major_version'
> > collect2: ld returned 1 exit status
> >
> > I couldn't find the library where those symbols are defined.
>
> You don't need to do this. As long as your program is dynamically linked=
with libpthread.so (which should be the default), Valgrind's libpthread.so=
will automatically be used, and it all should work with just "valgrind myp=
rog".
>
> N
>
|
|
From: Jeremy F. <je...@go...> - 2004-03-23 07:06:31
|
Quoting Nicholas Nethercote <nj...@ca...>: > I don't think the problem is your fault. I tried your program under > Valgrind, and it worked for me (well; I had to add a pthread_join() > call > in main() after the pthread_create(), otherwise main() terminates > before > the created thread runs). > > So it's not a problem with your program; I think it's a problem with > Valgrind or gcc or libc or a combination. Unfortunately, I'm no expert > on > the segment-override stuff and can't help your further. I've cc'd the > valgrind-users list in case anyone else knows more. The clear problem here is that the client is still picking up /lib/i686/ libpthread-0.9.so for some reason. I wonder if the program is being linked with -Wl,-rpath,/lib or something. Or perhaps something is unsetting/resetting LD_LIBRARY_PATH. Or maybe the toolchain, for whatever reason, just ignores LD_LIBRARY_PATH. The output of gcc -v while linking would be interesting. J |