From cf73c7db8814078b9ad95de3d2095d058b5152ca Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 13:20:45 +1100 Subject: [PATCH 01/10] Enable Interprocedural Optimization Interprocedural Optimization (LTO) provides generally good benefits for performance. Lets enable this where supported. To achieve this gain we need to be strict and accurate with function prototypes and casting and not rely on undefined behaviour. --- configure.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/configure.cmake b/configure.cmake index 7d345645b85d4..08c6a6f09204a 100644 --- a/configure.cmake +++ b/configure.cmake @@ -22,7 +22,7 @@ INCLUDE (CheckFunctionExists) INCLUDE (CheckCCompilerFlag) INCLUDE (CheckCSourceRuns) INCLUDE (CheckSymbolExists) - +INCLUDE (CheckIPOSupported) # WITH_PIC options.Not of much use, PIC is taken care of on platforms # where it makes sense anyway. @@ -41,7 +41,12 @@ IF(UNIX) ENDIF() ENDIF() - +# With INTERPROCEDURAL OPTMIZATION +CHECK_IPO_SUPPORTED(RESULT IPO_SUPPORTED LANGUAGES C CXX) +IF(IPO_SUPPORTED) + SET(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +ENDIF() +ADD_FEATURE_INFO(INTERPROCEDURAL_OPTIMIZATION IPO_SUPPORTED "Support Interprocedural Optmization (LTO)") # System type affects version_compile_os variable IF(NOT SYSTEM_TYPE) From 43816876c793cd0c6ce88c700b0abe7f3bf44807 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 14:59:12 +1100 Subject: [PATCH 02/10] rename second sql_mode_string_representation to sql_mode_string_representation_for_bit --- sql/set_var.h | 2 +- sql/sql_mode.cc | 2 +- sql/sys_vars.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/set_var.h b/sql/set_var.h index c8da3c1c1697a..6c9ee3dcaf087 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -463,7 +463,7 @@ inline bool IS_SYSVAR_AUTOSIZE(void *ptr) bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type); sql_mode_t expand_sql_mode(sql_mode_t sql_mode); -const char *sql_mode_string_representation(uint bit_number); +const char *sql_mode_string_representation_for_bit(uint bit_number); bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode, LEX_CSTRING *ls); int default_regex_flags_pcre(THD *thd); diff --git a/sql/sql_mode.cc b/sql/sql_mode.cc index 6e62fa8fa24cc..90a8b5c54f984 100644 --- a/sql/sql_mode.cc +++ b/sql/sql_mode.cc @@ -28,7 +28,7 @@ void Sql_mode_dependency::push_dependency_warnings(THD *thd) const push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, "Expression depends on the @@%s value %s", - "sql_mode", sql_mode_string_representation(i)); + "sql_mode", sql_mode_string_representation_for_bit(i)); } } } diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index cb35386f883c5..33951e34f1b8e 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -3766,7 +3766,7 @@ static const char *sql_mode_names[]= }; -const char *sql_mode_string_representation(uint bit_number) +const char *sql_mode_string_representation_for_bit(uint bit_number) { DBUG_ASSERT(bit_number < array_elements(sql_mode_names)); return sql_mode_names[bit_number]; From a856090cd8eae95d63174da7eb0e83f0431600ff Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 15:08:36 +1100 Subject: [PATCH 03/10] i_s_metadata_lock_info_fill_row correct function def --- sql/mdl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/mdl.h b/sql/mdl.h index fad81ce9249d8..3c38c7bc83a34 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -1100,7 +1100,7 @@ class MDL_context MDL_context &operator=(MDL_context &rhs); /* not implemented */ /* metadata_lock_info plugin */ - friend int i_s_metadata_lock_info_fill_row(MDL_ticket*, void*); + friend int i_s_metadata_lock_info_fill_row(MDL_ticket*, void*, bool); #ifndef DBUG_OFF public: /** From bb6990a5d1ea99c89088f501afe2ac50f2d4f4ed Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 15:36:06 +1100 Subject: [PATCH 04/10] IPO - disable connect --- storage/connect/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 31f7d2eb9e51b..a84ff98b292c8 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -413,6 +413,8 @@ IF(NOT TARGET connect) RETURN() ENDIF() +SET_TARGET_PROPERTIES(connect PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + IF(MSVC AND (CMAKE_CXX_FLAGS MATCHES "/MP")) # domdoc.cpp uses compiler directive #import which is not compatible # with the /MP option, resulting in compiler error C2813. From 0c0e15baae1ec67e84a21f897970b6ef2750acaf Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 15:39:26 +1100 Subject: [PATCH 05/10] disable IPO on unit tests --- cmake/ctest.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/ctest.cmake b/cmake/ctest.cmake index 5bc1ce5f8320d..03ead796ea0ed 100644 --- a/cmake/ctest.cmake +++ b/cmake/ctest.cmake @@ -17,6 +17,7 @@ MACRO(MY_ADD_TESTS) FOREACH(name ${ARG_UNPARSED_ARGUMENTS}) ADD_EXECUTABLE(${name}-t "${name}-t.${ARG_EXT}") + SET_TARGET_PROPERTIES(${name}-t PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) TARGET_LINK_LIBRARIES(${name}-t mytap ${ARG_LINK_LIBRARIES}) MY_ADD_TEST(${name}) ENDFOREACH() From 2d53ad1538730dc5fb976e605d088f76c499ae46 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 15:55:18 +1100 Subject: [PATCH 06/10] pfs: unit compliant with ODR --- storage/perfschema/unittest/pfs_server_stubs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/perfschema/unittest/pfs_server_stubs.cc b/storage/perfschema/unittest/pfs_server_stubs.cc index 1ec84c2538efb..82b0ad3b18c30 100644 --- a/storage/perfschema/unittest/pfs_server_stubs.cc +++ b/storage/perfschema/unittest/pfs_server_stubs.cc @@ -50,7 +50,7 @@ void sql_print_warning(const char *format, ...) /* Do not pollute the unit test output with annoying messages. */ } -class sys_var { public: enum where { AUTO }; }; +class sys_var { public: enum where { CONFIG, COMMAND_LINE, AUTO, SQL, COMPILE_TIME, ENV }; }; void set_sys_var_value_origin(void *, enum sys_var::where, const char *) { } From db2cab497c3ef9ced98d5f6d4c3a44fab4b485cc Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 16:15:04 +1100 Subject: [PATCH 07/10] IPO disable for test_sql_discovery --- storage/test_sql_discovery/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/storage/test_sql_discovery/CMakeLists.txt b/storage/test_sql_discovery/CMakeLists.txt index 2039b08123c54..4eff5383a085a 100644 --- a/storage/test_sql_discovery/CMakeLists.txt +++ b/storage/test_sql_discovery/CMakeLists.txt @@ -1,2 +1,6 @@ MYSQL_ADD_PLUGIN(test_sql_discovery test_sql_discovery.cc STORAGE_ENGINE COMPONENT Test) + +# missing symbols needs to be defined as extern? +SET_TARGET_PROPERTIES(test_sql_discovery PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + From e7ef965665f4e312af1f4c283c34a54addb4622e Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 16:18:24 +1100 Subject: [PATCH 08/10] IPO disable metadata_lock_info --- plugin/metadata_lock_info/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/metadata_lock_info/CMakeLists.txt b/plugin/metadata_lock_info/CMakeLists.txt index 6b1f5108bf18d..842f0df711450 100644 --- a/plugin/metadata_lock_info/CMakeLists.txt +++ b/plugin/metadata_lock_info/CMakeLists.txt @@ -1,3 +1,6 @@ SET(METADATA_LOCK_INFO_SOURCES metadata_lock_info.cc) MYSQL_ADD_PLUGIN(metadata_lock_info ${METADATA_LOCK_INFO_SOURCES} RECOMPILE_FOR_EMBEDDED) + +# mdl elements need extern defination +SET_TARGET_PROPERTIES(metadata_lock_info PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) From 53dd17d0aabdfc9c9c4cc907328eda88c0049381 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 16:20:59 +1100 Subject: [PATCH 09/10] IPO disable for archive and example --- storage/archive/CMakeLists.txt | 4 ++++ storage/example/CMakeLists.txt | 3 +++ 2 files changed, 7 insertions(+) diff --git a/storage/archive/CMakeLists.txt b/storage/archive/CMakeLists.txt index 5c7b6aa4aab19..f7a88ffb10a77 100644 --- a/storage/archive/CMakeLists.txt +++ b/storage/archive/CMakeLists.txt @@ -16,3 +16,7 @@ SET(ARCHIVE_SOURCES azio.c ha_archive.cc ha_archive.h) MYSQL_ADD_PLUGIN(archive ${ARCHIVE_SOURCES} STORAGE_ENGINE LINK_LIBRARIES ${ZLIB_LIBRARIES}) + + +# Unresolved symbols need be extern +SET_TARGET_PROPERTIES(archive PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) diff --git a/storage/example/CMakeLists.txt b/storage/example/CMakeLists.txt index 5b59d1b1118db..4414decc243f6 100644 --- a/storage/example/CMakeLists.txt +++ b/storage/example/CMakeLists.txt @@ -15,3 +15,6 @@ SET(EXAMPLE_SOURCES ha_example.cc) MYSQL_ADD_PLUGIN(example ${EXAMPLE_SOURCES} STORAGE_ENGINE MODULE_ONLY COMPONENT Test) + +# Unresolved symbols need be extern - same list as ha_test_sql_discover +SET_TARGET_PROPERTIES(example PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) From 247daf1879014d25fe015bebd795cd0b578b17c4 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 18 Oct 2024 16:21:15 +1100 Subject: [PATCH 10/10] string-t -missing definations for IPO --- unittest/strings/strings-t.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unittest/strings/strings-t.c b/unittest/strings/strings-t.c index 0e3b97c261c5a..5859e11021e0a 100644 --- a/unittest/strings/strings-t.c +++ b/unittest/strings/strings-t.c @@ -1545,6 +1545,9 @@ test_strnncollsp_char() return failed; } +static void my_init() {}; +static int my_end(int infoflag) { return 0; }; +static const char *my_progname= NULL; int main(int ac, char **av) {