Program crashes with optimization level O2


 
Thread Tools Search this Thread
Operating Systems HP-UX Program crashes with optimization level O2
# 1  
Old 08-13-2007
Program crashes with optimization level O2

I am experiencing a difficulty undersatnding why my program (C++, HP UNIX) crashes. It crashes only when I build it with -O (+O2) optimization switch (used in aCC compiler). It works ok with +O0 or +O1 optimization.

Also, I see that local variables are shown incorrecly when program is built with +O2 optimization switch. They show correcly with +O0 or +O1 optimization.

Could anyone advise me on the +O2 optimization? Why this could lead to the crash? Why the debugger fails to show correctly the local variables?

It is compiled with the following switches:
/opt/aCC/bin/aCC -AA -DHPUX -DBUILD_UNIX -DNO_MSG_BUILD -DNO_MAP_BUILD -DUNICODE -DPIC +Z +inst_auto -D_THREADSAFE -mt +W641 +W829 -g0 -O -I.. -I../.. -I../lib -I/usr/local/include/stl -I../pcmsrv32 -I../pcmlib -g0 -c

Below is the gdb output after the crash:

Program received signal SIGSEGV, Segmentation fault.
0x7f0cc484 in GetAddress (grid=0, link=0, rAddress=@0x0) at street.cpp:352
352 street.cpp: No such file or directory.
(gdb) backtrace
#0 0x7f0cc484 in GetAddress (grid=0, link=0, rAddress=@0x0) at street.cpp:352
#1 0x7f2409d8 in LRAddrOutput::AddressSearch (this=0x7f7f41e8, pInterp=0x0,
grid=13, oldNumMatches=2132813148, rLinkJuris=@0x7f7f41cc,
rPostalCodes=@0x7f7f41e8, rLinkInfo=@0x7f7f4178, rNameInfo=@0x7f7f4194,
exact=@0x7f7f4078) at geoaddrs.cpp:3845
#2 0x7f23e450 in LRAddrOutput::SearchForAddress (this=0x7f7f3fe0, gridID=0,
pInterp=0x401be934, exact=@0x7f129158) at geoaddrs.cpp:2887
#3 0x7f232b88 in LRAddrOutput::CalcMatches (this=0x0, pCB=0x0)
at geoaddrs.cpp:559
#4 0x7f244664 in LRAddr::Lookup (this=0x694, region=0x0,
state=0x3 <Error reading address 0x3: Invalid argument>, pCB=0x0)
at geoaddrs.cpp:4901
#5 0x7f24beb0 in CGeocoder::FindStreetMatchesW (this=0x4004cd7c,
addrW=0x4004cd38 "\177\026\357\b", cityW=0x401be3a4 "", stateW=0x0,
countyW=0x401be934 "", zipW=0x401be9b4 "", size=0 '\000', grid=7026188,
pCB=0x0, type=0, lLat=0, lLong=0) at geocoder.cpp:1044
#6 0x7f2a21d4 in Place_NumAddressMatches (geoID=2139042812,
inStr=0x7f7f33f0 "",
city=0xffffffff <Error reading address 0xffffffff: Bad address>,
state=0x0, county=0x401be934 "", zip=0x401be9b4 "", size=0 '\000',
grid=7026188, UpdateProgMeter=0) at placemgr.cpp:957
#7 0x7f30d5d4 in GeoCodeImpl::NodeForCityOrAddr (this=0x7f7f3300,
pGeoResults=0x7f2b8430, pszLookup=0x4000f608 "NA", bExactMatch=96,
bSPLC=false, bRdNameOnly=false) at geo_impl.cpp:542
---Type <return> to continue, or q <return> to quit---
#8 0x7f30df4c in GeoCodeImpl::Nodefor (this=0x401be370,
pszLookup=0x3 <Error reading address 0x3: Invalid argument>,
bExactMatch=-56, returnSPLC=96, pRtOptions=0x40009e78,
bTrySupressPicklist=false) at geo_impl.cpp:687
#9 0x7f336774 in RouteImpl::AddStop (this=0x401b7f58,
name=0x400c17ec "\177+g@t\nfin=CoPilot tiedostotiedot\nfre=Informations sur
le Fichier CoPilot\nger=CoPilot Dateiinformationen\ngre=\316\240\316\273\316\267
\317\201\316\277\317\206\316\277\317\201\316\257\316\265\317\202 \316\263\316\27
1\316\261 \317\204\316\277 \316\261\317\201\317\207\316\265\316\257\316\277 CoPi
lot\nita=Informazioni sui file di CoPilot"..., gc=0x7f7f31b0)
at route_impl.cpp:488
#10 0x7f39915c in PCMSAddStop (trip=333240,
stop=0x5159c "PCMSAddStop returned %d\n") at pcmsrvapp.cpp:1312
#11 0x266b8 in TestFuelOpt () at pcmstest.cpp:616
#12 0x25ae4 in main () at pcmstest.cpp:467
(gdb)

Any help is appreciated.
# 2  
Old 08-13-2007
Quote:
Originally Posted by Yuriy07
Also, I see that local variables are shown incorrecly when program is built with +O2 optimization switch. They show correcly with +O0 or +O1 optimization.
Often optimizations are incompatible with debuggers because optimizers will re-organize variables on the stack for efficiency, um, basically optimizing the thing.

