FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Help with C++ compile

   
Author Topic: Help with C++ compile
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
So I've got a program I'm trying to profile; the difficulty is, when I add '-pg' to my compile and link options, it crashes, somewhere in the static initialisation - before main. So, I stripped it down to the minimum that will still produce this crash, which is surprisingly small:

code:
#include <iostream>

class TestClass {
public:
TestClass ();

private:
double* testarray;
};


TestClass::TestClass () {
testarray = new double[40];
}

int main (int argc, char** argv) {
return 0;
}

Compile and link like so:

code:
g++  -Wall -fPIC  -O2 -g -pg  -c -o Test.o Test.cc
g++ -Wall -fPIC -O2 -g -pg -pthread Test.o -o blah

This program, which does absolutely nothing, manages to segviol; here's the gdb trace:

code:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1218574944 (LWP 27213)]
0x0076e2c7 in _int_free () from /lib/tls/libc.so.6
(gdb) bt
#0 0x0076e2c7 in _int_free () from /lib/tls/libc.so.6
#1 0x0076d278 in free () from /lib/tls/libc.so.6
#2 0x007dac28 in _mcleanup () from /lib/tls/libc.so.6
#3 0x007268f3 in exit () from /lib/tls/libc.so.6
#4 0x007117fc in __libc_start_main () from /lib/tls/libc.so.6
#5 0x0804853d in _start ()

Any of the following will fix the crash:

  • Do not include iostream.
  • Set the optimisation level to zero.
  • Compile without the profiling option.
  • Comment out the allocation of testarray.

Any suggestions for how I can debug this?

ETA: gcc 3.2.3, Linux24SL3.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Try putting it into the Microsoft Visual studios and see what happens.
IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
I've already tried it with a different compiler, which removes the crash. And anyway, I'd need to set up a whole dev environment on a Windows box, which seems like a lot of work for one dang profiling.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Alcon
Member
Member # 6645

 - posted      Profile for Alcon   Email Alcon         Edit/Delete Post 
What distro of linux, where does the libC6 come from - distro packaged version or custom compiled? What version of libC6 do you have?

Also, update both gcc and G++ 3.2.3 is a pretty old version. [Edit]Actually we're up to version 4.4.[/Edit]

And if there's an update for libC6 I'd just grab that as well.

Posts: 3295 | Registered: Jun 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
I have two main candidates: there was a bug in the profiler in that version of gcc, or there is a version mismatch somewhere between your compiler and your libraries -- which would, of course, be another bug, because if it runs at all with differently compiled libraries, it is supposed to work.

In either case, upgrading should almost certainly fix, but given what computers you're running on, might not be feasible.

My best suggestion for working it out would be to go to a gcc IRC channel and ask around. Even verifying that it is a bug would be valuable.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Upgrading my gcc version would be difficult; however, I switched to icpc, which was already installed, and that worked. (Even with the non-stripped version of the code.) Incidentally, it turns out you can reduce from 25 ms/cycle down to 19 just with -DNDEBUG; perhaps I went a bit overboard on the asserts.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
I'm guess you were using a lot of asserts or a library with lots of asserts?

And yeah, intel's compiler is pretty good (and I suspect the version installed is based on a more recent gcc version than the gcc installed). You should see some nice speedups over certain sorts of array math with the right compiler flags, too; the compiler can vectorize some things automatically.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Ah-hah! If you fix the bad design that leads to getting close to the equilibrium position and then bouncing up because it goes just below it and divides by a small number, not only do you remove the enormous swings, it speeds up by two orders of magnitude because it's not constantly running into the iteration limit.

So yeah, lots of asserts, but that's not the actual problem. [Big Grin]

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Lots of asserts is why DNDEBUG made it so much faster.

But yes, fixing the algorithm is generally where the most speed gains come from [Wink]

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
quote:
Lots of asserts is why DNDEBUG made it so much faster.
Yes, I did realise that, but it was a 20% improvement, not a two-orders-of-magnitude one.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2