Linux compilation and assert

When I compile an amalgamated version of the latest (GIT) juce version in Linux Ubuntu, if in the Makefile I use the -O2 or -O3 flags it crashes.

But if I use the -Os flag (as in the Juce original Makefile) it works.
What is the “inner” reason for that?

Also: has anyone tried to build a Linux Juce Release version with these options:

#define JUCE_64BIT_ATOMICS_UNAVAILABLE 1 //having some linking problems
#define JUCE_FORCE_DEBUG 1
#define JUCE_LOG_ASSERTIONS 1

All the assersions of :

AtomicTester <float>::testFloat(); 

(called by SimpleUnitTests::runBasicTests) fail for me.
Do I need yo worry?

Thanks

PS I’m so picky because I’m actually testing the library. Sorry for that!

Can you post platform-specific stuff in the appropriate forum, please!

I’m afraid my psychic powers are not strong enough to tell you what’s wrong when all you say is “it crashes”… Do you mean the compiler or the program? If the program, then where does it crash??

[quote]All the assersions of :

AtomicTester ::testFloat();

(called by SimpleUnitTests::runBasicTests) fail for me.
Do I need yo worry?[/quote]

Yes, definitely! If your compiler hasn’t even got 32-bit atomic ops, then it’ll break a lot of code. Are you running an ancient version of gcc or something?

It crashes in the program (not during compilation).
And strangely it crashes inside

 [1] initialiseJuce_GUI
 [2] LookAndFell:setDefaultLookAndFeel(0)
 [3] defaultLF=new LookAndFeel()
 [4] ...somewhere inside the LookAndFeel() contructor...

soory I cannot be more specific but I’m in Release mode (in Debug all is working perfectly).

About the AtomicTester ::testFloat(). I see there are several tests:

  AtomicTester<int>::testInteger()
  AtomicTester<unsigned int>::testInteger();
  ...      
  AtomicTester<int*>::testInteger();
  AtomicTested<float>::testFloat();

but only the last one fails.
My gcc --version is 4.2.4 (Ubuntu 4.2.4-1ubuntu4).

Must be some kind of compiler flag that you’ve set… Where did your makefile come from?

My Linux Ubuntu configuration is the following:

