Bug #111652 mysql cmake build fails with clang+LTO
Submitted: 4 Jul 2023 9:03 Modified: 4 Jul 2023 14:05
Reporter: Ofek Shilon Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any
Tags: build configuration

[4 Jul 2023 9:03] Ofek Shilon
Description:
Trying to cmake with clang and LTO fails.

How to repeat:
$ export CC=clang
$ export CXX=clang++
$ mkdir build && cd build
$ cmake .. -G Ninja -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../boost -DWITH_LTO=ON

fails with:

...
-- Performing Test CXX_LTO_RESULT
-- Performing Test CXX_LTO_RESULT - Failed
CMake Error at CMakeLists.txt:1600 (MESSAGE):
  Compiler does not support -flto
[4 Jul 2023 14:05] MySQL Verification Team
Hello Ofek Shilon,

Thank you for the report and feedback.
I quickly tried to build with the provided cmake options but not seeing any issues. Please confirm exact server version you are trying to build and Which version of clang are you using? Thank you.

Also, see https://dev.mysql.com/doc/mysql-sourcebuild-excerpt/8.0/en/source-configuration-options.ht...
https://dev.mysql.com/doc/mysql-sourcebuild-excerpt/8.0/en/source-configuration-options.ht...

##
 rm -rf CMakeCache.txt
mkdir build && cd build
cmake .. -G Ninja -DWITH_BOOST=../boost -DWITH_LTO=ON
-- Running cmake version 3.22.1
-- Found Git: /usr/bin/git (found version "2.31.1")
-- CMAKE_MODULE_PATH is /export/home/tmp/ushastry/src/mysql-8.0.33/cmake
-- MySQL 8.0.33
-- The C compiler identification is Clang 13.0.1
-- The CXX compiler identification is Clang 13.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Source directory /export/home/tmp/ushastry/src/mysql-8.0.33
-- Binary directory /export/home/tmp/ushastry/src/mysql-8.0.33/build
-- CMAKE_GENERATOR: Ninja
-- Looking for SHM_HUGETLB
-- Looking for SHM_HUGETLB - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void *
-- Check size of void * - done
-- SIZEOF_VOIDP 8
-- Packaging as: mysql-8.0.33-Linux-aarch64
-- Performing Test HAVE_OUTLINE_ATOMICS
-- Performing Test HAVE_OUTLINE_ATOMICS - Success
-- Local boost dir /export/home/tmp/ushastry/src/mysql-8.0.33/boost/boost_1_77_0
-- Found /export/home/tmp/ushastry/src/mysql-8.0.33/boost/boost_1_77_0/boost/version.hpp
-- BOOST_VERSION_NUMBER is #define BOOST_VERSION 107700
-- BOOST_INCLUDE_DIR /export/home/tmp/ushastry/src/mysql-8.0.33/boost/boost_1_77_0
.
.
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;BOOST_NO_CXX98_FUNCTION_BASE;HAVE_CONFIG_H;__STDC_LIMIT_MACROS;__STDC_FORMAT_MACROS;_USE_MATH_DEFINES;LZ4_DISABLE_DEPRECATE_WARNINGS;HAVE_TLSv13
-- CMAKE_C_FLAGS: -fno-omit-frame-pointer -ftls-model=initial-exec  -moutline-atomics -flto -Wall -Wextra -Wformat-security -Wvla -Wundef -Wmissing-format-attribute -Wwrite-strings -Wconditional-uninitialized -Wextra-semi -Wmissing-noreturn -Wunreachable-code-break -Wunreachable-code-return
-- CMAKE_CXX_FLAGS: -std=c++17 -fno-omit-frame-pointer -ftls-model=initial-exec  -moutline-atomics -march=armv8-a+crc -flto -Wall -Wextra -Wformat-security -Wvla -Wundef -Wmissing-format-attribute -Woverloaded-virtual -Wcast-qual -Wno-null-conversion -Wno-unused-private-field -Wconditional-uninitialized -Wdeprecated -Wextra-semi -Wheader-hygiene -Wnon-virtual-dtor -Wundefined-reinterpret-cast -Wrange-loop-analysis -Winconsistent-missing-destructor-override -Winconsistent-missing-override -Wshadow-field
-- CMAKE_CXX_FLAGS_DEBUG: -DSAFE_MUTEX -DENABLED_DEBUG_SYNC -g
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -g1
-- CMAKE_CXX_FLAGS_RELEASE: -ffunction-sections -fdata-sections -O3 -DNDEBUG
-- CMAKE_CXX_FLAGS_MINSIZEREL: -ffunction-sections -fdata-sections -Os -DNDEBUG
-- CMAKE_C_LINK_FLAGS:
-- CMAKE_CXX_LINK_FLAGS:  -flto
-- CMAKE_EXE_LINKER_FLAGS
-- CMAKE_MODULE_LINKER_FLAGS
-- CMAKE_SHARED_LINKER_FLAGS  -flto
-- Configuring done
-- Generating done
-- Build files have been written to: /export/home/tmp/ushastry/src/mysql-8.0.33/build

regards,
Umesh