mysql/community-mysql-lto.patch

120 lines
4.6 KiB
Diff
Raw Normal View History

2020-08-17 11:54:35 +00:00
commit dfd43f7d5527680fd27a29c80e8eb3b9b5165220
Author: Tor Didriksen <tor.didriksen@oracle.com>
Date: Mon Aug 3 16:39:21 2020 +0200
Bug #31701553 CMAKE CODE TO DISABLE LTO IS TOO SIMPLE
Parts of our codebase (3rd party libraries) fail to compile/link if built with -flto.
For these we simply remove "-flto[=n|auto|jobserver] from
CMAKE_C_FLAGS and CMAKE_CXX_FLAGS.
We also disable linkers lld and gold by default if building with
link-time optimization.
Change-Id: I84e9f7128a4d263056aa60c188e6430ea7161655
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dc118b37472..919e7cbd783 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -639,6 +639,10 @@ OPTION(WITH_LTO
${WITH_LTO_DEFAULT}
)
+IF(CMAKE_C_FLAGS MATCHES " -flto" OR CMAKE_CXX_FLAGS MATCHES " -flto")
+ SET(CMAKE_COMPILER_FLAG_WITH_LTO 1)
+ENDIF()
+
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
# We need some extra FAIL_REGEX patterns
@@ -848,7 +852,7 @@ ENDIF()
# Use lld for Clang if available and not explicitly disabled.
# Also works for gcc on Debian/Ubuntu. Do 'apt install lld'.
# LTO build fails with lld, so turn it off by default.
-IF(LINUX AND NOT WITH_LTO)
+IF(LINUX AND NOT WITH_LTO AND NOT CMAKE_COMPILER_FLAG_WITH_LTO)
OPTION(USE_LD_LLD "Use llvm lld linker" ON)
ELSE()
OPTION(USE_LD_LLD "Use llvm lld linker" OFF)
@@ -879,7 +883,11 @@ IF(USE_LD_LLD)
ENDIF()
# Use gold on x86 if available and not explicitly disabled.
-IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT WIN32)
+# LTO build fails with gold, so turn it off by default.
+IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
+ AND NOT WIN32
+ AND NOT WITH_LTO
+ AND NOT CMAKE_COMPILER_FLAG_WITH_LTO)
OPTION(USE_LD_GOLD "Use GNU gold linker" ON)
ELSE()
OPTION(USE_LD_GOLD "Use GNU gold linker" OFF)
diff --git a/cmake/compile_flags.cmake b/cmake/compile_flags.cmake
index 053e48b9e70..bb1338ee9f8 100644
--- a/cmake/compile_flags.cmake
+++ b/cmake/compile_flags.cmake
@@ -1,4 +1,4 @@
-# Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2014, 2020, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
@@ -83,3 +83,12 @@ FUNCTION(ADD_COMPILE_DEFINITIONS)
${FILE} PROPERTIES COMPILE_DEFINITIONS "${DEFS}")
ENDFOREACH()
ENDFUNCTION()
+
+# -flto[=n] or -flto=auto or -flto=jobserver
+SET(MY_COMPILER_FLAG_FLTO " -flto(=[0-9a-z]+)?")
+
+# Remove compiler flag/pattern from CMAKE_C_FLAGS or CMAKE_CXX_FLAGS
+FUNCTION(REMOVE_CMAKE_COMPILER_FLAGS FLAG_VAR PATTERN)
+ STRING(REGEX REPLACE "${PATTERN}" "" ${FLAG_VAR} "${${FLAG_VAR}}")
+ SET(${FLAG_VAR} "${${FLAG_VAR}}" PARENT_SCOPE)
+ENDFUNCTION()
diff --git a/extra/icu/CMakeLists.txt b/extra/icu/CMakeLists.txt
index aa1cfb1a90e..81ef19335a0 100644
--- a/extra/icu/CMakeLists.txt
+++ b/extra/icu/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2017, 2020, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
@@ -91,8 +91,10 @@ IF(MSVC AND NOT WIN32_CLANG)
STRING_APPEND(CMAKE_CXX_FLAGS " /wd4229")
ENDIF()
-STRING(REPLACE "-flto" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
-STRING(REPLACE "-flto" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+IF(WITH_ICU STREQUAL "bundled")
+ REMOVE_CMAKE_COMPILER_FLAGS(CMAKE_C_FLAGS "${MY_COMPILER_FLAG_FLTO}")
+ REMOVE_CMAKE_COMPILER_FLAGS(CMAKE_CXX_FLAGS "${MY_COMPILER_FLAG_FLTO}")
+ENDIF()
ADD_SUBDIRECTORY(source/common)
ADD_SUBDIRECTORY(source/i18n)
diff --git a/plugin/innodb_memcached/CMakeLists.txt b/plugin/innodb_memcached/CMakeLists.txt
index b9d93da5f20..00bbddeb3ec 100644
--- a/plugin/innodb_memcached/CMakeLists.txt
+++ b/plugin/innodb_memcached/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2020, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
@@ -76,8 +76,8 @@ IF(WITH_INNODB_MEMCACHED AND UNIX)
ENDIF()
# -Werror=lto-type-mismatch for misc functions.
- STRING(REPLACE "-flto" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
- STRING(REPLACE "-flto" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ REMOVE_CMAKE_COMPILER_FLAGS(CMAKE_C_FLAGS "${MY_COMPILER_FLAG_FLTO}")
+ REMOVE_CMAKE_COMPILER_FLAGS(CMAKE_CXX_FLAGS "${MY_COMPILER_FLAG_FLTO}")
ADD_SUBDIRECTORY(daemon_memcached)
ADD_SUBDIRECTORY(innodb_memcache)