Ubuntu 8.04 (hardy)
GNOME 2.22.3 (Ubuntu 2008-07-09)
Kernel 2.6.24-28-generic (#1 SMP Wed Aug 25 15:25:41 UTC 2010)
GCC version 4.2.4 (i486-linux-gnu)

///////////////////////////////////////////////////////////////////////////////////////////////////
PROBLEM 1. Linux Runtime crash in CONFIG=Release with -O2
///////////////////////////////////////////////////////////////////////////////////////////////////

I
(1) downloaded the latest GIT version
(2) modified the “extras/example projects/Build/Linux/Makefile”:

#CFLAGS += $(CPPFLAGS) $(TARGET_ARCH) -Os
CFLAGS += $(CPPFLAGS) $(TARGET_ARCH) -O2

(3) run Hello world

> cd "extras/example projects/Build/Linux"
> make CONFIG=Release
    ......
    > build/HelloWorld

I get at runtime an “Aborted” message (NOTE: If I use -Os it runs without errors):

build/HelloWorld
*** glibc detected *** build/HelloWorld: double free or corruption (fasttop): 0x083d5598 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb71c1b25]
/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb71c5590]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb738cb11]
/usr/lib/libstdc++.so.6(_ZdaPv+0x1d)[0xb738cb6d]
build/HelloWorld[0x80ac0e8]
build/HelloWorld[0x82241ad]
build/HelloWorld[0x82481d6]
build/HelloWorld[0x819dc3b]
build/HelloWorld[0x81ad8aa]
build/HelloWorld[0x80974b0]
build/HelloWorld[0x80fa15d]
build/HelloWorld[0x80fa29f]
build/HelloWorld(ftell+0x140)[0x804f26c]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb716c450]
build/HelloWorld(ftell+0x35)[0x804f161]
======= Memory map: ========
08048000-082cb000 r-xp 00000000 08:11 2066117 /home/scorzell/Desktop/juce/extras/example projects/Builds/Linux/build/HelloWorld
082cb000-083c8000 rw-p 00282000 08:11 2066117 /home/scorzell/Desktop/juce/extras/example projects/Builds/Linux/build/HelloWorld
083c8000-083ec000 rw-p 083c8000 00:00 0 [heap]
b6400000-b6421000 rw-p b6400000 00:00 0
b6421000-b6500000 —p b6421000 00:00 0
b658e000-b65f4000 rw-p b658e000 00:00 0
b65f4000-b65f8000 r-xp 00000000 08:11 17723 /usr/lib/libXdmcp.so.6.0.0
b65f8000-b65f9000 rw-p 00003000 08:11 17723 /usr/lib/libXdmcp.so.6.0.0
b65f9000-b65fb000 r-xp 00000000 08:11 17712 /usr/lib/libXau.so.6.0.0
b65fb000-b65fc000 rw-p 00001000 08:11 17712 /usr/lib/libXau.so.6.0.0
b65fc000-b65fd000 rw-p b65fc000 00:00 0
b65fd000-b65fe000 r-xp 00000000 08:11 18694 /usr/lib/libnvidia-tls.so.169.12
b65fe000-b65ff000 rw-p 00000000 08:11 18694 /usr/lib/libnvidia-tls.so.169.12
b65ff000-b70d3000 r-xp 00000000 08:11 18690 /usr/lib/libGLcore.so.169.12
b70d3000-b710f000 rwxp 00ad3000 08:11 18690 /usr/lib/libGLcore.so.169.12
b710f000-b7114000 rwxp b710f000 00:00 0
b7114000-b712b000 r-xp 00000000 08:11 18553 /usr/lib/libxcb.so.1.0.0
b712b000-b712c000 rw-p 00016000 08:11 18553 /usr/lib/libxcb.so.1.0.0
b712c000-b712d000 r-xp 00000000 08:11 18551 /usr/lib/libxcb-xlib.so.0.0.0
b712d000-b712e000 rw-p 00000000 08:11 18551 /usr/lib/libxcb-xlib.so.0.0.0
b712e000-b7142000 r-xp 00000000 08:11 18565 /usr/lib/libz.so.1.2.3.3
b7142000-b7143000 rw-p 00013000 08:11 18565 /usr/lib/libz.so.1.2.3.3
b7143000-b7144000 rw-p b7143000 00:00 0
b7144000-b7151000 r-xp 00000000 08:11 17727 /usr/lib/libXext.so.6.4.0
b7151000-b7152000 rw-p 0000d000 08:11 17727 /usr/lib/libXext.so.6.4.0
b7152000-b7154000 r-xp 00000000 08:11 1345189 /lib/tls/i686/cmov/libdl-2.7.so
b7154000-b7156000 rw-p 00001000 08:11 1345189 /lib/tls/i686/cmov/libdl-2.7.so
b7156000-b729f000 r-xp 00000000 08:11 1345186 /lib/tls/i686/cmov/libc-2.7.so
b729f000-b72a0000 r–p 00149000 08:11 1345186 /lib/tls/i686/cmov/libc-2.7.so
b72a0000-b72a2000 rw-p 0014a000 08:11 1345186 /lib/tls/i686/cmov/libc-2.7.so
b72a2000-b72a5000 rw-p b72a2000 00:00 0
b72a5000-b72af000 r-xp 00000000 08:11 1327680 /lib/libgcc_s.so.1
b72af000-b72b0000 rw-p 0000a000 08:11 1327680 /lib/libgcc_s.so.1
b72b0000-b72d3000 r-xp 00000000 08:11 1345190 /lib/tls/i686/cmov/libm-2.7.so
b72d3000-b72d5000 rw-p 00023000 08:11 1345190 /lib/tls/i686/cmov/libm-2.7.so
b72d5000-b73bd000 r-xp 00000000 08:11 16532 /usr/lib/libstdc++.so.6.0.9
b73bd000-b73c0000 r–p 000e8000 08:11 16532 /usr/lib/libstdc++.so.6.0.9
b73c0000-b73c2000 rw-p 000eb000 08:11 16532 /usr/lib/libstdc++.so.6.0.9
b73c2000-b73c9000 rw-p b73c2000 00:00 0
b73c9000-b7488000 r-xp 00000000 08:11 17784 /usr/lib/libasound.so.2.0.0
b7488000-b748c000 rw-p 000be000 08:11 17784 /usr/lib/libasound.so.2.0.0
b748c000-b748e000 r-xp 00000000 08:11 17737 /usr/lib/libXinerama.so.1.0.0
b748e000-b748f000 rw-p 00001000 08:11 17737 /usr/lib/libXinerama.so.1.0.0
b748f000-b7511000 r-xp 00000000 08:11 17669 /usr/lib/libGLU.so.1.3.070002
b7511000-b7512000 rw-p 00081000 08:11 17669 /usr/lib/libGLU.so.1.3.070002
b7512000-b759a000 r-xp 00000000 08:11 18614 /usr/lib/libGL.so.169.12
b759a000-b75b5000 rwxp 00087000 08:11 18614 /usr/lib/libGL.so.169.12
b75b5000-b75b6000 rwxp b75b5000 00:00 0
b75b6000-b769a000 r-xp 00000000 08:11 17706 /usr/lib/libX11.so.6.2.0
b769a000-b769d000 rw-p 000e4000 08:11 17706 /usr/lib/libX11.so.6.2.0
b769d000-b76a4000 r-xp 00000000 08:11 1345202 /lib/tls/i686/cmov/librt-2.7.so
b76a4000-b76a6000 rw-p 00006000 08:11 1345202 /lib/tls/i686/cmov/librt-2.7.so
b76a6000-b76a7000 rw-p b76a6000 00:00 0
b76a7000-b76bb000 r-xp 00000000 08:11 1345200 /lib/tls/i686/cmov/libpthread-2.7.so
b76bb000-b76bd000 rw-p 00013000 08:11 1345200 /lib/tls/i686/cmov/libpthread-2.7.so
b76bd000-b76bf000 rw-p b76bd000 00:00 0
b76bf000-b7729000 r-xp 00000000 08:11 16754 /usr/lib/libfreetype.so.6.3.16
b7729000-b772c000 rw-p 0006a000 08:11 16754 /usr/lib/libfreetype.so.6.3.16
b7739000-b773b000 rwxp 00000000 00:0e 1082 /dev/zero
b773b000-b773d000 rw-p b773b000 00:00 0
b773d000-b773e000 r-xp b773d000 00:00 0 [vdso]
b773e000-b7758000 r-xp 00000000 08:11 1327167 /lib/ld-2.7.so
b7758000-b775a000 rw-p 00019000 08:11 1327167 /lib/ld-2.7.so
bfe04000-bfe19000 rwxp bffea000 00:00 0 [stack]
Aborted
"

