I have the problem that a C++ program running under linux, compiled with g++ raises after some time a illegal instruction exception and I get a core dump. When I do a backtrace using gdb I get
(gdb) bt
#0 0x005e18cf in ATL_dpotrfL () from /usr/lib/liblapack.so.3gf开发者_运维技巧
#1 0x00000001 in ?? ()
#2 0xb786f2e8 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
I do not know why there is no main in the backtrace. The ?? seems to be part of my linux libraries which have no debugging symbols in.
My question is now: What is the problem with the program? Is the library lapack falsely compiled (I copiled it some days ago)? Or is there any other error?
I did definitfly no assembler or similar things. Only C++.
Thanks Christian
That usually means smashed stack. Especially the value of 0x00000001, which is pretty damn unlikely to be a valid stack address, so I'd say you overflowed a stack-allocated buffer and overwrote the return address.
What DeadMG said, plus:
Illegal instructions are usually the results of binaries that are compiled to use CPU instructions not available on the running machine. This can happen for example if you compile like
g++ -msse4 ...
and then run the thing on an Intel Atom CPU, which does not support the SSE4 instruction set. The crash does not necessarily happen, e.g. it is unlikely that
int main () {}
while cause SSE4 instructions be generated. Same of course for unprobable codepaths, which may cause no crash now, but in the future.
To find the stack smashing code, you might consider a LINT like cppcheck or similar, Valgrind, good old printf/cout debugging in a divide and conquer manner, or using a checked STL implementation.
as the other have said, you probably have screwed your stack.
The most common causes are :
- writing on a bad pointer (already deleted)
- writing outside of pointed space
- declaring huge local data on the stack
The magic way to find the cause is :
valgrind your_program [args]
(just add "valgrind" in front of the command you usually launch. Install valgrind if not already here, must have a packet for it on your distro since it is a widely used tool.)
Then valgrind will inspect your program while it run (slowing it a bit) and report you immediatly as soon as a write happen where it should not (for example, on the stack)
精彩评论