Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gcc 3.0 + SGI = crup

Status
Not open for further replies.

Lim

Programmer
Aug 15, 2000
192
US
I have been upgrading gcc 2.9 to 3.0 on SGI (2.9 has a conflict with GLU library) and I could not belive how many problems new version has created to me.
1) Looks like they have chage algorith of name mangling, so all previously C++ compiled libraries with gcc 2.9 had to be recompiled to be link with gcc 3.0 objects.
2) Precompiled gcc3.0 from freeware.sgi.com does not include SGI specific C inludes. I have copied it from 2.9 or some macros in va_arg was undefined;
3) Level O2 optimization doesn't work with such code:
int *pi = NULL;
void **ppv = (void**)π
*ppv=malloc(2*sizeof(int));
after that pi was still NULL, but O1 optimization works fine.

May be it will be usefull to somebody.
 
1) It is possible to change name mangling rules for C++
but I can't convince the essencial problem is it.
Anyway, if name mangling rules are changed, you need to
get the new library and compile for the new compiler.

2) Some macros in varargs.h is not guaranteed to be
compatible. You need to use stdarg.h to maintain
compatibility.

3) Basically, a program which doesn't have no problem
is not affected by the optimization options. And there
is doubtful code in your source.
void **ppv = (void**)¥ð
what is '¥ð' on the right side? Hee S. Chung
heesc@netian.com
 
Actually it is macros

#ifndef MY_MALLOC
#define MY_MALLOC(out_p,in_nItem,in_ItemType){void** ppv = (void**)&(out_p); *ppv = malloc ((size_t)(in_nItem)*sizeof(in_ItemType));if ( (out_p) == NULL ){ int iBytesRequested = (in_nItem) * sizeof(in_ItemType); MY_MESSAGE_ALLOC_FAILED(iBytesRequested); iExitStatus =MY_STATUS_OUT_OF_MEMORY; goto End;} }
#endif

I used it in C and to be able compile with C++ I had to add casting. Since I don't know the real type and C++ do not allowed to skip casting I had to use this double pointer to void. I could not use
out_p = (in_ItemType*) malloc(...);
This will not work with some type such as int (*paiA)[3];

And I am not agree that program that doesn't have problems does not affected by optimization. They are looking for pattern to optimize and you could run into problem with pretty leagal code but with some new pattern. MS C++ is a case, I had to turn off optimization for some very simple function.
 
1. You can use casting for int (*a)[3].
int (*p)[3] = ( int(*)[3] ) malloc( sizeof(int[3])*5 );
But it cannot be applied for your macro.
out_p = (in_ItemType*) malloc(...);

I think you already test the following simple program

#include <malloc.h>
#include <stdio.h>

int main()
{
int *pi = NULL;
void **ppv = (void**)&pi;
*ppv = (void*)malloc(2*sizeof(int));
printf( &quot;%p\n&quot;, pi );
return 0;
}

and you said pi is still NULL. And I cannot find
any problem in this code. But if it is affected
by the compiler option, we can guess it is compiler
problem.


2. Please show me some example codes which need to
turn off optimization options for MS C++.

I said my experiences to you. I've been suffered
so many times to solve problems in a program and
everytime I find the problem was originated from
my routines and it is rarely occurred the case
which is affected by compiler option. I think
sometimes the bug is detected a few months later
after leaving it for another day.

Evidently I know that there are compiler bugs and
it can generate potential problems in a program
but I think it is rare. Anyway it can be occurred
so I said 'Basically'. And if there are some
mistakes in my expressions, please understand me,
English is not my native language.

Hee S. Chung
heesc@netian.com
 
hmm...

I meant the following code.

#include <malloc.h>
#include <stdio.h>

int main()
{
int *pi = NULL;
void **ppv = (void**)& pi
*ppv = (void*)malloc(2*sizeof(int));
printf( &quot;%p\n&quot;, pi );
return 0;
}


& pi must have blank between & and pi for this
web site... otherwise we get the mathematical
symbol of pi :)
Hee S. Chung
heesc@netian.com
 
I am agree that in 99% it is programing bug, but compilers is the same program that you and me are writing only (I hope) much better tested. But no one can give you 100% proof of bug free, especially when you compiling a lot of difference libraries together.

From MSDN (optimization problem):
___________________________
Optimizing compilers can sometimes change your code to something you wouldn't expect. If you find that the application works when you build for release without optimizations, but not when you build for release with optimizations, this might be the case.

If you suspect that a particular portion of your code is not being optimized correctly and is causing problems in the compilation or running of your program, you can bracket the offending code with

#pragma optimize(&quot;&quot;, off)
and
#pragma optimize(&quot;&quot;, on)

Developers have also been able to trace the bad code being generated when optimizations are on by looking at the actual assembly code generated for a function.
_______________________________________
I have expirienced this twice.

 
I wanted some source codes which depend on compiler
options in MS C++ because I hoped to test it. If you
still have such examples and they are minimal to
cause that problem, please upload them.
- I want to test them.

Now I think the best way to solve your problem
is to visit GCC site and report your bugs.


And it will be very grateful if you send an
e-mail to me or reply to this article when you know
the reason why your problem was occurred.
Hee S. Chung
heesc@netian.com
 
Can you upload the assembly codes generated by your
GCC compiler for the source code I wrote above ?

For the following two cases :
gcc -S test.c
gcc -S -O2 test.c
Hee S. Chung
heesc@netian.com
 
Sorry,
It is working in clear example.
It was not working in my project. I couldn't repet it in simple case. May be because to many different libraries link together and they can interfere some how.
Same case was with MS C++, some line was not working in specific place. I could not reproduced it. It is not that some code structure it is more how they work together.
I am agree that here can be the potential bug in some other place, but it was working fine on 4 other different platforms.
In my project I have changed my macros to the same lines, but with clear cast and it start working. I think this optimizator has problem not with my code, but inside itself in the way how he handle the whole code.
Sorry, I feel that I am not very usefull for you, I just want to say that these things sometime happens and they are not releated to the error in code. But it is very rare (and I only had this twice for 3 years with MS C++ and now with gcc3.0 on SGI). And new version of gcc 3.0 is worse the previous one in optimization, 2.9 was working fine.





 
Maybe the simple program works fine.

I've also suffered from such mysterious problem. I think it is worth
while getting minimal codes to cause the problem. If I have such a
problem, I'll try to reduce some codes until the problem is not occurred.
And then, I'll add some code to confirm the problem is appeared
again. I'll do this operations repeatedly and I'll finally get minimal
codes to cause that problem.

I've also worked on the various platforms and compilers. And
many times I thought my problem is caused by compiler or
OS bug. But eventually I realized the problem was made by me.
So, I think you need to get the minimal code before concluding
that your problem is caused by a compiler bug. It's my opinion.
Hee S. Chung
heesc@netian.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top