Solved

Segmentation fault accessing local variables

Posted on 2013-05-17
7
474 Views
Last Modified: 2013-05-20
Hello There Experts,

I'm seeing a very strange problem with my multi-threaded C++ application. After calling a certain function (in main()) I can no longer access any local (stack) variables without getting a segmentation fault. Also, calling return() produces the same results. Moving the variables to the heap makes it run. The function called is not passed any of the local variables, but it does create several new threads. I'm suspecting stack corruption, so got the stack pointer using 'register int stackp asm("r1")' and printed out 50 nearest dwords with addresses higher than the stack pointer, but its the same. I set a local variable to a specific value and was able to see it in the print-out, so my method looks like its right.

I'm a C-guy so I'm not sure if I'm missing some C++ thing here or what's going on.

Any advice or help is appreciated,

Thanks

/SC

Btw, I'm using the following

ARCH: Microblaze
Linux 3.6.0
GCC 4.6.4
Binutils  2.22.90
egLibc 2.14.90
0
Comment
Question by:sctccomm
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39176409
Could you post the code?
0
 

Author Comment

by:sctccomm
ID: 39176436
I wish, its 5 megabytes of fairly complicated source code. I'll try to distill it down.

I did discover something new though. I'm no expert on this but looking at the assembly code it looks like r19 is used to point to the stack base. The problem is that this value's most significant byte is wiped out after calling that function I mentioned earlier.

R19 Before: 0xbf945db8
R19 After:   0x00945db8

The crash happens as soon as a "load word immediate" instruction is called with r19 as a pointer. Very strange..
0
 
LVL 86

Expert Comment

by:jkr
ID: 39176468
Maybe a snippet of that code?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:sctccomm
ID: 39176497
I'll start working on reducing it, but there is so much code it will probably take a couple of days.

Thanks !
0
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 39176547
>> I can no longer access any local (stack) variables without getting a segmentation fault
If you increased the size of an auto-array to exceed the stack size limit, you may experience the symptoms you described.
0
 

Author Closing Comment

by:sctccomm
ID: 39182141
Turns out here is a memcpy that is passed the wrong size parameter
0
 
LVL 32

Expert Comment

by:phoffric
ID: 39182365
nasty little bug.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question