diff --git a/cmake/init-compilation-flags.cmake b/cmake/init-compilation-flags.cmake index 09ae3e17cd..a2aee3f278 100644 --- a/cmake/init-compilation-flags.cmake +++ b/cmake/init-compilation-flags.cmake @@ -36,7 +36,7 @@ if(APPLE) add_definitions(-D_XOPEN_SOURCE) else() # Since Ubuntu 22.04 lto is enabled by default; breaks some builds - add_link_options(-fno-lto) + #add_link_options(-fno-lto) endif() @@ -65,6 +65,20 @@ endif() cmake_print_variables(CMAKE_BUILD_TYPE) if("${CMAKE_BUILD_TYPE}" STREQUAL ${DEFAULT_BUILD_TYPE}) add_compile_options(-O3) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION 1) + if(CMAKE_INTERPROCEDURAL_OPTIMIZATION) + set(COMPILE_LTO_OPTIONS -flto) + set(LINK_LTO_OPTIONS -flto) + if(NOT APPLE) + list(APPEND COMPILE_LTO_OPTIONS -ffat-lto-objects) + endif() + if(COMPILER_GCC) + list(APPEND COMPILE_LTO_OPTIONS -Wl,-flto) + endif() + add_compile_options(${COMPILE_LTO_OPTIONS}) + add_link_options(${LINK_LTO_OPTIONS}) + list(JOIN COMPILE_LTO_OPTIONS " " THIRD_PARTY_LTO_OPTIONS) + endif() endif() if(DEFINED ENV{FAST_COMPILATION_FMT}) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 2747a77f98..be6b879487 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -69,7 +69,13 @@ endfunction() function(allow_deprecated_declarations) foreach(src_file ${ARGN}) - set_source_files_properties(${src_file} PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) + set_property(SOURCE ${src_file} APPEND PROPERTY COMPILE_OPTIONS -Wno-deprecated-declarations) + endforeach() +endfunction() + +function(allow_stringop_overflow) + foreach(src_file ${ARGN}) + set_property(SOURCE ${src_file} APPEND PROPERTY COMPILE_OPTIONS -Wno-stringop-overflow) endforeach() endfunction() diff --git a/compiler/compiler-settings.cpp b/compiler/compiler-settings.cpp index 491e23f4aa..1575da4004 100644 --- a/compiler/compiler-settings.cpp +++ b/compiler/compiler-settings.cpp @@ -340,7 +340,7 @@ void CompilerSettings::init() { std::string cxx_default_flags = ss.str(); cxx_toolchain_option.value_ = !cxx_toolchain_dir.value_.empty() ? ("-B" + cxx_toolchain_dir.value_) : ""; - incremental_linker_flags.value_ = dynamic_incremental_linkage.get() ? "-shared" : "-r -nostdlib"; + incremental_linker_flags.value_ = dynamic_incremental_linkage.get() ? "-shared" : "-r -nostdlib -gdwarf64 -gdwarf-5 -mcmodel=large -flto -Wl,-flto -flinker-output=rel"; remove_extra_spaces(extra_ld_flags.value_); diff --git a/compiler/compiler.cmake b/compiler/compiler.cmake index 3fcdcab68e..4d697b978a 100644 --- a/compiler/compiler.cmake +++ b/compiler/compiler.cmake @@ -225,9 +225,36 @@ prepend(KPHP_COMPILER_SOURCES ${KPHP_COMPILER_DIR}/ utils/string-utils.cpp) # Suppress YAML-cpp-related warnings -if(COMPILER_CLANG) - allow_deprecated_declarations(${KPHP_COMPILER_DIR}/data/composer-json-data.cpp) - allow_deprecated_declarations(${KPHP_COMPILER_DIR}/data/modulite-data.cpp) +if(COMPILER_CLANG OR (COMPILER_GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0"))) + allow_deprecated_declarations( + ${KPHP_COMPILER_DIR}/data/composer-json-data.cpp + ${KPHP_COMPILER_DIR}/data/modulite-data.cpp + ) +endif() + +if(COMPILER_GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0")) + allow_stringop_overflow( + ${KPHP_COMPILER_DIR}/code-gen/vertex-compiler.cpp + ${KPHP_COMPILER_DIR}/data/class-data.cpp + ${KPHP_COMPILER_DIR}/data/kphp-json-tags.cpp + ${KPHP_COMPILER_DIR}/data/generics-mixins.cpp + ${KPHP_COMPILER_DIR}/data/kphp-tracing-tags.cpp + ${KPHP_COMPILER_DIR}/data/modulite-data.cpp + ${KPHP_COMPILER_DIR}/code-gen/files/tracing-autogen.cpp + ${KPHP_COMPILER_DIR}/pipes/analyze-performance.cpp + ${KPHP_COMPILER_DIR}/pipes/check-access-modifiers.cpp + ${KPHP_COMPILER_DIR}/pipes/check-classes.cpp + ${KPHP_COMPILER_DIR}/pipes/check-tl-classes.cpp + ${KPHP_COMPILER_DIR}/pipes/code-gen.cpp + ${KPHP_COMPILER_DIR}/pipes/filter-only-actually-used.cpp + ${KPHP_COMPILER_DIR}/pipes/final-check.cpp + ${KPHP_COMPILER_DIR}/pipes/parse-and-apply-phpdoc.cpp + ${KPHP_COMPILER_DIR}/pipes/sort-and-inherit-classes.cpp + ${KPHP_COMPILER_DIR}/pipes/register-kphp-configuration.cpp + ${KPHP_COMPILER_DIR}/phpdoc.cpp + ${KPHP_COMPILER_DIR}/gentree.cpp + ${KPHP_COMPILER_DIR}/make/make.cpp + ) endif() if(APPLE) diff --git a/compiler/ffi/c_parser/parsing_driver.cpp b/compiler/ffi/c_parser/parsing_driver.cpp index e0989a6aca..709a3feba1 100644 --- a/compiler/ffi/c_parser/parsing_driver.cpp +++ b/compiler/ffi/c_parser/parsing_driver.cpp @@ -11,6 +11,7 @@ #include #include +#include using namespace ffi; @@ -113,7 +114,7 @@ FFIType *ParsingDriver::function_to_var(FFIType *function) { function->kind = FFITypeKind::Var; FFIType *function_ptr_type = alloc.new_type(FFITypeKind::FunctionPointer); function_ptr_type->members = std::move(function->members); - function->members = {function_ptr_type}; + function->members = std::vector{function_ptr_type}; return function; } diff --git a/runtime-common/core/core-types/definition/array.inl b/runtime-common/core/core-types/definition/array.inl index ce1270adae..b6f3d8ef7a 100644 --- a/runtime-common/core/core-types/definition/array.inl +++ b/runtime-common/core/core-types/definition/array.inl @@ -107,14 +107,22 @@ template<> inline typename array::array_inner* array::array_inner::empty_array() { // need this hack because gcc10 and newer complains about // "array subscript is outside array bounds of array::array_inner" - static array_inner_control empty_array[1]{{ - true, - ExtraRefCnt::for_global_const, - -1, - {0, 0}, - 0, - 2, - }}; + static array_inner_control empty_array[2]{{ + true, + ExtraRefCnt::for_global_const, + -1, + {0, 0}, + 0, + 2, + }, + { + true, + ExtraRefCnt::for_global_const, + -1, + {0, 0}, + 0, + 2, + }}; return static_cast::array_inner*>(&empty_array[0]); } diff --git a/runtime/runtime.cmake b/runtime/runtime.cmake index 80d5a0b1e0..9aa98ff158 100644 --- a/runtime/runtime.cmake +++ b/runtime/runtime.cmake @@ -142,7 +142,7 @@ set_source_files_properties( ) # Suppress YAML-cpp-related warnings -if(COMPILER_CLANG) +if(COMPILER_CLANG OR (COMPILER_GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0"))) allow_deprecated_declarations(${BASE_DIR}/runtime/interface.cpp) endif() diff --git a/server/server.cmake b/server/server.cmake index 59ac5f311c..fd1b5dbf9f 100644 --- a/server/server.cmake +++ b/server/server.cmake @@ -31,12 +31,14 @@ prepend(KPHP_SERVER_SOURCES ${BASE_DIR}/server/ signal-handlers.cpp) # Suppress YAML-cpp-related warnings -if(COMPILER_CLANG) - allow_deprecated_declarations(${BASE_DIR}/server/json-logger.cpp) - allow_deprecated_declarations(${BASE_DIR}/server/lease-config-parser.cpp) - allow_deprecated_declarations(${BASE_DIR}/server/php-engine.cpp) - allow_deprecated_declarations(${BASE_DIR}/server/php-master.cpp) - allow_deprecated_declarations(${BASE_DIR}/server/server-config.cpp) +if(COMPILER_CLANG OR (COMPILER_GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0"))) + allow_deprecated_declarations( + ${BASE_DIR}/server/json-logger.cpp + ${BASE_DIR}/server/lease-config-parser.cpp + ${BASE_DIR}/server/php-engine.cpp + ${BASE_DIR}/server/php-master.cpp + ${BASE_DIR}/server/server-config.cpp + ) endif() prepend(KPHP_JOB_WORKERS_SOURCES ${BASE_DIR}/server/job-workers/ diff --git a/tests/cpp/server/server-tests.cmake b/tests/cpp/server/server-tests.cmake index 98827729e2..ebfd72f529 100644 --- a/tests/cpp/server/server-tests.cmake +++ b/tests/cpp/server/server-tests.cmake @@ -7,7 +7,7 @@ prepend(SERVER_TESTS_SOURCES ${BASE_DIR}/tests/cpp/server/ workers-control-test.cpp) # Suppress YAML-cpp-related warnings -if(COMPILER_CLANG) +if(COMPILER_CLANG OR (COMPILER_GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0"))) allow_deprecated_declarations(${BASE_DIR}/tests/cpp/server/server-config-test.cpp) endif() diff --git a/third-party/curl-cmake/curl.cmake b/third-party/curl-cmake/curl.cmake index 0b0178a043..19d7d63413 100644 --- a/third-party/curl-cmake/curl.cmake +++ b/third-party/curl-cmake/curl.cmake @@ -25,7 +25,7 @@ function(build_curl PIC_ENABLED) file(MAKE_DIRECTORY ${install_dir}) file(MAKE_DIRECTORY ${include_dirs}) - set(compile_flags "$ENV{CFLAGS} -g0 -Wno-deprecated-declarations ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 -Wno-deprecated-declarations ${extra_compile_flags}") # Suppress compiler-specific warnings caused by -O3 if(COMPILER_CLANG) diff --git a/third-party/nghttp2-cmake/nghttp2.cmake b/third-party/nghttp2-cmake/nghttp2.cmake index 87458c35a5..835d4809c8 100644 --- a/third-party/nghttp2-cmake/nghttp2.cmake +++ b/third-party/nghttp2-cmake/nghttp2.cmake @@ -30,7 +30,7 @@ function(build_nghttp2 PIC_ENABLED) file(MAKE_DIRECTORY ${install_dir}) file(MAKE_DIRECTORY ${include_dirs}) - set(compile_flags "$ENV{CFLAGS} -g0 ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 ${extra_compile_flags}") message(STATUS "NGHTTP2 Summary: diff --git a/third-party/numactl-cmake/numactl.cmake b/third-party/numactl-cmake/numactl.cmake index 4682907dc7..ed5f32a051 100644 --- a/third-party/numactl-cmake/numactl.cmake +++ b/third-party/numactl-cmake/numactl.cmake @@ -27,7 +27,7 @@ function(build_numactl PIC_ENABLED) # The configuration has been based on: # https://sources.debian.org/src/numactl/2.0.12-1/debian/rules/ - set(compile_flags "$ENV{CFLAGS} -Wno-unused-but-set-variable -g0 ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} -Wno-unused-but-set-variable -g0 -fno-lto ${extra_compile_flags}") message(STATUS "NUMA Summary: diff --git a/third-party/openssl-cmake/openssl.cmake b/third-party/openssl-cmake/openssl.cmake index 0fec65a816..3b356a1e59 100644 --- a/third-party/openssl-cmake/openssl.cmake +++ b/third-party/openssl-cmake/openssl.cmake @@ -35,7 +35,7 @@ function(build_openssl PIC_ENABLED) file(MAKE_DIRECTORY ${install_dir}) file(MAKE_DIRECTORY ${include_dirs}) - set(compile_flags "$ENV{CFLAGS} -g0 ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 ${extra_compile_flags}") # The configuration has been based on: # https://packages.debian.org/buster/libssl1.1 diff --git a/third-party/pcre-cmake/pcre.cmake b/third-party/pcre-cmake/pcre.cmake index 38325357dd..0b345038e9 100644 --- a/third-party/pcre-cmake/pcre.cmake +++ b/third-party/pcre-cmake/pcre.cmake @@ -30,7 +30,7 @@ function(build_pcre PIC_ENABLED) file(MAKE_DIRECTORY ${install_dir}) file(MAKE_DIRECTORY ${include_dirs}) - set(compile_flags "$ENV{CFLAGS} -g0 -Wall ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 -Wall ${extra_compile_flags}") message(STATUS "PCRE Summary: diff --git a/third-party/pcre2-cmake/pcre2.cmake b/third-party/pcre2-cmake/pcre2.cmake index d72510dc98..4cd9c5b364 100644 --- a/third-party/pcre2-cmake/pcre2.cmake +++ b/third-party/pcre2-cmake/pcre2.cmake @@ -28,7 +28,7 @@ function(build_pcre2 PIC_ENABLED) file(MAKE_DIRECTORY ${install_dir}) file(MAKE_DIRECTORY ${include_dirs}) - set(compile_flags "$ENV{CFLAGS} -O3 ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -O3 ${extra_compile_flags}") message(STATUS "PCRE2 Summary: diff --git a/third-party/re2-cmake/re2.cmake b/third-party/re2-cmake/re2.cmake index 446c77fe25..3341f31a06 100644 --- a/third-party/re2-cmake/re2.cmake +++ b/third-party/re2-cmake/re2.cmake @@ -37,7 +37,7 @@ function(build_re2 PIC_ENABLED) # The configuration has been based on: # https://sources.debian.org/src/re2/20190101%2Bdfsg-2/debian/rules/#L5 - set(compile_flags "$ENV{CFLAGS} -g0 -Wall -std=c++11 -O3 ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 -Wall -std=c++11 -O3 ${extra_compile_flags}") message(STATUS "RE2 Summary: diff --git a/third-party/timelib-cmake/timelib.cmake b/third-party/timelib-cmake/timelib.cmake index a99225c9bd..3c1c07ac78 100644 --- a/third-party/timelib-cmake/timelib.cmake +++ b/third-party/timelib-cmake/timelib.cmake @@ -36,7 +36,7 @@ function(build_timelib PIC_ENABLED) file(MAKE_DIRECTORY ${install_dir}) file(MAKE_DIRECTORY ${include_dirs}) - set(compile_flags "$ENV{CFLAGS} -g0 ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 ${extra_compile_flags}") message(STATUS "Timelib Summary: diff --git a/third-party/uber-h3-cmake/uber-h3.cmake b/third-party/uber-h3-cmake/uber-h3.cmake index f692505ce4..0fad35c907 100644 --- a/third-party/uber-h3-cmake/uber-h3.cmake +++ b/third-party/uber-h3-cmake/uber-h3.cmake @@ -26,7 +26,7 @@ function(build_uber_h3 PIC_ENABLED) file(MAKE_DIRECTORY ${install_dir}) file(MAKE_DIRECTORY ${include_dirs}) - set(compile_flags "$ENV{CFLAGS} -g0 ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 ${extra_compile_flags}") message(STATUS "Uber-h3 Summary: diff --git a/third-party/yaml-cpp-cmake/yaml-cpp.cmake b/third-party/yaml-cpp-cmake/yaml-cpp.cmake index 9d8e57766d..52da416708 100644 --- a/third-party/yaml-cpp-cmake/yaml-cpp.cmake +++ b/third-party/yaml-cpp-cmake/yaml-cpp.cmake @@ -25,7 +25,7 @@ function(build_yaml_cpp PIC_ENABLED) file(MAKE_DIRECTORY ${install_dir}) file(MAKE_DIRECTORY ${include_dirs}) - set(compile_flags "$ENV{CFLAGS} -g0 ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 ${extra_compile_flags}") # Suppress compiler-specific warnings if(COMPILER_CLANG) diff --git a/third-party/zlib-cmake/zlib.cmake b/third-party/zlib-cmake/zlib.cmake index 13cf3c356d..7bbb8e7b95 100644 --- a/third-party/zlib-cmake/zlib.cmake +++ b/third-party/zlib-cmake/zlib.cmake @@ -27,7 +27,7 @@ function(build_zlib PIC_ENABLED) # The configuration has been based on: # https://sources.debian.org/src/zlib/1%3A1.3.dfsg%2Breally1.3.1-1/debian/rules/#L20 - set(compile_flags "$ENV{CFLAGS} -g0 -Wall -O3 -D_REENTRANT ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 -Wall -O3 -D_REENTRANT ${extra_compile_flags}") message(STATUS "Zlib Summary: diff --git a/third-party/zstd-cmake/zstd.cmake b/third-party/zstd-cmake/zstd.cmake index 2448568b3e..053dc89958 100644 --- a/third-party/zstd-cmake/zstd.cmake +++ b/third-party/zstd-cmake/zstd.cmake @@ -30,7 +30,7 @@ function(build_zstd PIC_ENABLED) # The configuration has been based on: # https://sources.debian.org/src/libzstd/1.4.8%2Bdfsg-2.1/debian/rules/ - set(compile_flags "$ENV{CFLAGS} -g0 -Wno-unused-but-set-variable ${extra_compile_flags}") + set(compile_flags "$ENV{CFLAGS} ${THIRD_PARTY_LTO_OPTIONS} -g0 -Wno-unused-but-set-variable ${extra_compile_flags}") message(STATUS "ZSTD Summary: diff --git a/vkext/vkext-rpc.cpp b/vkext/vkext-rpc.cpp index 6f5512327c..1096c52d15 100644 --- a/vkext/vkext-rpc.cpp +++ b/vkext/vkext-rpc.cpp @@ -155,7 +155,9 @@ void update_precise_now() { } rpc_connection *rpc_connection_get(int fd) { - rpc_connection **T = tree_lookup_value_connection(rpc_connection_tree, reinterpret_cast(&fd)); + static rpc_connection dummy_rpc_connection{}; + dummy_rpc_connection.fd = fd; + rpc_connection **T = tree_lookup_value_connection(rpc_connection_tree, reinterpret_cast(&dummy_rpc_connection)); return T ? *T : 0; }