Sdl program compiled with "-O2 -g0" takes ages to start

Hi there, I’m new to this list with a very strange question.

I’m developing an open source in car infotainment system using sdl 1.2, opengl. You may have a look at http://opencitt.org. Whenever I compile this optimized with CXXFLAGS="-O2 -g0" the program will take ages to start about up to 2 minutes of black screen on a core2duo before graphics shows up! Compiling debug code with “-g2 -O0” doesnt show that behaviour, program starts instantly. Same effect on all computers I tested on about 4 machines, all running different versions of debian. I’m not sure whether this issue is related to sdl but I never saw such a behaviour before. Even debugging didn’t give me a clue where the program hangs such a long time. Google neither.

Anyone of you ever saw such behaviour and could give me a hint.
Thanks in advance, Tobi–
GRATIS f?r alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

There is a very good chance no one will respond to your message.On Sun, Jun 28, 2009 at 9:28 AM, wrote:

blah blah blah infotainment blah blah blah


http://codebad.com/

You did. Another beautiful theory destroyed by an ugly fact :-)On Sunday 28 June 2009 08:24, Donny Viszneki wrote:

On Sun, Jun 28, 2009 at 9:28 AM, wrote:

blah blah blah infotainment blah blah blah

There is a very good chance no one will respond to your message.

You’re probably trying to debug this with a debugger? Problem is, this isn’t the sort of thing a debugger is good at solving. When an operation is taking too long, what you need is a profiler, which will monitor your program and see what routines it’s spending most of its time on. Try running your program through one and see if it helps clear things up any…

Hi there, I’m new to this list with a very strange question.

I’m developing an open source in car infotainment system using sdl 1.2, opengl. You may have a look at http://opencitt.org. Whenever I compile this optimized with CXXFLAGS="-O2 -g0" the program will take ages to start about up to 2 minutes of black screen on a core2duo before graphics shows up! Compiling debug code with “-g2 -O0” doesnt show that behaviour, program starts instantly. Same effect on all computers I tested on about 4 machines, all running different versions of debian. I’m not sure whether this issue is related to sdl but I never saw such a behaviour before. Even debugging didn’t give me a clue where the program hangs such a long time. Google neither.

Anyone of you ever saw such behaviour and could give me a hint.
Thanks in advance, TobiFrom: topro at gmx.de (Tobi)
Subject: [SDL] sdl program compiled with “-O2 -g0” takes ages to start

Hi there, I’m new to this list with a very strange question.

I’m developing an open source in car infotainment system using sdl 1.2, opengl. You may have a look at http://opencitt.org. Whenever I compile this optimized with CXXFLAGS="-O2 -g0" the program will take ages to start about up to 2 minutes of black screen on a core2duo before graphics shows up! Compiling debug code with “-g2 -O0” doesnt show that behaviour, program starts instantly. Same effect on all computers I tested on about 4 machines, all running different versions of debian. I’m not sure whether this issue is related to sdl but I never saw such a behaviour before. Even debugging didn’t give me a clue where the program hangs such a long time. Google neither.

Anyone of you ever saw such behaviour and could give me a hint.
Thanks in advance, Tobi

SInce it is CXXFLAGS I’m assuming you are using C++? Do you have any
global or static class variables? I ask because global class
initializers run before main() and if they require something that is
initialized from main() you can see long waits while things time out.

In the -O2 -g0 case you are potentially removing a lot of code that
would be left in your program in the -O0 -g2 case. Not to mention that
-g2 will add lots of tables and maybe even some inline code used to
make the debugger happier. If you have static or global initializers
that depend on code than -O2 removes, or on some side effect resulting
from -g2 you could see your initializers getting forced into waiting
for something to time out before main() gets to run. I’ve seen a
similar effect when their are threads involved. The code left if by
-g2 can result in serializations that lets programs run that will not
run properly when the code is removed.

Just a guess.

Bob PendletonOn Sun, Jun 28, 2009 at 8:28 AM, wrote:


GRATIS f?r alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

SInce it is CXXFLAGS I’m assuming you are using C++?
Yes I am, i.e. g++ version 4.3.3.

