|
From: Jan K. <jan...@gm...> - 2015-11-13 18:54:52
|
Hi :),
I have a prog. with pthread semaphores. Everything works fine, but i
have a small problem with valgring.
If I commpile my program with
gcc -gdwarf-2 -O0 -static main.c -lpthread
and run as
valgrind --tool=helgrind --read-var-info=yes ./a.out
I get
==15757== Process terminating with default action of signal 11 (SIGSEGV)
==15757== Access not within mapped region at address 0xFFFFFFFFFFFFFFF8
==15757== at 0x4010B8: main (main.c:39)
==15757== If you believe this happened as a result of a stack
==15757== overflow in your program's main thread (unlikely but
==15757== possible), you can try to increase the size of the
==15757== main thread stack using the --main-stacksize= flag.
==15757== The main thread stack size used in this run was 8388608.
(on line 39 there is sem_post(sem), where sem is valid pointer on the
semaphore which is created by sem_open("test", O_CREAT, S_IRWXU, 1))
Is this normal? I am really confused...
Thanks,
John
(and sorry fo my english :D)
|
|
From: David C. <dcc...@ac...> - 2015-11-13 20:39:20
|
On 11/13/2015 10:54 AM, Jan Kubalek wrote:
> Hi :),
>
> I have a prog. with pthread semaphores. Everything works fine, but i
> have a small problem with valgring.
>
> If I commpile my program with
> gcc -gdwarf-2 -O0 -static main.c -lpthread
> and run as
> valgrind --tool=helgrind --read-var-info=yes ./a.out
> I get
> ==15757== Process terminating with default action of signal 11 (SIGSEGV)
> ==15757== Access not within mapped region at address 0xFFFFFFFFFFFFFFF8
> ==15757== at 0x4010B8: main (main.c:39)
> ==15757== If you believe this happened as a result of a stack
> ==15757== overflow in your program's main thread (unlikely but
> ==15757== possible), you can try to increase the size of the
> ==15757== main thread stack using the --main-stacksize= flag.
> ==15757== The main thread stack size used in this run was 8388608.
>
> (on line 39 there is sem_post(sem), where sem is valid pointer on the
> semaphore which is created by sem_open("test", O_CREAT, S_IRWXU, 1))
>
> Is this normal? I am really confused...
>
>
> Thanks,
> John
> (and sorry fo my english :D)
>
>
What happens if you compile without "-static"? Valgrind wants to
replace system libraries with its own versions so that it can trace
memory allocation and release. It does so at runtime, so static linking
is not good for it.
--
David Chapman dcc...@ac...
Chapman Consulting -- San Jose, CA
Software Development Done Right.
www.chapman-consulting-sj.com
|
|
From: Jan K. <jan...@gm...> - 2015-11-16 16:06:20
|
Hello,
> What happens if you compile without "-static"? Valgrind wants to replace
> system libraries with its own versions so that it can trace memory
> allocation and release. It does so at runtime, so static linking is not
> good for it.
If I compile program without "-static"
gcc -gdwarf-2 -O0 main.c -lpthread &&
valgrind --tool=helgrind --read-var-info=yes ./a.out
I get the same error :(.
(I have valgrind 3.1.0)
Thanks,
John
(i forgot send copy to the mailing list)
|
|
From: David C. <dcc...@ac...> - 2015-11-16 16:21:19
|
On 11/16/2015 8:06 AM, Jan Kubalek wrote:
> Hello,
>> What happens if you compile without "-static"? Valgrind wants to replace
>> system libraries with its own versions so that it can trace memory
>> allocation and release. It does so at runtime, so static linking is not
>> good for it.
> If I compile program without "-static"
> gcc -gdwarf-2 -O0 main.c -lpthread &&
> valgrind --tool=helgrind --read-var-info=yes ./a.out
> I get the same error :(.
>
> (I have valgrind 3.1.0)
>
> Thanks,
> John
> (i forgot send copy to the mailing list)
There are two possibilities:
There may be a bug in valgrind 3.1.0 which has been fixed; the current
release is 3.11.0. Can you compile or download binaries for version 3.11.0?
If it still fails (or if you can't use a copy of 3.11.0), the next step
is to try to reduce the problem to a program small enough to post to the
list. Since no one else has (to my limited knowledge) reported a
similar problem, there may be something unique about your code.
Hopefully someone on the list would spot it.
--
David Chapman dcc...@ac...
Chapman Consulting -- San Jose, CA
Software Development Done Right.
www.chapman-consulting-sj.com
|
|
From: Jan K. <jan...@gm...> - 2015-11-18 22:38:36
|
Hi,
> There may be a bug in valgrind 3.1.0 which has been fixed; the current
> release is 3.11.0. Can you compile or download binaries for version 3.11.0?
I tried Valgrind 3.10.0 and get the same error as with 3.1.0
> If it still fails (or if you can't use a copy of 3.11.0), the next step is
> to try to reduce the problem to a program small enough to post to the list.
[...]
Ok. This is short version of my program.
> #define _GNU_SOURCE
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <semaphore.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sched.h>
>
> #define STACK_SIZE 8*1024*1024
>
>
> int at_wait(void* a) {
> sem_t* _sem = sem_open("test", O_CREAT, S_IRWXU, 1);
>
> printf("2 - waiting\n");
> fflush(stdout);
> sem_wait(_sem);
> printf("2 - i am free. Tralalaaa\n");
> fflush(stdout);
>
> sem_close(_sem);
> return 0;
> }
>
>
> int main() {
> sem_t* sem = sem_open("test", O_CREAT, S_IRWXU, 1);
> void* stack = malloc(STACK_SIZE);
>
> sem_wait(sem);
> if(-1 == clone(at_wait, stack + STACK_SIZE, 0, NULL)) {
> fputs("Cannot clone program :(\n", stderr);
> exit(EXIT_FAILURE);
> }
>
> sleep(2);
> sem_post(sem);
> printf("1 - OK\n");
>
> int status;
> int _pid = waitpid(-1, &status, __WCLONE);
> if(_pid == -1) {
> fputs("waitpid error\n", stderr);
> exit(EXIT_FAILURE);
> }
> if(_pid > 0) {
> if(WIFEXITED(status)) {
> printf("child exited - %i\n", _pid);
> }
> }
>
> sem_close(sem);
> sem_unlink("test");
> free(stack);
> printf("program end\n");
>
> return 0;
> }
If i compile this with
gcc -gdwarf-2 main.c -lpthread
or
gcc main.c -lpthread
and run
valgrind --tool=helgrind ./a.out
I get the error
--- dump start ---
==7032== Helgrind, a thread error detector
==7032== Copyright (C) 2007-2013, and GNU GPL'd, by OpenWorks LLP et al.
==7032== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==7032== Command: ./a.out
==7032==
==7033==
==7033== Process terminating with default action of signal 11 (SIGSEGV)
==7033== Access not within mapped region at address 0xFFFFFFFFFFFFFFF8
==7033== at 0x400B6B: main (main.c:39)
==7033== If you believe this happened as a result of a stack
==7033== overflow in your program's main thread (unlikely but
==7033== possible), you can try to increase the size of the
==7033== main thread stack using the --main-stacksize= flag.
==7033== The main thread stack size used in this run was 8388608.
==7033==
==7033== For counts of detected and suppressed errors, rerun with: -v
==7033== Use --history-level=approx or =none to gain increased speed, at
==7033== the cost of reduced accuracy of conflicting-access information
==7033== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
1 - OK
program end
==7032==
==7032== For counts of detected and suppressed errors, rerun with: -v
==7032== Use --history-level=approx or =none to gain increased speed, at
==7032== the cost of reduced accuracy of conflicting-access information
==7032== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
--- dump end ---
What's wrong? Some bug in my program (which i do not see) or problem
with valgrind?
Thanks for any help :),
John
|