Segmentation fault after compilation with gcc-3.4 on 64-bit Linux

John S. Fine johnsfine@verizon.net
Sat Aug 1 14:53:00 GMT 2009


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




More information about the Gcc-help mailing list