Do you have any
global or static class variables? I ask because global class
initializers run before main() and if they require something that is
initialized from main() you can see long waits while things time out.
Thats a good point, you gave me a new idea on how to track this down.

I’ve seen a
similar effect when their are threads involved. The code left if by
-g2 can result in serializations that lets programs run that will not
run properly when the code is removed.
Indeed there are threads involved…

Thanks so far,
Tobi–
GRATIS f?r alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

What? What are you claiming "times out?"On Sun, Jun 28, 2009 at 12:37 PM, Bob Pendleton wrote:

global class
initializers run before main() and if they require something that is
initialized from main() you can see long waits while things time out.


http://codebad.com/

global class
initializers run before main() and if they require something that is
initialized from main() you can see long waits while things time out.

What? What are you claiming “times out?”

I am not claiming that anything times out because I do not know if
there is anything that can time out.

OTOH, I once saw a situation where I singleton class was trying to
make an network connection and the networking code depended on
something that was initialized before main() but after the singleton.
The connection failed in an odd way that lead to the open waiting
until it timed out. That blocked the start up of the program until the
timeout completed.

Later, when the connection was needed the code noted that it was not
open and attempted to make the connection again. At that point the
network code was initialized so the connection worked and the program
worked correctly. The result was a very long wait while the program
waited for a connection attempt to time out followed by perfect
function…

Took me a while to figure that one out.

So, what I was saying is that if a global or static class tries to do
many different things it might result in a situation where a it has to
wait through a timeout.

Bob PendletonOn Sun, Jun 28, 2009 at 3:48 PM, Donny Viszneki<donny.viszneki at gmail.com> wrote:

On Sun, Jun 28, 2009 at 12:37 PM, Bob Pendleton<@Bob_Pendleton> wrote:


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

Bob Pendleton wrote:

OTOH, I once saw a situation where I singleton class was trying to
make an network connection and the networking code depended on
something that was initialized before main() but after the singleton.
The connection failed in an odd way that lead to the open waiting
until it timed out. That blocked the start up of the program until the
timeout completed.

Later, when the connection was needed the code noted that it was not
open and attempted to make the connection again. At that point the
network code was initialized so the connection worked and the program
worked correctly. The result was a very long wait while the program
waited for a connection attempt to time out followed by perfect
function…

Took me a while to figure that one out.

So, what I was saying is that if a global or static class tries to do
many different things it might result in a situation where a it has to
wait through a timeout.

Bob Pendleton

Looks like the infamous “static initialization order fiasco”

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

.bill

Bob Pendleton wrote:

OTOH, I once saw a situation where I singleton class was trying to
make an network connection and the networking code depended on
something that was initialized before main() but after the singleton.
The connection failed in an odd way that lead to the open waiting
until it timed out. That blocked the start up of the program until the
timeout completed.

Later, when the connection was needed the code noted that it was not
open and attempted to make the connection again. At that point the
network code was initialized so the connection worked and the program
worked correctly. The result was a very long wait while the program
waited for a connection attempt to time out followed by perfect
function…

Took me a while to figure that one out.

So, what I was saying is that if a global or static class tries to do
many different things it might result in a situation where a it has to
wait through a timeout.

Bob Pendleton

Looks like the infamous “static initialization order fiasco”

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

Exactly. Static initialization in C++ is a very powerful tool, rather
like a hand grenade. Used mindfully, by a trained practitioner, it is
an extremely effective way of solving problems. Used by an amateur it
gives you a dead amateur and maybe some dead and injured bystanders
too. May be not the best example I ever came up with… :slight_smile:

Bob PendletonOn Mon, Jun 29, 2009 at 12:07 AM, Vassilis Virvilis wrote:

? ? ? ?.bill


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

Looks like the infamous “static initialization order fiasco”

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

Exactly. Static initialization in C++ is a very powerful tool, rather
like a hand grenade. Used mindfully, by a trained practitioner, it is
an extremely effective way of solving problems. Used by an amateur it
gives you a dead amateur and maybe some dead and injured bystanders
too. May be not the best example I ever came up with… :slight_smile:

