public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Segmentation fault after compilation with gcc-3.4 on 64-bit Linux
@ 2009-08-01 14:28 Alireza Haghdoost
  2009-08-01 14:53 ` John S. Fine
  2009-08-01 16:35 ` Andrew Haley
  0 siblings, 2 replies; 3+ messages in thread
From: Alireza Haghdoost @ 2009-08-01 14:28 UTC (permalink / raw)
  To: gcc-help

Dear All

I have a big ANSI-C application which should compile by gcc 3.4 or
earlier gcc versions, It works fine on any 32-bit Linux but when I
compile it on 64-bit one, application execution failed by Segmentation
fault error. I mean that gcc-3.4 on 64-bit machine compiles my
application well but when I try to run compiled application, it failed
by Segmentation Fault error.
I have tried several compilation Flags like -mtune=nocona and -m64 but
no one works for me and I still have Segmentation fault in the
execution of my application only on 64-bit Linux.
I will appreciate if some one here can help me.

---
Best regards,
Alireza Haghdoost

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Segmentation fault after compilation with gcc-3.4 on 64-bit Linux
  2009-08-01 14:28 Segmentation fault after compilation with gcc-3.4 on 64-bit Linux Alireza Haghdoost
@ 2009-08-01 14:53 ` John S. Fine
  2009-08-01 16:35 ` Andrew Haley
  1 sibling, 0 replies; 3+ messages in thread
From: John S. Fine @ 2009-08-01 14:53 UTC (permalink / raw)
  To: Alireza Haghdoost; +Cc: gcc-help

Forget compilation flags and don't ask about or blame gcc.  There are 
bugs in your C code and that makes it crash.

Many 32 bit applications are filled with questionable casts and other 
constructs that assume things such as ints being the same size as 
pointers, that are correct in 32 bit mode but not in 64 bit mode.

When you port a large application like that from 32 bit to 64 bit, you 
have to be prepared to find and fix those bugs.

I've also seen a number of examples of code that is just wrong, even in 
32 bit mode, but shows no symptoms until you build it in 64 bit mode.  
That includes things like using fields in a structure after freeing the 
memory containing that structure and things like testing uninitialized 
stack variables and behaving correctly only if they are non zero.  
Almost anything that changes the size or layout of your program or data 
might change those errors from symptom free to seg fault.  It just 
happened that a switch from 32 bit to 64 bit did it.

If you know how to use a debugger, you can look at the code, data and 
callback stack at the point of the seg fault and deduce what bug caused 
the seg fault.  If you're lucky, finding and fixing a few of those bugs 
will solve the whole problem.  But many questionable casts and other 
usages that only works in 32 bit mode produce wrong results rather than 
seg faults when run in 64 bit.  If you program has those bugs, you need 
a good understanding of the whole program, rather than just some 
competence with a debugger, in order to find and fix the bugs.

You should be asking yourself why you need this program to run in 64 bit 
mode and whether it is really worth the effort.  If I were doing it, I 
would certainly try to find the bugs (I don't like leaving such bugs in 
my code even if running in 64 bit mode isn't important now).  But I know 
how to do that.  If you had to ask what you asked in the quoted message, 
I assume you don't know how to find the bugs in your program.

Alireza Haghdoost wrote:
> I mean that gcc-3.4 on 64-bit machine compiles my
> application well but when I try to run compiled application, it failed
> by Segmentation Fault error.
> I have tried several compilation Flags


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Segmentation fault after compilation with gcc-3.4 on 64-bit Linux
  2009-08-01 14:28 Segmentation fault after compilation with gcc-3.4 on 64-bit Linux Alireza Haghdoost
  2009-08-01 14:53 ` John S. Fine
@ 2009-08-01 16:35 ` Andrew Haley
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Haley @ 2009-08-01 16:35 UTC (permalink / raw)
  To: Alireza Haghdoost; +Cc: gcc-help

Alireza Haghdoost wrote:
> Dear All
> 
> I have a big ANSI-C application which should compile by gcc 3.4 or
> earlier gcc versions, It works fine on any 32-bit Linux but when I
> compile it on 64-bit one, application execution failed by Segmentation
> fault error. I mean that gcc-3.4 on 64-bit machine compiles my
> application well but when I try to run compiled application, it failed
> by Segmentation Fault error.
> I have tried several compilation Flags like -mtune=nocona and -m64 but
> no one works for me and I still have Segmentation fault in the
> execution of my application only on 64-bit Linux.
> I will appreciate if some one here can help me.

Assuming you're on a supported platform, Valgrind memcheck is your friend.

http://valgrind.org/docs/manual/mc-manual.html

Andrew.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-01 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-01 14:28 Segmentation fault after compilation with gcc-3.4 on 64-bit Linux Alireza Haghdoost
2009-08-01 14:53 ` John S. Fine
2009-08-01 16:35 ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).