Hi,
I am using sun's CC (c++ compiler) to compile the follow code:
#define __REENTRANT
#include <stdio.h>
#include <pthread.h>
void *one(void *dummy);
void two(void);
void output(void);
int main (int argc, char **argv)
{
pthread_t tid;
pthread_create( &tid, NULL, one, NULL );
pthread_join(tid,NULL);
}
void *one(void *dummy)
{
output();
two();
return NULL;
}
void two(void)
{
output();
}
void output(void)
{
//char string[16468]; //This one purify likes
//char string[16469]={0}; //This and greater makes purify spit
BSW's
char string[16469]; //This and greater makes purify spit a
IPW/R's
string[0]='\0';
}
This is purify's output:
IPW: Invalid pointer write
This is occurring while in thread 7:
void output() [testmain3.o]
void two() [testmain3.o]
void*one(void*) [testmain3.o]
_thread_start [libthread.so.1]
Writing 1 byte to 0x7e5fbbef on the stack of thread 7.
Address 0x7e5fbbef is 16473 bytes below frame pointer in
function void output().
Thread Summary : 7 threads in existence
Thread 0 [main thread]
Stack Limit : (0xff3f0000 0xffbf0000), size = 0x800000
Thread 1
Stack Limit : (0x7ef10000 0x7f010000), size = 0x100000
Stack Use : (0x7f00fa30 0x7f00fd54), size = 0x324
Thread 2
Stack Limit : (0x7e652000 0x7e656000), size = 0x4000
Stack Use : (0x7e655978 0x7e655d54), size = 0x3dc
Thread 3
Stack Limit : (0x7f902b64 0x7f91e3f8), size = 0x1b894
Stack Use : (0x7f9076d0 0x7f9078f4), size = 0x224
Thread 4
Stack Limit : (0x7ee0e000 0x7ef0e000), size = 0x100000
Stack Use : (0x7ef0db30 0x7ef0dd54), size = 0x224
Thread 6
Stack Limit : (0x7e612000 0x7e616000), size = 0x4000
Stack Use : (0x7e615b28 0x7e615d54), size = 0x22c
Thread 8
Stack Limit : (0x7e632000 0x7e634000), size = 0x2000
Stack Use : (0x7e633b28 0x7e633d54), size = 0x22c
This is with CC. With gcc or g++ it does not have this problem. cc has
the problem too but with a larger number in the array.
Is it the compiler/linker bug or it purify making things up?
If it is the compiler I assume I am screwing up memory badly.
Matt
|
|
0
|
|
|
|
Reply
|
matt13 (5)
|
2/6/2004 12:32:57 PM |
|
On 6 Feb 2004 04:32:57 -0800
matt@holly.com.au (Matthew) wrote:
> Hi,
>
> I am using sun's CC (c++ compiler) to compile the follow code:
>
> #define __REENTRANT
> #include <stdio.h>
> #include <pthread.h>
>
> void *one(void *dummy);
>
> void two(void);
> void output(void);
>
> int main (int argc, char **argv)
> {
> pthread_t tid;
> pthread_create( &tid, NULL, one, NULL );
> pthread_join(tid,NULL);
> }
>
> void *one(void *dummy)
> {
> output();
> two();
> return NULL;
> }
>
> void two(void)
> {
> output();
> }
>
> void output(void)
> {
> //char string[16468]; //This one purify likes
> //char string[16469]={0}; //This and greater makes purify spit
> BSW's
> char string[16469]; //This and greater makes purify spit a
> IPW/R's
> string[0]='\0';
> }
>
> This is purify's output:
>
> IPW: Invalid pointer write
> This is occurring while in thread 7:
> void output() [testmain3.o]
> void two() [testmain3.o]
> void*one(void*) [testmain3.o]
> _thread_start [libthread.so.1]
> Writing 1 byte to 0x7e5fbbef on the stack of thread 7.
> Address 0x7e5fbbef is 16473 bytes below frame pointer in
> function void output().
>
> Thread Summary : 7 threads in existence
> Thread 0 [main thread]
> Stack Limit : (0xff3f0000 0xffbf0000), size = 0x800000
> Thread 1
> Stack Limit : (0x7ef10000 0x7f010000), size = 0x100000
> Stack Use : (0x7f00fa30 0x7f00fd54), size = 0x324
> Thread 2
> Stack Limit : (0x7e652000 0x7e656000), size = 0x4000
> Stack Use : (0x7e655978 0x7e655d54), size = 0x3dc
> Thread 3
> Stack Limit : (0x7f902b64 0x7f91e3f8), size = 0x1b894
> Stack Use : (0x7f9076d0 0x7f9078f4), size = 0x224
> Thread 4
> Stack Limit : (0x7ee0e000 0x7ef0e000), size = 0x100000
> Stack Use : (0x7ef0db30 0x7ef0dd54), size = 0x224
> Thread 6
> Stack Limit : (0x7e612000 0x7e616000), size = 0x4000
> Stack Use : (0x7e615b28 0x7e615d54), size = 0x22c
> Thread 8
> Stack Limit : (0x7e632000 0x7e634000), size = 0x2000
> Stack Use : (0x7e633b28 0x7e633d54), size = 0x22c
>
> This is with CC. With gcc or g++ it does not have this problem. cc has
> the problem too but with a larger number in the array.
>
> Is it the compiler/linker bug or it purify making things up?
>
> If it is the compiler I assume I am screwing up memory badly.
I think Purify might be correct. (Note that I was on the team that
ported Purify to Tru64 Unix). I'm not sure why Purify is saying thread
7, then printing the stats for 0 through 8, but you are exceeding the
stack size on several threads.
Also, the stack allocation scheme for threads differs depending on the
compiler in use, which is why you get different results with CC and cc.
--
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
|
|
0
|
|
|
|
Reply
|
Jerry
|
2/8/2004 2:28:17 PM
|
|
On 6 Feb 2004 04:32:57 -0800
matt@holly.com.au (Matthew) wrote:
> Hi,
>
> I am using sun's CC (c++ compiler) to compile the follow code:
>
> #define __REENTRANT
> #include <stdio.h>
> #include <pthread.h>
>
> void *one(void *dummy);
>
> void two(void);
> void output(void);
>
> int main (int argc, char **argv)
> {
> pthread_t tid;
> pthread_create( &tid, NULL, one, NULL );
> pthread_join(tid,NULL);
> }
>
> void *one(void *dummy)
> {
> output();
> two();
> return NULL;
> }
>
> void two(void)
> {
> output();
> }
>
> void output(void)
> {
> //char string[16468]; //This one purify likes
> //char string[16469]={0}; //This and greater makes purify spit
> BSW's
> char string[16469]; //This and greater makes purify spit a
> IPW/R's
> string[0]='\0';
> }
>
> This is purify's output:
>
> IPW: Invalid pointer write
> This is occurring while in thread 7:
> void output() [testmain3.o]
> void two() [testmain3.o]
> void*one(void*) [testmain3.o]
> _thread_start [libthread.so.1]
> Writing 1 byte to 0x7e5fbbef on the stack of thread 7.
> Address 0x7e5fbbef is 16473 bytes below frame pointer in
> function void output().
>
> Thread Summary : 7 threads in existence
> Thread 0 [main thread]
> Stack Limit : (0xff3f0000 0xffbf0000), size = 0x800000
> Thread 1
> Stack Limit : (0x7ef10000 0x7f010000), size = 0x100000
> Stack Use : (0x7f00fa30 0x7f00fd54), size = 0x324
> Thread 2
> Stack Limit : (0x7e652000 0x7e656000), size = 0x4000
> Stack Use : (0x7e655978 0x7e655d54), size = 0x3dc
> Thread 3
> Stack Limit : (0x7f902b64 0x7f91e3f8), size = 0x1b894
> Stack Use : (0x7f9076d0 0x7f9078f4), size = 0x224
> Thread 4
> Stack Limit : (0x7ee0e000 0x7ef0e000), size = 0x100000
> Stack Use : (0x7ef0db30 0x7ef0dd54), size = 0x224
> Thread 6
> Stack Limit : (0x7e612000 0x7e616000), size = 0x4000
> Stack Use : (0x7e615b28 0x7e615d54), size = 0x22c
> Thread 8
> Stack Limit : (0x7e632000 0x7e634000), size = 0x2000
> Stack Use : (0x7e633b28 0x7e633d54), size = 0x22c
>
> This is with CC. With gcc or g++ it does not have this problem. cc has
> the problem too but with a larger number in the array.
>
> Is it the compiler/linker bug or it purify making things up?
>
> If it is the compiler I assume I am screwing up memory badly.
I thought I posted an answer for this.
The issue here is that your string is too large for the thread's stack,
and Purify is throwing the proper thing. Each compiler lays out its
threads differently.
One possible solution is to use an attribute, (eg.
pthread_attr_setstacksize) to set the stacksize. Also, I question your
use of the #define __REENTRANT, but I don't know Sun's use of that.
Normally, that flag is for the building of the reentrant libc.so.
I assume that Sun's compiler may also place some per-thread data
adjacent to the visible stack, but that is just an assumption.
--
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
|
|
0
|
|
|
|
Reply
|
Jerry
|
2/16/2004 1:57:59 PM
|
|
|
2 Replies
380 Views
(page loaded in 0.068 seconds)
|