“Powerful” isn’t the word I’d use to describe a feature that leaves one of
its most important pieces of functionality undefined, and makes it all too
easy to write code that depends on this undefined functionality. I believe
"defective" would be a more accurate term.

http://yosefk.com/c++fqa/ctors.html#fqa-10.12>From: Bob Pendleton

Subject: Re: [SDL] sdl program compiled with “-O2 -g0” takes ages to start
On Mon, Jun 29, 2009 at 12:07 AM, Vassilis Virvilis wrote:

Looks like the infamous “static initialization order fiasco”

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

Exactly. Static initialization in C++ is a very powerful tool, rather
like a hand grenade. Used mindfully, by a trained practitioner, it is
an extremely effective way of solving problems. Used by an amateur it
gives you a dead amateur and maybe some dead and injured bystanders
too. ?May be not the best example I ever came up with… :slight_smile:

“Powerful” isn’t the word I’d use to describe a feature that leaves one of
its most important pieces of functionality undefined, and makes it all too
easy to write code that depends on this undefined functionality. ?I believe
"defective" would be a more accurate term.

I guess that puts you in the “hand grenade is an appropriate example camp”? ;-}

Bob PendletonOn Mon, Jun 29, 2009 at 1:13 PM, Mason Wheeler wrote:

From: Bob Pendleton <@Bob_Pendleton>
Subject: Re: [SDL] sdl program compiled with “-O2 -g0” takes ages to start
On Mon, Jun 29, 2009 at 12:07 AM, Vassilis Virvilis wrote:

http://yosefk.com/c++fqa/ctors.html#fqa-10.12


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

Looks like the infamous “static initialization order fiasco”

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

Exactly. Static initialization in C++ is a very powerful tool, rather
like a hand grenade. Used mindfully, by a trained practitioner, it is
an extremely effective way of solving problems. Used by an amateur it
gives you a dead amateur and maybe some dead and injured bystanders
too. May be not the best example I ever came up with… :slight_smile:

“Powerful” isn’t the word I’d use to describe a feature that leaves one of
its most important pieces of functionality undefined, and makes it all too
easy to write code that depends on this undefined functionality. I believe
"defective" would be a more accurate term.

I guess that puts you in the “hand grenade is an appropriate example camp”? ;-}

Bob Pendleton

grin I suppose. I have to wonder how something like that ended up in the
language in the first place. Is it just yet another strange side-effect of C++'s
C roots being grafted onto a completely inappropriate tree, or is this a
completely new feature that has no C analogue?

This is one of the places where I can’t even really say “and Delphi does it
better” even though it does, because it’s an apples-to-oranges comparison.
The way Delphi handles initialization to give a well-defined order of
execution probably wouldn’t work on a language that doesn’t compile in a
single pass.>----- Original Message ----

From: Bob Pendleton
Subject: Re: [SDL] sdl program compiled with “-O2 -g0” takes ages to start
On Mon, Jun 29, 2009 at 1:13 PM, Mason Wheeler<@Mason_Wheeler> wrote:

From: Bob Pendleton
Subject: Re: [SDL] sdl program compiled with “-O2 -g0” takes ages to start
On Mon, Jun 29, 2009 at 12:07 AM, Vassilis Virvilis wrote:

Looks like the infamous “static initialization order fiasco”

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

Exactly. Static initialization in C++ is a very powerful tool, rather
like a hand grenade. Used mindfully, by a trained practitioner, it is
an extremely effective way of solving problems. Used by an amateur it
gives you a dead amateur and maybe some dead and injured bystanders
too. ?May be not the best example I ever came up with… :slight_smile:

“Powerful” isn’t the word I’d use to describe a feature that leaves one of
its most important pieces of functionality undefined, and makes it all too
easy to write code that depends on this undefined functionality. ?I believe
"defective" would be a more accurate term.

I guess that puts you in the “hand grenade is an appropriate example camp”? ;-}

Bob Pendleton

