You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

389 lines
13 KiB

19 years ago
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled Essentially, the problem is that safemalloc is excruciatingly slow as it checks all allocated blocks for overrun at each memory management primitive, yielding a almost exponential slowdown for the memory management functions (malloc, realloc, free). The overrun check basically consists of verifying some bytes of a block for certain magic keys, which catches some simple forms of overrun. Another minor problem is violation of aliasing rules and that its own internal list of blocks is prone to corruption. Another issue with safemalloc is rather the maintenance cost as the tool has a significant impact on the server code. Given the magnitude of memory debuggers available nowadays, especially those that are provided with the platform malloc implementation, maintenance of a in-house and largely obsolete memory debugger becomes a burden that is not worth the effort due to its slowness and lack of support for detecting more common forms of heap corruption. Since there are third-party tools that can provide the same functionality at a lower or comparable performance cost, the solution is to simply remove safemalloc. Third-party tools can provide the same functionality at a lower or comparable performance cost. The removal of safemalloc also allows a simplification of the malloc wrappers, removing quite a bit of kludge: redefinition of my_malloc, my_free and the removal of the unused second argument of my_free. Since free() always check whether the supplied pointer is null, redudant checks are also removed. Also, this patch adds unit testing for my_malloc and moves my_realloc implementation into the same file as the other memory allocation primitives.
16 years ago
19 years ago
  1. # Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; version 2 of the License.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
  16. # Avoid warnings in higher versions
  17. if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 2.6)
  18. CMAKE_POLICY(VERSION 2.8)
  19. endif()
  20. SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
  21. # First, decide about build type (debug or release)
  22. # If custom compiler flags are set or cmake is invoked with -DCMAKE_BUILD_TYPE,
  23. # respect user wishes and do not (re)define CMAKE_BUILD_TYPE. If WITH_DEBUG{_FULL}
  24. # is given, set CMAKE_BUILD_TYPE = Debug. Otherwise, use Relwithdebinfo.
  25. IF(DEFINED CMAKE_BUILD_TYPE)
  26. SET(HAVE_CMAKE_BUILD_TYPE TRUE)
  27. ENDIF()
  28. SET(CUSTOM_C_FLAGS $ENV{CFLAGS})
  29. OPTION(WITH_DEBUG "Use dbug/safemutex" OFF)
  30. # Distinguish between community and non-community builds, with the
  31. # default being a community build. This does not impact the feature
  32. # set that will be compiled in; it's merely provided as a hint to
  33. # custom packaging steps.
  34. OPTION(COMMUNITY_BUILD "Set to true if this is a community build" ON)
  35. # Use a default manufacturer if no manufacturer was identified.
  36. SET(MANUFACTURER_DOCSTRING
  37. "Set the entity that appears as the manufacturer of packages that support a manufacturer field.")
  38. IF(NOT DEFINED MANUFACTURER)
  39. SET(MANUFACTURER "Built from Source" CACHE STRING ${MANUFACTURER_DOCSTRING})
  40. MARK_AS_ADVANCED(MANUFACTURER)
  41. ENDIF()
  42. # We choose to provide WITH_DEBUG as alias to standard CMAKE_BUILD_TYPE=Debug
  43. # which turns out to be not trivial, as this involves synchronization
  44. # between CMAKE_BUILD_TYPE and WITH_DEBUG. Besides, we have to deal with cases
  45. # where WITH_DEBUG is reset from ON to OFF and here we need to reset
  46. # CMAKE_BUILD_TYPE to either none or default RelWithDebInfo
  47. SET(BUILDTYPE_DOCSTRING
  48. "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
  49. CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel")
  50. IF(WITH_DEBUG)
  51. SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
  52. SET(MYSQL_MAINTAINER_MODE ON CACHE BOOL
  53. "MySQL maintainer-specific development environment")
  54. IF(UNIX AND NOT APPLE)
  55. # Compiling with PIC speeds up embedded build, on PIC sensitive systems
  56. # Predefine it to ON, in case user chooses to build embedded.
  57. SET(WITH_PIC ON CACHE BOOL "Compile with PIC")
  58. ENDIF()
  59. SET(OLD_WITH_DEBUG 1 CACHE INTERNAL "" FORCE)
  60. ELSEIF(NOT HAVE_CMAKE_BUILD_TYPE OR OLD_WITH_DEBUG)
  61. IF(CUSTOM_C_FLAGS)
  62. SET(CMAKE_BUILD_TYPE "" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
  63. ELSE(CMAKE_BUILD_TYPE MATCHES "Debug" OR NOT HAVE_CMAKE_BUILD_TYPE)
  64. SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
  65. ${BUILDTYPE_DOCSTRING} FORCE)
  66. ENDIF()
  67. SET(OLD_WITH_DEBUG 0 CACHE INTERNAL "" FORCE)
  68. ENDIF()
  69. PROJECT(MySQL)
  70. IF(BUILD_CONFIG)
  71. INCLUDE(
  72. ${CMAKE_SOURCE_DIR}/cmake/build_configurations/${BUILD_CONFIG}.cmake)
  73. ENDIF()
  74. # Include the platform-specific file. To allow exceptions, this code
  75. # looks for files in order of how specific they are. If there is, for
  76. # example, a generic Linux.cmake and a version-specific
  77. # Linux-2.6.28-11-generic, it will pick Linux-2.6.28-11-generic and
  78. # include it. It is then up to the file writer to include the generic
  79. # version if necessary.
  80. FOREACH(_base
  81. ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}-${CMAKE_SYSTEM_PROCESSOR}
  82. ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}
  83. ${CMAKE_SYSTEM_NAME})
  84. SET(_file ${CMAKE_SOURCE_DIR}/cmake/os/${_base}.cmake)
  85. IF(EXISTS ${_file})
  86. INCLUDE(${_file})
  87. BREAK()
  88. ENDIF()
  89. ENDFOREACH()
  90. # Following autotools tradition, add preprocessor definitions
  91. # specified in environment variable CPPFLAGS
  92. IF(DEFINED ENV{CPPFLAGS})
  93. ADD_DEFINITIONS($ENV{CPPFLAGS})
  94. ENDIF()
  95. #
  96. # Control aspects of the development environment which are
  97. # specific to MySQL maintainers and developers.
  98. #
  99. INCLUDE(maintainer)
  100. OPTION(MYSQL_MAINTAINER_MODE
  101. "MySQL maintainer-specific development environment" OFF)
  102. # Whether the maintainer mode compiler options should be enabled.
  103. IF(MYSQL_MAINTAINER_MODE)
  104. IF(CMAKE_C_COMPILER_ID MATCHES "GNU")
  105. SET_MYSQL_MAINTAINER_GNU_C_OPTIONS()
  106. ENDIF()
  107. IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  108. SET_MYSQL_MAINTAINER_GNU_CXX_OPTIONS()
  109. ENDIF()
  110. IF(CMAKE_C_COMPILER_ID MATCHES "Intel")
  111. SET_MYSQL_MAINTAINER_INTEL_C_OPTIONS()
  112. ENDIF()
  113. IF(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
  114. SET_MYSQL_MAINTAINER_INTEL_CXX_OPTIONS()
  115. ENDIF()
  116. ENDIF()
  117. # Add macros
  118. INCLUDE(character_sets)
  119. INCLUDE(zlib)
  120. INCLUDE(ssl)
  121. INCLUDE(readline)
  122. INCLUDE(mysql_version)
  123. INCLUDE(libutils)
  124. INCLUDE(dtrace)
  125. INCLUDE(plugin)
  126. INCLUDE(install_macros)
  127. INCLUDE(install_layout)
  128. INCLUDE(mysql_add_executable)
  129. # Handle options
  130. OPTION(DISABLE_SHARED
  131. "Don't build shared libraries, compile code as position-dependent" OFF)
  132. IF(DISABLE_SHARED)
  133. SET(WITHOUT_DYNAMIC_PLUGINS 1)
  134. ENDIF()
  135. OPTION(ENABLED_PROFILING "Enable profiling" ON)
  136. OPTION(CYBOZU "" OFF)
  137. OPTION(BACKUP_TEST "" OFF)
  138. OPTION(WITHOUT_SERVER OFF)
  139. IF(UNIX)
  140. OPTION(WITH_VALGRIND "Valgrind instrumentation" OFF)
  141. ENDIF()
  142. OPTION (WITH_UNIT_TESTS "Compile MySQL with unit tests" ON)
  143. MARK_AS_ADVANCED(CYBOZU BACKUP_TEST WITHOUT_SERVER DISABLE_SHARED)
  144. OPTION(ENABLE_DEBUG_SYNC "Enable debug sync (debug builds only)" ON)
  145. IF(ENABLE_DEBUG_SYNC)
  146. SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLED_DEBUG_SYNC")
  147. SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DENABLED_DEBUG_SYNC")
  148. ENDIF()
  149. OPTION(ENABLE_GCOV "Enable gcov (debug, Linux builds only)" OFF)
  150. IF (ENABLE_GCOV AND NOT WIN32 AND NOT APPLE)
  151. SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
  152. SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
  153. SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov")
  154. ENDIF()
  155. OPTION(ENABLED_LOCAL_INFILE
  156. "If we should should enable LOAD DATA LOCAL by default" ${IF_WIN})
  157. MARK_AS_ADVANCED(ENABLED_LOCAL_INFILE)
  158. OPTION(WITH_FAST_MUTEXES "Compile with fast mutexes" OFF)
  159. MARK_AS_ADVANCED(WITH_FAST_MUTEXES)
  160. # Set DBUG_OFF and other optional release-only flags for non-debug project types
  161. FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL)
  162. FOREACH(LANG C CXX)
  163. SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE}
  164. "${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DDBUG_OFF")
  165. IF(WITH_FAST_MUTEXES)
  166. SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE}
  167. "${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DMY_PTHREAD_FASTMUTEX=1")
  168. ENDIF()
  169. ENDFOREACH()
  170. ENDFOREACH()
  171. IF(NOT CMAKE_BUILD_TYPE
  172. AND NOT CMAKE_GENERATOR MATCHES "Visual Studio"
  173. AND NOT CMAKE_GENERATOR MATCHES "Xcode")
  174. # This is the case of no CMAKE_BUILD_TYPE choosen, typical for VS and Xcode
  175. # or if custom C flags are set. In VS and Xcode for non-Debug configurations
  176. # DBUG_OFF is already correctly set. Use DBUG_OFF for Makefile based projects
  177. # without build type too, unless user specifically requests DBUG.
  178. IF(NOT CMAKE_C_FLAGS MATCHES "-DDBUG_ON")
  179. ADD_DEFINITIONS(-DDBUG_OFF)
  180. ENDIF()
  181. ENDIF()
  182. # Add safemutex for debug configurations, except on Windows
  183. # (safemutex has never worked on Windows)
  184. IF(WITH_DEBUG AND NOT WIN32)
  185. FOREACH(LANG C CXX)
  186. SET(CMAKE_${LANG}_FLAGS_DEBUG
  187. "${CMAKE_${LANG}_FLAGS_DEBUG} -DSAFE_MUTEX")
  188. ENDFOREACH()
  189. ENDIF()
  190. # Set commonly used variables
  191. IF(WIN32)
  192. SET(DEFAULT_MYSQL_HOME "C:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}" )
  193. SET(SHAREDIR share)
  194. ELSE()
  195. SET(DEFAULT_MYSQL_HOME ${CMAKE_INSTALL_PREFIX})
  196. SET(SHAREDIR ${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLSHAREDIR})
  197. ENDIF()
  198. SET(DEFAULT_BASEDIR "${DEFAULT_MYSQL_HOME}")
  199. IF(INSTALL_MYSQLDATADIR MATCHES "^/.*")
  200. SET(MYSQL_DATADIR ${INSTALL_MYSQLDATADIR} CACHE PATH "default MySQL data directory")
  201. ELSE()
  202. SET(MYSQL_DATADIR "${DEFAULT_MYSQL_HOME}/${INSTALL_MYSQLDATADIR}" CACHE PATH "default MySQL data directory")
  203. ENDIF()
  204. SET(DEFAULT_CHARSET_HOME "${DEFAULT_MYSQL_HOME}")
  205. SET(PLUGINDIR "${DEFAULT_MYSQL_HOME}/${INSTALL_PLUGINDIR}")
  206. IF(SYSCONFDIR)
  207. SET(DEFAULT_SYSCONFDIR "${SYSCONFDIR}")
  208. ENDIF()
  209. # Run platform tests
  210. INCLUDE(configure.cmake)
  211. # Common defines and includes
  212. ADD_DEFINITIONS(-DHAVE_CONFIG_H)
  213. INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include)
  214. # Add bundled or system zlib.
  215. MYSQL_CHECK_ZLIB_WITH_COMPRESS()
  216. # Optionally add bundled yassl/taocrypt or system openssl.
  217. MYSQL_CHECK_SSL()
  218. # Add readline or libedit.
  219. MYSQL_CHECK_READLINE()
  220. #
  221. # Setup maintainer mode options by the end. Platform checks are
  222. # not run with the warning options as to not perturb fragile checks
  223. # (i.e. do not make warnings into errors).
  224. #
  225. IF(MYSQL_MAINTAINER_MODE)
  226. # Set compiler flags required under maintainer mode.
  227. MESSAGE(STATUS "C warning options: ${MY_MAINTAINER_C_WARNINGS}")
  228. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_MAINTAINER_C_WARNINGS}")
  229. MESSAGE(STATUS "C++ warning options: ${MY_MAINTAINER_CXX_WARNINGS}")
  230. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_MAINTAINER_CXX_WARNINGS}")
  231. ENDIF()
  232. IF(NOT WITHOUT_SERVER)
  233. SET (MYSQLD_STATIC_PLUGIN_LIBS "" CACHE INTERNAL "")
  234. # Add storage engines and plugins.
  235. CONFIGURE_PLUGINS()
  236. ENDIF()
  237. ADD_SUBDIRECTORY(include)
  238. ADD_SUBDIRECTORY(dbug)
  239. ADD_SUBDIRECTORY(strings)
  240. ADD_SUBDIRECTORY(vio)
  241. ADD_SUBDIRECTORY(regex)
  242. ADD_SUBDIRECTORY(mysys)
  243. ADD_SUBDIRECTORY(libmysql)
  244. IF(WITH_UNIT_TESTS)
  245. ENABLE_TESTING()
  246. ENDIF()
  247. IF(WITH_UNIT_TESTS)
  248. ADD_SUBDIRECTORY(unittest/mytap)
  249. ADD_SUBDIRECTORY(unittest/mysys)
  250. ENDIF()
  251. ADD_SUBDIRECTORY(extra)
  252. IF(NOT WITHOUT_SERVER)
  253. ADD_SUBDIRECTORY(tests)
  254. ADD_SUBDIRECTORY(client)
  255. ADD_SUBDIRECTORY(sql)
  256. ADD_SUBDIRECTORY(sql/share)
  257. ADD_SUBDIRECTORY(libservices)
  258. OPTION (WITH_EMBEDDED_SERVER "Compile MySQL with embedded server" OFF)
  259. IF(WITH_EMBEDDED_SERVER)
  260. ADD_SUBDIRECTORY(libmysqld)
  261. ADD_SUBDIRECTORY(libmysqld/examples)
  262. ENDIF(WITH_EMBEDDED_SERVER)
  263. ADD_SUBDIRECTORY(mysql-test)
  264. ADD_SUBDIRECTORY(mysql-test/lib/My/SafeProcess)
  265. ADD_SUBDIRECTORY(support-files)
  266. ADD_SUBDIRECTORY(scripts)
  267. ADD_SUBDIRECTORY(sql-bench)
  268. IF(UNIX)
  269. ADD_SUBDIRECTORY(man)
  270. ENDIF()
  271. ENDIF()
  272. INCLUDE(cmake/abi_check.cmake)
  273. INCLUDE(cmake/tags.cmake)
  274. CONFIGURE_FILE(config.h.cmake ${CMAKE_BINARY_DIR}/include/my_config.h)
  275. CONFIGURE_FILE(config.h.cmake ${CMAKE_BINARY_DIR}/include/config.h)
  276. CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/include/mysql_version.h.in
  277. ${CMAKE_BINARY_DIR}/include/mysql_version.h )
  278. CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in
  279. ${CMAKE_BINARY_DIR}/sql/sql_builtin.cc)
  280. CONFIGURE_FILE(
  281. ${CMAKE_SOURCE_DIR}/cmake/info_macros.cmake.in ${CMAKE_BINARY_DIR}/info_macros.cmake @ONLY)
  282. # Handle the "INFO_*" files.
  283. INCLUDE(${CMAKE_BINARY_DIR}/info_macros.cmake)
  284. # Source: This can be done during the cmake phase, all information is
  285. # available, but should be repeated on each "make" just in case someone
  286. # does "cmake ; make ; bzr pull ; make".
  287. CREATE_INFO_SRC(${CMAKE_BINARY_DIR}/Docs)
  288. ADD_CUSTOM_TARGET(INFO_SRC ALL
  289. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/info_src.cmake
  290. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  291. )
  292. # Build flags: This must be postponed to the make phase.
  293. ADD_CUSTOM_TARGET(INFO_BIN ALL
  294. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/info_bin.cmake
  295. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  296. )
  297. # Packaging
  298. IF(WIN32)
  299. SET(CPACK_GENERATOR "ZIP")
  300. ELSE()
  301. SET(CPACK_GENERATOR "TGZ")
  302. ENDIF()
  303. ADD_SUBDIRECTORY(packaging/WiX)
  304. # Create a single package with "make package"
  305. # (see http://public.kitware.com/Bug/view.php?id=11452)
  306. SET(CPACK_MONOLITHIC_INSTALL 1 CACHE INTERNAL "")
  307. INCLUDE(CPack)
  308. IF(UNIX)
  309. INSTALL(FILES Docs/mysql.info DESTINATION ${INSTALL_INFODIR} OPTIONAL COMPONENT Info)
  310. ENDIF()
  311. #
  312. # RPM installs documentation directly from the source tree
  313. #
  314. IF(NOT INSTALL_LAYOUT MATCHES "RPM")
  315. INSTALL(FILES COPYING LICENSE.mysql
  316. DESTINATION ${INSTALL_DOCREADMEDIR}
  317. COMPONENT Readme
  318. OPTIONAL
  319. )
  320. INSTALL(FILES README DESTINATION ${INSTALL_DOCREADMEDIR} COMPONENT Readme)
  321. INSTALL(FILES ${CMAKE_BINARY_DIR}/Docs/INFO_SRC ${CMAKE_BINARY_DIR}/Docs/INFO_BIN DESTINATION ${INSTALL_DOCDIR})
  322. IF(UNIX)
  323. INSTALL(FILES Docs/INSTALL-BINARY DESTINATION ${INSTALL_DOCREADMEDIR} COMPONENT Readme)
  324. ENDIF()
  325. # MYSQL_DOCS_LOCATON is used in "make dist", points to the documentation directory
  326. SET(MYSQL_DOCS_LOCATION "" CACHE PATH "Location from where documentation is copied")
  327. MARK_AS_ADVANCED(MYSQL_DOCS_LOCATION)
  328. INSTALL(DIRECTORY Docs/ DESTINATION ${INSTALL_DOCDIR}
  329. COMPONENT Documentation
  330. PATTERN "INSTALL-BINARY" EXCLUDE
  331. PATTERN "Makefile.*" EXCLUDE
  332. PATTERN "glibc*" EXCLUDE
  333. PATTERN "linuxthreads.txt" EXCLUDE
  334. PATTERN "myisam.txt" EXCLUDE
  335. PATTERN "mysql.info" EXCLUDE
  336. PATTERN "sp-imp-spec.txt" EXCLUDE
  337. )
  338. ENDIF()