Skip to content

Commit

Permalink
Fixed boost::flat_map/gcc 4.1.2 crash.
Browse files Browse the repository at this point in the history
The boost::flat_map implementation makes calls to container_detail::force_copy(), which as far as GCC 4.1.2 is concerned breaks strict aliasing rules. GCC then outputs code which crashes in our Context class, which uses flat_map internally.

This is "fixed" by disabling the strict-aliasing optimisations when we detect compilation with GCC 4.1.2. Although there may be some performance implications to this, it turns out that our OS X builds never enabled that optimisation, because there it does not default to on with -O2, and performance has always seemed OK.

As one nice side effect of this, we have now removed the disabling of warnings for strict-aliasing problems, which were previously disabled across all compilers on Linux (to work around other problems in boost, and the -isystem flag in GCC 4.1.2). So we now do at least have more complete error checking in more recent compilers.
  • Loading branch information
johnhaddon committed May 30, 2014
1 parent cef54fc commit ca6c228
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions SConstruct
Expand Up @@ -510,12 +510,14 @@ if env["PLATFORM"] == "darwin" :

elif env["PLATFORM"] == "posix" :

## We really want to not have the -Wno-strict-aliasing flag, but it's necessary to stop boost
# python warnings that don't seem to be prevented by including boost via -isystem even. Better to
# be able to have -Werror but be missing one warning than to have no -Werror.
## \todo This is probably only necessary for specific gcc versions where -isystem doesn't
# fully work. Reenable when we encounter versions that work correctly.
env.Append( CXXFLAGS = [ "-Wno-strict-aliasing" ] )
# gcc 4.1.2 in conjunction with boost::flat_map produces crashes when
# using the -fstrict-aliasing optimisation (which defaults to on with -O2),
# so we turn the optimisation off here, only for that specific gcc version.
if "g++" in os.path.basename( env["CXX"] ) :
gccVersion = subprocess.Popen( [ env["CXX"], "-dumpversion" ], env=env["ENV"], stdout=subprocess.PIPE ).stdout.read().strip()
if gccVersion == "4.1.2" :
env.Append( CXXFLAGS = [ "-fno-strict-aliasing" ] )

env["GAFFER_PLATFORM"] = "linux"

if env["BUILD_CACHEDIR"] != "" :
Expand Down Expand Up @@ -809,12 +811,9 @@ baseLibEnv.Append(
)

# include 3rd party headers with -isystem rather than -I.
# this should turns off warnings from those headers, allowing us to
# this should turn off warnings from those headers, allowing us to
# build with -Werror. there are so many warnings from boost
# in particular that this would be otherwise impossible - note that
# we're still having to turn off strict aliasing warnings in the
# default CXXFLAGS because somehow they creep out of boost python
# and past the defences.
# in particular that this would be otherwise impossible.
for path in [
"$BUILD_DIR/include",
"$BUILD_DIR/include/python$PYTHON_VERSION",
Expand Down

0 comments on commit ca6c228

Please sign in to comment.