grin I suppose. ?I have to wonder how something like that ended up in the
language in the first place. ?Is it just yet another strange side-effect of C++'s
C roots being grafted onto a completely inappropriate tree, or is this a
completely new feature that has no C analogue?

IMHO it is a result of following to closely to C. C has variables that
are static, dynamic (stack based) along with heap storage. From what I
have read Stroustrup decided that C++ should have the same classes of
storage for classes. Doing that added a lot of complications and, if I
say so myself, many unexpected consequences for the language. Once you
have static classes and you have constructors and destructors, you can
not avoid the problem of having constructors that run before main()
because static variables are initialized before main.

I am one of many people who read the original C++ paper in SIGPLAN and
said “oooh, this does not look like a good idea” only to have C++ show
up as a major language a few years later. At this point I am really
quite fond of it. I call it “the language I hate to love”. But,
seriously I only learned the language after I started teaching it. I
thought I knew it… of I wouldn’t have tried to teach it. But,
really until you have to face a class room full of totally bewildered
people while trying to explain multiple inheritance…

This is one of the places where I can’t even really say “and Delphi does it
better” even though it does, because it’s an apples-to-oranges comparison.
The way Delphi handles initialization to give a well-defined order of
execution probably wouldn’t work on a language that doesn’t compile in a
single pass.

I’m not sure that means what you think it means. C, and I do believe
C++ are quite capable of being compiled in a single pass. In fact, I
don’t think I ever used a multiple pass C compiler. The languages do
not have explicit “forward” declarations but they do allow you do
declare the signature of a thing before you declare the actual thing.
Otherwise you could not link separate compilation units together. Or,
are you counting optimization and linking as separate passes? Either
way, the number of passes have nothing to do with the order of
initialization.

Bob PendletonOn Mon, Jun 29, 2009 at 2:09 PM, Mason Wheeler wrote:

----- Original Message ----
From: Bob Pendleton <@Bob_Pendleton>
Subject: Re: [SDL] sdl program compiled with “-O2 -g0” takes ages to start
On Mon, Jun 29, 2009 at 1:13 PM, Mason Wheeler wrote:

From: Bob Pendleton <@Bob_Pendleton>
Subject: Re: [SDL] sdl program compiled with “-O2 -g0” takes ages to start
On Mon, Jun 29, 2009 at 12:07 AM, Vassilis Virvilis wrote:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

grin I suppose. ?I have to wonder how something like that ended up in the
language in the first place. ?Is it just yet another strange side-effect of C++'s
C roots being grafted onto a completely inappropriate tree, or is this a
completely new feature that has no C analogue?

There’s no C analogue to constructors, no. When you think you have
one, it’s really all compile-time constants.

This is one of the places where I can’t even really say “and Delphi does it
better” even though it does, because it’s an apples-to-oranges comparison.
The way Delphi handles initialization to give a well-defined order of
execution probably wouldn’t work on a language that doesn’t compile in a
single pass.

It’s not so much the single compilation pass as the linker model. In
Delphi, there’s a specific order of inclusion of “libraries” (units),
so it’s possible to define an order at all.

Although I suspect that if you throw DLLs into the mix, it might
become quite interesting (but I also suspect that it should be
consistent within a DLL and that you’d have to work quite hard to
create inter-DLL dependencies that would end up screwing things up,
but it might be possible)…

In C++, the way this is dealt with is generally by having few globals,
and also by using factory functions that keep a pointer to the global,
and enforces a model similar to Delphi’s (using something is what
creates it). Even then, destruction can be weird (supposing that you
used smart pointers to keep the global pointers used by the factories,
so that things would get cleaned up), because theoretically threads
can still be running after main() has returned (whee! true in C and
Delphi as well, I think)…On Mon, Jun 29, 2009 at 3:09 PM, Mason Wheeler wrote:


http://pphaneuf.livejournal.com/

grin I suppose. I have to wonder how something like that ended up in the
language in the first place. Is it just yet another strange side-effect of C++'s
C roots being grafted onto a completely inappropriate tree, or is this a
completely new feature that has no C analogue?