Optimizers are more aggressive and less forgiving of dodgy code.

Also, if you are using C++ libraries, have these been built with the same optimizations?


Use maximum warning and errors during compilation, for HPUX compilers I use "-Aa -D_HPUX_SOURCE +e +We".

Try GCC and see if that exposes anything, again use "-Wall -Werror".
# 3  
Old 08-14-2007
Quote:
Originally Posted by porter
Often optimizations are incompatible with debuggers because optimizers will re-organize variables on the stack for efficiency, um, basically optimizing the thing.

Optimizers are more aggressive and less forgiving of dodgy code.

Also, if you are using C++ libraries, have these been built with the same optimizations?


Use maximum warning and errors during compilation, for HPUX compilers I use "-Aa -D_HPUX_SOURCE +e +We".

Try GCC and see if that exposes anything, again use "-Wall -Werror".
Thank you, porter!

I tried -Aa option. The code won't compile, it complains about the inline statements we have in our code. Apparently, there's a reason why the -AA flag is used. All libraries are built with the same options.

It's weird to see that -g option is not compatible with -O (a typical optimization option).

The aCC man page says that +O2 optimization option is the same as +O1 optimization plus global optimization. What the "global optimization" means in this case? Are there any specific things I have to check in my code for that cause the crash with +O2 option, but not +O1?


Thank you in advance.
# 4  
Old 08-17-2007
I found that the program does not crash even with +O2 optimization when I set the inline option to zero (using "+inline_level 0" or "+d"). I understand that inline functions sometimes improve the speed but still don't see why using them could lead to a crash if everything else is OK with the program.

I also understand why the program might be not crashing now. By disabling inlined calls, I moved some code around and the problem (if it exists) could be just hidden now. Any ideas, or information on inline function calls with aCC in HP UNIX? Anyone has experience when making function inline would lead to a crash or knows about problems aCC has with inline calls?

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Apcupsd crashes

I am trying to run apcupsd, but it will not retain contact the UPS root@meow:/home/ethan/UPS/gapcmon-0.8.9# /etc/init.d/apcupsd start Starting UPS power management: A copy of the daemon is still running. If you just stopped it, please wait about 5 seconds for it to shut down.... (0 Replies)
Discussion started by: Meow613
0 Replies

2. Red Hat

SSL certificate generation on OS level or application level

We have a RHEL 5.8 server at the production level and we have a Java application on this server. I know of the SSL certificate generation at the OS (RHEL) level but it is implemented on the Java application by our development team using the Java keytool. My doubt is that is the SSL generation can... (3 Replies)
Discussion started by: RHCE
3 Replies

3. Programming

C++ program crashes

Hi, Can anyone tell me why the below program is crashing? and where exactly it is crashing. What is the corrective measure to be taken to make it work fine? #include <iostream> #include <cstring> using namespace std; class CString { char* m_data; public: CString() :... (6 Replies)
Discussion started by: royalibrahim
6 Replies

4. Programming

Program crashes on calling __libc_msgrcv()

Hi, I am a newbie to linux programming. I have implemented msgqueue in C. msgrcv() call at the client end is as below: msgrcv( msgqid, msgptr, msgsize, msgtype, 0 ); My program works fine when msgrcv () from /lib/libc.so.6 is called. However it crashes when __libc_msgrcv() is called. ... (3 Replies)
Discussion started by: praasanna
3 Replies

5. Programming

C++ program crashes

Hi, Could anyone tell me the reason why the following program crashes? class A { int x; public: A() { cout << "from A()" << endl; } ~A() { cout << "from ~A()" << endl; } }; class B : public A { public: B() { cout << "from B()"... (2 Replies)
Discussion started by: royalibrahim
2 Replies

6. Solaris

Difference between run level & init level

what are the major Difference Between run level & init level (2 Replies)
Discussion started by: rajaramrnb
2 Replies

7. UNIX for Dummies Questions & Answers

Text book / online resource for learning to program at system/kernel level

Is there any book/resource that one can refer to, to be able to write programs at kernel/system level.. I'm looking for a programming book that could serve as a guide to write kernel codes / system level programming etc.. I have Tannenbaum's Design and Implementation. It addresses theoretical... (2 Replies)
Discussion started by: vishwamitra
2 Replies

8. UNIX for Advanced & Expert Users

Which Base Level Filesets needed by a specific program?

hello... thats a great forum btw :) my problem is that I need a list of the Base Level Filesets (BLF) which are needed by a specific program. Is there any command/tool which shows me that? during the installation I can choose "Preview only" so that I can see what BLF´s are missing etc but... (4 Replies)
Discussion started by: cypher82
4 Replies

9. Programming

AIX 5.3 64-bit program crashes with AIX 5.1

I have an AIX 64-bit program which uses following from AIX5.3 /usr/lib/libc.a(shr_64.o) /usr/lib/libpthread.a(shr_xpg5_64.o) /home/jeet_xp/export/power/usr/lib/libsarpc.a(shr.o) /unix /usr/lib/libcrypt.a(shr_64.o) /usr/lib/libc_r.a(shr_64.o) ... (3 Replies)
Discussion started by: jeet_xp
3 Replies
Login or Register to Ask a Question