Skip to content

Commit

Permalink
Don't use the -fwhole-program compiler flag
Browse files Browse the repository at this point in the history
-fwhole-program can be used to tell the gcc that everything that
makes up the final program is included in the current command, which
allows it to use more aggressive optimizations. This can result in
smaller and faster code.

However, cmake always uses at least two commands to compile each
executable, even with the unity build: one for building the user code
and one for linking all libraries.

Using the -fwhole-program option here can cause the compiler to not
properly internalize some C++ objects (such as typeids) that are used
in both the user code and external libraries, resulting in unexpected
behavior.

From my tests, there is no measurable performance gain and the file size
reduction for the arx executable is 'only' around 18%. I think the
potential problems outweigh those benefits, so -fwhole-program must go.

This only affects unity builds as -fwhole-program was only used for
those. Unity builds are still possible and recommended.

In the future we can look into using link-time optimizations, but those
are not stable enough in current gcc versions to be enabled by default.
Also, quick tests show no real benefits.

See crash report #245
See also commit 58aa3 and crash report #243
  • Loading branch information
dscharrer committed May 24, 2012
1 parent c979ef0 commit 64c2352
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions CMakeLists.txt
Expand Up @@ -435,28 +435,6 @@ else(MSVC)
add_cxxflag("-Wno-constant-logical-operand")
endif()

if(UNITY_BUILD)

set(USE_FWHOLE_PROGRAM 1)

if(CMAKE_COMPILER_IS_GNUCXX AND ${Boost_VERSION} LESS 104100)
exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE compiler_string)
string(REGEX REPLACE ".* ([0-9])\\.([0-9])\\.[0-9].*" "\\1.\\2"
compiler_version "${compiler_string}")
if("${compiler_version}" VERSION_LESS 4.5 AND NOT "${compiler_version}" STREQUAL "")
# Cross-shared-object typeid is broken with some gcc versions
# Boost 1.41+ has a workaround for boost::any_cast:
# https://svn.boost.org/trac/boost/ticket/754
message(STATUS "not using -fwhole-program for GCC ${compiler_version} + Boost ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}")
set(USE_FWHOLE_PROGRAM 0)
endif()
endif()

if(${USE_FWHOLE_PROGRAM})
add_cxxflag("-fwhole-program")
endif()
endif()

# Because we are lazy
add_ldflag("-Wl,--as-needed")

Expand Down

0 comments on commit 64c2352

Please sign in to comment.