diff options
author | Vladislav Vaintroub <vvaintroub@mysql.com> | 2009-12-11 15:51:39 +0100 |
---|---|---|
committer | Vladislav Vaintroub <vvaintroub@mysql.com> | 2009-12-11 15:51:39 +0100 |
commit | 55ccb35ba66e4e9168c412c95ebbb85106db8b2c (patch) | |
tree | fa038e3ac6dc4935686d55c7c0d764d5b0db0b64 | |
parent | 1ec457961df55720e465a46f5ee340654429bed1 (diff) | |
download | mariadb-git-55ccb35ba66e4e9168c412c95ebbb85106db8b2c.tar.gz |
Introduce a workaround for Solaris' inability to deal with dtrace in static libraries.
Rerun dtrace -G on all objects that can contan dtrace probes (also objects that are
part of static libs) before linking mysqld to produce dtrace_probes_all.o and link
dtrace_probes_all.o with mysqld
This ugly workaround was inspired by handling dtrace using autotools.
-rw-r--r-- | cmake/dtrace.cmake | 26 | ||||
-rw-r--r-- | cmake/dtrace_prelink.cmake | 15 | ||||
-rwxr-xr-x | sql/CMakeLists.txt | 66 | ||||
-rw-r--r-- | sql/Makefile.am | 2 | ||||
-rw-r--r-- | sql/main.cc | 25 | ||||
-rw-r--r-- | sql/mysqld.cc | 4 |
6 files changed, 103 insertions, 35 deletions
diff --git a/cmake/dtrace.cmake b/cmake/dtrace.cmake index 58fbbba022c..960a7aa4c84 100644 --- a/cmake/dtrace.cmake +++ b/cmake/dtrace.cmake @@ -83,16 +83,30 @@ MACRO (DTRACE_INSTRUMENT target) -DOUTFILE=${outfile} -DDFILE=${CMAKE_BINARY_DIR}/include/probes_mysql.d -DDTRACE_FLAGS=${DTRACE_FLAGS} + -DDIRS=. -P ${CMAKE_SOURCE_DIR}/cmake/dtrace_prelink.cmake WORKING_DIRECTORY ${objdir} ) - GET_TARGET_PROPERTY(target_link_flags ${target} LINK_FLAGS) - IF(NOT target_link_flags) - SET(target_link_flags) + # Add full object path to linker flags + GET_TARGET_PROPERTY(target_type ${target} TYPE) + IF(NOT target_type MATCHES "STATIC") + SET_TARGET_PROPERTIES(${target} PROPERTIES LINK_FLAGS "${outfile}") + ELSE() + # For static library flags, add the object to the library. + # Note: DTrace probes in static libraries are unusable currently + # (see http://opensolaris.org/jive/thread.jspa?messageID=432454) + # but maybe one day this will be fixed. + GET_TARGET_PROPERTY(target_location ${target} LOCATION) + ADD_CUSTOM_COMMAND( + TARGET ${target} POST_BUILD + COMMAND ${CMAKE_AR} r ${target_location} ${outfile} + COMMAND ${CMAKE_RANLIB} ${target_location} + ) + + # Remember the object directory (it is used to workaround lack of static + # library support when linking mysqld) + SET(TARGET_OBJECT_DIRECTORY_${target} ${objdir} CACHE INTERNAL "") ENDIF() - - SET_TARGET_PROPERTIES(${target} PROPERTIES LINK_FLAGS - "${target_link_flags} ${outfile}") ENDIF() ENDIF() ENDMACRO() diff --git a/cmake/dtrace_prelink.cmake b/cmake/dtrace_prelink.cmake index 53e12407cb9..ae475a90921 100644 --- a/cmake/dtrace_prelink.cmake +++ b/cmake/dtrace_prelink.cmake @@ -19,13 +19,14 @@ # Do not follow symlinks in GLOB_RECURSE CMAKE_POLICY(SET CMP0009 NEW) -FILE(GLOB_RECURSE OBJECTS *.o) - -# Use relative paths to generate shorter command line -GET_FILENAME_COMPONENT(CURRENT_ABS_DIR . ABSOLUTE) -FOREACH(OBJ ${OBJECTS}) - FILE(RELATIVE_PATH REL ${CURRENT_ABS_DIR} ${OBJ}) - LIST(APPEND REL_OBJECTS ${REL}) +FOREACH(dir ${DIRS}) + FILE(GLOB_RECURSE OBJECTS ${dir}/*.o) + # Use relative paths to generate shorter command line + GET_FILENAME_COMPONENT(CURRENT_ABS_DIR . ABSOLUTE) + FOREACH(OBJ ${OBJECTS}) + FILE(RELATIVE_PATH REL ${CURRENT_ABS_DIR} ${OBJ}) + LIST(APPEND REL_OBJECTS ${REL}) + ENDFOREACH() ENDFOREACH() EXECUTE_PROCESS( diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index d086149831e..92cf55aa4ff 100755 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -43,7 +43,6 @@ IF(SSL_DEFINES) ENDIF() - SET (SQL_SOURCE ../sql-common/client.c derror.cc des_key_file.cc discover.cc ../libmysql/errmsg.c field.cc field_conv.cc @@ -85,22 +84,55 @@ SET (SQL_SOURCE MYSQL_ADD_PLUGIN(partition ha_partition.cc STORAGE_ENGINE DEFAULT STATIC_ONLY) +ADD_LIBRARY(sql STATIC ${SQL_SOURCE}) +DTRACE_INSTRUMENT(sql) +TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS} + mysys dbug strings vio regex + ${LIBWRAP} ${LIBCRYPT} ${LIBDL} + ${SSL_LIBRARIES}) + + + +# Ugly workaround for Solaris' DTrace inability to use probes +# from static libraries currently, discussed e.g in this thread +# (http://opensolaris.org/jive/thread.jspa?messageID=432454) +# We have to collect all object files that may be instrumented +# and go into the mysqld (also those that come from in static libs) +# run them again through dtrace -G to generate an ELF file that links +# to mysqld. +IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND ENABLE_DTRACE) + SET(DTRACE_PROBES_ALL ${CMAKE_CURRENT_BINARY_DIR}/dtrace_probes_all.o) + SET(DTRACED_LIBS sql ${MYSQLD_STATIC_PLUGIN_LIBS} mysys) + FOREACH(lib ${DTRACED_LIBS}) + SET(DTRACE_DIRS ${DTRACE_DIRS} ${TARGET_OBJECT_DIRECTORY_${lib}}) + ENDFOREACH() + + MESSAGE("DTRACE_DIRS=${DTRACE_DIRS}") + ADD_CUSTOM_COMMAND( + OUTPUT ${DTRACE_PROBES_ALL} + DEPENDS ${DTRACED_LIBS} + COMMAND ${CMAKE_COMMAND} + -DDTRACE=${DTRACE} + -DOUTFILE=${DTRACE_PROBES_ALL} + -DDFILE=${CMAKE_BINARY_DIR}/include/probes_mysql.d + -DDTRACE_FLAGS=${DTRACE_FLAGS} + "-DDIRS=${DTRACE_DIRS}" + -P ${CMAKE_SOURCE_DIR}/cmake/dtrace_prelink.cmake + VERBATIM + ) +ELSE() + SET(DTRACE_PROBES_ALL) +ENDIF() + IF(WIN32) - SET(SQL_SOURCE ${SQL_SOURCE} nt_servc.cc nt_servc.h) -ENDIF() -IF(MSVC) - ADD_LIBRARY(sql ${SQL_SOURCE}) - ADD_EXECUTABLE(mysqld mysqld_dummy.cc) - ADD_CUSTOM_COMMAND( - OUTPUT mysqld_dummy.cc - COMMAND cmake ARGS -E touch mysqld_dummy.cc - VERBATIM) - SET(SQL_LIB sql) + SET(MYSQLD_SOURCE main.cc nt_servc.cc nt_servc.h) ELSE() - ADD_EXECUTABLE(mysqld ${SQL_SOURCE}) - DTRACE_INSTRUMENT(mysqld) -ENDIF() + SET(MYSQLD_SOURCE main.cc ${DTRACE_PROBES_ALL}) +ENDIF() + +ADD_EXECUTABLE(mysqld ${MYSQLD_SOURCE}) + IF(NOT WITHOUT_DYNAMIC_PLUGINS) SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) @@ -128,11 +160,7 @@ ENDIF() SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX}) -TARGET_LINK_LIBRARIES(mysqld ${MYSQLD_STATIC_PLUGIN_LIBS} - mysys dbug strings vio regex ${SQL_LIB} - ${LIBWRAP} ${LIBCRYPT} ${LIBDL} - ${ZLIB_LIBRARY} ${SSL_LIBRARIES}) - +TARGET_LINK_LIBRARIES(mysqld sql) # Provide plugins with minimal set of libraries SET(INTERFACE_LIBS ${LIBRT}) IF(INTERFACE_LIBS) diff --git a/sql/Makefile.am b/sql/Makefile.am index 15ee0d588c4..5f5b8de97be 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -123,7 +123,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ net_serv.cc protocol.cc sql_state.c \ lock.cc my_lock.c \ sql_string.cc sql_manager.cc sql_map.cc \ - mysqld.cc password.c hash_filo.cc hostname.cc \ + main.cc mysqld.cc password.c hash_filo.cc hostname.cc \ sql_connect.cc scheduler.cc sql_parse.cc \ set_var.cc sql_yacc.yy \ sql_base.cc table.cc sql_select.cc sql_insert.cc \ diff --git a/sql/main.cc b/sql/main.cc new file mode 100644 index 00000000000..249a2a883fe --- /dev/null +++ b/sql/main.cc @@ -0,0 +1,25 @@ +/* Copyright (C) 2009 Sun Microsystems, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* + main() for mysqld. + Calls mysqld_main() entry point exported by sql library. +*/ +extern int mysqld_main(int argc, char **argv); + +int main(int argc, char **argv) +{ + return mysqld_main(argc, argv); +} diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 30ea646d2fd..e871d46d6a1 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4309,7 +4309,7 @@ static void test_lc_time_sz() #ifdef __WIN__ int win_main(int argc, char **argv) #else -int main(int argc, char **argv) +int mysqld_main(int argc, char **argv) #endif { MY_INIT(argv[0]); // init my_sys library & pthreads @@ -4699,7 +4699,7 @@ default_service_handling(char **argv, } -int main(int argc, char **argv) +int mysqld_main(int argc, char **argv) { /* When several instances are running on the same machine, we |