/////////////////////////////////////////////////////////////////////////
Problem 2. Linux CONFIG=Release assertion failed
/////////////////////////////////////////////////////////////////////////

I

(1) downloaded the latest GIT version 
(2) I did NOT modify the Makefile (so the -Os is used) 
(3) I modified the AppConfig.h of the Hello world adding these two lines:

#define  JUCE_FORCE_DEBUG        1
#define  JUCE_LOG_ASSERTIONS   1

 (4) run HelloWorld

> cd "extras/example projects/Build/Linux"
> make CONFIG=Release
    ...
    > build/HelloWorld 

this is the output I get:

build/HelloWorld
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 86
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 87
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 88
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 89
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 90
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 92
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 93
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 94
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 96
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 97
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 86
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 87
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 88
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 89
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 90
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 92
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 93
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 94
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 96
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/…/amalgamation/…/src/core/juce_Initialisation.cpp, line 97
JUCE v1.52.59

Well, I’m running ubuntu, with gcc 4.4 and don’t get any of that stuff. I thought it was gcc4.2 that had full support for atomics, but maybe it was 4.3…? You should update it anyway, 4.4 is a better compiler.

Your CXXFLAGS for your project should include “-DLINUX=1 -D_DEBUG=1 -DDEBUG=1” if you build a debug build.

Thanks for the tip.
But the problem seems to be specific for the release version.
I guess there is some optimization made by -O2 (or -O3) which breaks the release version.
I’m actually installing the latest Ubuntu version to see if it is a problem of Ubuntu or gcc.

Very unlikely to be ubuntu’s fault, but it could indeed be that version of gcc, so you should update that.

Updated Linux config:

Ubuntu 10.04 LTS
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3

It works. Both problems solved.