Commit cbcf45fc authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

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.
parent 86e3cbe2
...@@ -83,16 +83,30 @@ MACRO (DTRACE_INSTRUMENT target) ...@@ -83,16 +83,30 @@ MACRO (DTRACE_INSTRUMENT target)
-DOUTFILE=${outfile} -DOUTFILE=${outfile}
-DDFILE=${CMAKE_BINARY_DIR}/include/probes_mysql.d -DDFILE=${CMAKE_BINARY_DIR}/include/probes_mysql.d
-DDTRACE_FLAGS=${DTRACE_FLAGS} -DDTRACE_FLAGS=${DTRACE_FLAGS}
-DDIRS=.
-P ${CMAKE_SOURCE_DIR}/cmake/dtrace_prelink.cmake -P ${CMAKE_SOURCE_DIR}/cmake/dtrace_prelink.cmake
WORKING_DIRECTORY ${objdir} WORKING_DIRECTORY ${objdir}
) )
GET_TARGET_PROPERTY(target_link_flags ${target} LINK_FLAGS) # Add full object path to linker flags
IF(NOT target_link_flags) GET_TARGET_PROPERTY(target_type ${target} TYPE)
SET(target_link_flags) 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() ENDIF()
SET_TARGET_PROPERTIES(${target} PROPERTIES LINK_FLAGS
"${target_link_flags} ${outfile}")
ENDIF() ENDIF()
ENDIF() ENDIF()
ENDMACRO() ENDMACRO()
...@@ -19,13 +19,14 @@ ...@@ -19,13 +19,14 @@
# Do not follow symlinks in GLOB_RECURSE # Do not follow symlinks in GLOB_RECURSE
CMAKE_POLICY(SET CMP0009 NEW) CMAKE_POLICY(SET CMP0009 NEW)
FILE(GLOB_RECURSE OBJECTS *.o) FOREACH(dir ${DIRS})
FILE(GLOB_RECURSE OBJECTS ${dir}/*.o)
# Use relative paths to generate shorter command line # Use relative paths to generate shorter command line
GET_FILENAME_COMPONENT(CURRENT_ABS_DIR . ABSOLUTE) GET_FILENAME_COMPONENT(CURRENT_ABS_DIR . ABSOLUTE)
FOREACH(OBJ ${OBJECTS}) FOREACH(OBJ ${OBJECTS})
FILE(RELATIVE_PATH REL ${CURRENT_ABS_DIR} ${OBJ}) FILE(RELATIVE_PATH REL ${CURRENT_ABS_DIR} ${OBJ})
LIST(APPEND REL_OBJECTS ${REL}) LIST(APPEND REL_OBJECTS ${REL})
ENDFOREACH()
ENDFOREACH() ENDFOREACH()
EXECUTE_PROCESS( EXECUTE_PROCESS(
......
...@@ -43,7 +43,6 @@ IF(SSL_DEFINES) ...@@ -43,7 +43,6 @@ IF(SSL_DEFINES)
ENDIF() ENDIF()
SET (SQL_SOURCE SET (SQL_SOURCE
../sql-common/client.c derror.cc des_key_file.cc ../sql-common/client.c derror.cc des_key_file.cc
discover.cc ../libmysql/errmsg.c field.cc field_conv.cc discover.cc ../libmysql/errmsg.c field.cc field_conv.cc
...@@ -85,22 +84,55 @@ SET (SQL_SOURCE ...@@ -85,22 +84,55 @@ SET (SQL_SOURCE
MYSQL_ADD_PLUGIN(partition ha_partition.cc STORAGE_ENGINE DEFAULT STATIC_ONLY) 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) IF(WIN32)
SET(SQL_SOURCE ${SQL_SOURCE} nt_servc.cc nt_servc.h) SET(MYSQLD_SOURCE main.cc 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)
ELSE() ELSE()
ADD_EXECUTABLE(mysqld ${SQL_SOURCE}) SET(MYSQLD_SOURCE main.cc ${DTRACE_PROBES_ALL})
DTRACE_INSTRUMENT(mysqld) ENDIF()
ENDIF()
ADD_EXECUTABLE(mysqld ${MYSQLD_SOURCE})
IF(NOT WITHOUT_DYNAMIC_PLUGINS) IF(NOT WITHOUT_DYNAMIC_PLUGINS)
SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE)
...@@ -128,11 +160,7 @@ ENDIF() ...@@ -128,11 +160,7 @@ ENDIF()
SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE)
SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX}) SET_TARGET_PROPERTIES(mysqld PROPERTIES OUTPUT_NAME mysqld${MYSQLD_EXE_SUFFIX})
TARGET_LINK_LIBRARIES(mysqld ${MYSQLD_STATIC_PLUGIN_LIBS} TARGET_LINK_LIBRARIES(mysqld sql)
mysys dbug strings vio regex ${SQL_LIB}
${LIBWRAP} ${LIBCRYPT} ${LIBDL}
${ZLIB_LIBRARY} ${SSL_LIBRARIES})
# Provide plugins with minimal set of libraries # Provide plugins with minimal set of libraries
SET(INTERFACE_LIBS ${LIBRT}) SET(INTERFACE_LIBS ${LIBRT})
IF(INTERFACE_LIBS) IF(INTERFACE_LIBS)
......
...@@ -123,7 +123,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ ...@@ -123,7 +123,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
net_serv.cc protocol.cc sql_state.c \ net_serv.cc protocol.cc sql_state.c \
lock.cc my_lock.c \ lock.cc my_lock.c \
sql_string.cc sql_manager.cc sql_map.cc \ 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 \ sql_connect.cc scheduler.cc sql_parse.cc \
set_var.cc sql_yacc.yy \ set_var.cc sql_yacc.yy \
sql_base.cc table.cc sql_select.cc sql_insert.cc \ sql_base.cc table.cc sql_select.cc sql_insert.cc \
......
/* 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);
}
...@@ -4309,7 +4309,7 @@ static void test_lc_time_sz() ...@@ -4309,7 +4309,7 @@ static void test_lc_time_sz()
#ifdef __WIN__ #ifdef __WIN__
int win_main(int argc, char **argv) int win_main(int argc, char **argv)
#else #else
int main(int argc, char **argv) int mysqld_main(int argc, char **argv)
#endif #endif
{ {
MY_INIT(argv[0]); // init my_sys library & pthreads MY_INIT(argv[0]); // init my_sys library & pthreads
...@@ -4699,7 +4699,7 @@ default_service_handling(char **argv, ...@@ -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 When several instances are running on the same machine, we
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment