[gccsdk] GCC 4.1.2 Release 1 Native Compilation Segmentation Fault

pdmiller at pdmiller1.plus.com pdmiller at pdmiller1.plus.com
Sun Apr 29 09:20:07 PDT 2012

On 25/04/12 19:20,Lee Noar <leenoar at sky.com>  wrote:
> On 25/04/12 17:17, pdmiller at pdmiller1.plus.com wrote:
>> I've just installed GCC 4.1.2 release 1 onto my VRPC AdjustSA RO 6.20
>> system, including SharedUnixlib 1.12, and the latest !SharedLibs. I get a
>> segmentation fault when compiling certain c files. It looks like they are
>> greater than a certain size in some way. They compile ok with the previous
>> GCC release. I don't remember getting this error with the previous
>> release,
>> or having to do anything to increase a slot size, etc. My next slot is set
>> to 10240k. Have I missed or forgotten to do something, or is it a real
>> bug.
> Could you please post one of the offending files that will demonstrate
> the problem.
> Thanks,
> Lee.

Hmm, not the answer I was hoping for. I've now had some time to
investigate further and have discovered two things.

1. If I remove the -O2 compiler switch the code compiles successfully.

2. The code at the line GCC 4.12 reports when the failure occcurs is

if (!(s = (char *) mydesk_alloc_from_mwsdda(md,
                               (int) strlen(pwd->stdwkbuffer) + 1)))
  numwindows = i;

If I reorganise the code as

ilen = strlen(pwd->stdwkbuffer);

s = (char *) mydesk_alloc_from_mwsdda(md,
                                      (int) ilen);

if (!s)
  numwindows = i;

where ilen is a size_t defined at the beginning of the function,

then the code compiles successfully - with the -O2 switch in the compiler
flags passed to GCC.

However, if I combine the length calculation to

ilen = strlen(pwd->stdwkbuffer) + 1;

the segmentation fault occurs, with GCC reporting the line above as the
point where the failure occurs.

I have some other calculations like this in my code and all are now
triggering the segmentation fault when I yse GCC 4.1.2 to compile it.

I have changed them all with a similar reorganisation of the code as here
and they all now compile ok with GCC 4.1.2, and using the -O2 switch.

For info: pwd is an external pointer to a structure allocated using
malloc, pwd->stdwkbuffer is a char * also allocated using malloc.

I have some other pieces of my program have code with similar calculatons
but don't trigger the segmentaton fault, e.g.

if ((tbuff = drw_alloc_tbuff(
                 (strlen(pwd->stdwkbuffer) + 1) * 2,

strcpy((drwimpc->incliblistfilename +
        strlen(drwimpc->incliblistfilename) + 1),

If you still need it I can send a zip file of a peprocessed C file
containing the problem code I described at the start of this email,
unfortunately unpreprocessed its 15000 lines long, preprocessed and zipped
its 115KB. If so, would you prefer it sent to your email address you used
to reply to this message. Please let me know.

Hope this helps.


Pete Miller.
pdmiller at pdmiller1.plus.com

More information about the gcc mailing list