From 41455566ac633e55f222bce7c4d2cb4cc33d5c72 Mon Sep 17 00:00:00 2001 From: Alex Stewart Date: Mon, 28 Sep 2015 22:43:42 +0100 Subject: [PATCH] Remove link-time optimisation (LTO). - On GCC 4.9+ although GCC supports LTO, it requires use of the non-default gcc-ar & gcc-ranlib. Whilst we can ensure Ceres is compiled with these, doing so with GCC 4.9 causes multiple definition linker errors of static ints inside Eigen when compiling the tests and examples when they are not also built with LTO. - On OS X (Xcode 6 & 7) after the latest update to gtest, if LTO is used when compiling the tests (& examples), two tests fail due to typeinfo::operator== (things are fine if only Ceres itself is compiled with LTO). - This patch disables LTO for all compilers. It should be revisited when the performance is more stable across our supported compilers. Change-Id: I17b52957faefbdeff0aa40846dc9b342db1b02e3 --- docs/source/version_history.rst | 3 +++ internal/ceres/CMakeLists.txt | 17 ----------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/docs/source/version_history.rst b/docs/source/version_history.rst index d1a19901d..ee082c453 100644 --- a/docs/source/version_history.rst +++ b/docs/source/version_history.rst @@ -27,6 +27,9 @@ New Features Bug Fixes & Minor Changes ------------------------- +#. Remove use of link-time optimisation (LTO) for all compilers due to + portability issues with gtest / type_info::operator== & Eigen with + Clang on OS X vs GCC 4.9+ on Linux requiring contradictory 'fixes'. #. Use link-time optimisation (LTO) only when compiling Ceres itself, not tests or examples, to bypass gtest / type_info::operator== issue. #. Use old minimum iOS version flags on Xcode < 7.0. diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt index cc2cb8970..3a51309d9 100644 --- a/internal/ceres/CMakeLists.txt +++ b/internal/ceres/CMakeLists.txt @@ -201,23 +201,6 @@ if (NOT WIN32 AND NOT BUILD_SHARED_LIBS) endif() endif() -# Use of -flto requires use of gold linker & LLVM-gold plugin, which might -# well not be present / in use and without which files will compile, but -# not link ('file not recognized') so explicitly check for support. -# -# Only use link-time optimisation (LTO) flags when building Ceres itself, as it -# causes an issue with type_info::operator==() in gtest's -# CheckedDowncastToActualType() in levenberg_marquardt_strategy_test & -# gradient_checking_cost_function_test if enabled for the tests as well. -include(CheckCXXCompilerFlag) -check_cxx_compiler_flag("-flto" HAVE_LTO_SUPPORT) -if (HAVE_LTO_SUPPORT) - message(STATUS "Enabling link-time optimization (-flto)") - append_target_property(ceres COMPILE_FLAGS "-flto") -else () - message(STATUS "Compiler/linker does not support link-time optimization (-flto).") -endif (HAVE_LTO_SUPPORT) - if (CMAKE_VERSION VERSION_LESS "2.8.12") # CMake version < 2.8.12 does not support target_compile_options(), warn # user that they will have to add compile flags to their own projects