Incidentally, and in case you were curious, the C++ FAQ covers
solutions to these problems at:
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

Additionally, the Loki library (from Modern C++ Design) has a method
of controlling the order of destruction.
http://loki-lib.sourceforge.net/

Sorry, but I cannot recall at the moment why it is like this in the
C++ language. I think it had something to do with the various
platform loaders behaving quite differently from one another, but like
I said, I’m drawing a blank right now.

Hope this helps.

Regards,

Johnathan Gurley

I’m not sure that means what you think it means. C, and I do believe
C++ are quite capable of being compiled in a single pass.

I’m pretty sure C++ requires multiple passes (you can use methods
declared further down in a class, for example). C might be possible in
a single pass.On Mon, Jun 29, 2009 at 4:21 PM, Bob Pendleton wrote:


http://pphaneuf.livejournal.com/

This is one of the places where I can’t even really say “and Delphi does it
better” even though it does, because it’s an apples-to-oranges comparison.
The way Delphi handles initialization to give a well-defined order of
execution probably wouldn’t work on a language that doesn’t compile in a
single pass.

I’m not sure that means what you think it means. C, and I do believe
C++ are quite capable of being compiled in a single pass. In fact, I
don’t think I ever used a multiple pass C compiler. The languages do
not have explicit “forward” declarations but they do allow you do
declare the signature of a thing before you declare the actual thing.
Otherwise you could not link separate compilation units together. Or,
are you counting optimization and linking as separate passes? Either
way, the number of passes have nothing to do with the order of
initialization.

No, what I mean is the way C++'s include model (also inherited from
C) can require the compiler to go over the same file more than once
if it’s included from more than one file.

http://yosefk.com/c++fqa/defective.html#defect-3

In Delphi, the compiler doesn’t allow circular unit interface dependencies,
so it can guarantee that it will never touch the same line of code twice
during any given compile cycle. This isn’t as much of a restriction as it
might sound, since you’re allowed to declare more than one class in
the same unit, (unlike Java,) and you can have circular dependencies
inside the implementation section, which is just fine once the external
interface has already been built.>----- Original Message ----

From: Bob Pendleton
Subject: Re: [SDL] sdl program compiled with “-O2 -g0” takes ages to start

Made some more tests with interesting results…

The problem seems to not happen on machines with nvidia graphics card using proprietary nvidia drivers. It definitely happens with intel based graphics cards and xorg supplied driver. All running xorg 7.3/7.4.

Does this give anyone a clue? not to me. Meanwhile I’m quite sure its not sdl’s fault but maybe one of you has an idea.

Thanks a lot
Tobi–
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
f?r nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02

-------- Original-Nachricht --------> Datum: Mon, 29 Jun 2009 15:21:25 -0500

Von: Bob Pendleton
An: “A list for developers using the SDL library. (includes SDL-announce)”
Betreff: Re: [SDL] sdl program compiled with “-O2 -g0” takes ages to start

IMHO it is a result of following to closely to C. C has variables that
are static, dynamic (stack based) along with heap storage. From what I
have read Stroustrup decided that C++ should have the same classes of
storage for classes. Doing that added a lot of complications and, if I
say so myself, many unexpected consequences for the language. Once you
have static classes and you have constructors and destructors, you can
not avoid the problem of having constructors that run before main()
because static variables are initialized before main.

I am one of many people who read the original C++ paper in SIGPLAN and
said “oooh, this does not look like a good idea” only to have C++ show
up as a major language a few years later. At this point I am really
quite fond of it. I call it “the language I hate to love”. But,
seriously I only learned the language after I started teaching it. I
thought I knew it… of I wouldn’t have tried to teach it. But,
really until you have to face a class room full of totally bewildered
people while trying to explain multiple inheritance…

I double-checked my code as I knew there were global (static) class-instances, but most of them have an empty default constructor. So I am 100% sure that my code is not affected by the “static initialisation order fiasco”. Anyway I wasn’t aware of such a thing so thanks for letting me learn about that.

I have to keep testing, maybe use a profiler as suggested…

GRATIS f?r alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01