DetectBrokenStackCheckMacOSXcodePairing.cmake 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Ceres Solver - A fast non-linear least squares minimizer
  2. # Copyright 2019 Google Inc. All rights reserved.
  3. # http://ceres-solver.org/
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. # * Redistributions of source code must retain the above copyright notice,
  9. # this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright notice,
  11. # this list of conditions and the following disclaimer in the documentation
  12. # and/or other materials provided with the distribution.
  13. # * Neither the name of Google Inc. nor the names of its contributors may be
  14. # used to endorse or promote products derived from this software without
  15. # specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. # POSSIBILITY OF SUCH DAMAGE.
  28. #
  29. # Author: alexs.mac@gmail.com (Alex Stewart)
  30. # As detailed in [1] the combination of macOS 10.15.x (Catalina) and
  31. # Xcode 11.0-1 enables by default a broken version of -fstack-check which
  32. # can break the alignment requirements for SIMD instructions resulting in
  33. # segfaults from within Eigen. This issue was apparently fixed in Xcode 11.2
  34. # despite not appearing in the official release notes.
  35. #
  36. # Although this can be worked around by compiling with -fno-stack-check, we
  37. # instead prevent generation as the update to Xcode 11.2 is free and failing
  38. # to include -fno-stack-check *everywhere* could still result in random
  39. # segfaults.
  40. #
  41. # [1]: https://forums.developer.apple.com/thread/121887
  42. function(detect_broken_stack_check_macos_xcode_pairing)
  43. if (NOT APPLE)
  44. return()
  45. endif()
  46. execute_process(COMMAND sw_vers -productVersion
  47. OUTPUT_VARIABLE MACOS_VERSION
  48. ERROR_QUIET
  49. OUTPUT_STRIP_TRAILING_WHITESPACE)
  50. if (MACOS_VERSION VERSION_LESS 10.15)
  51. # Only 10.15 (Catalina) is likely to be affected, irrespective of the Xcode
  52. # version. Although it is possible to recreate the issue on 10.14 (Mojave)
  53. # and Xcode 11.0-1 if -fstack-check is forced on, this is not the default.
  54. return()
  55. endif()
  56. execute_process(COMMAND xcodebuild -version
  57. OUTPUT_VARIABLE XCODE_VERSION
  58. ERROR_QUIET
  59. OUTPUT_STRIP_TRAILING_WHITESPACE)
  60. string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}")
  61. string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}")
  62. if ((XCODE_VERSION VERSION_EQUAL 11.0) OR
  63. (XCODE_VERSION VERSION_EQUAL 11.1))
  64. message(FATAL_ERROR "Detected macOS version: ${MACOS_VERSION} and "
  65. "Xcode version: ${XCODE_VERSION} which combined exhibit an "
  66. "-fstack-check bug which can break alignment requirements for at least "
  67. "AVX instructions as detailed here [1]."
  68. "\n"
  69. "This bug affected Xcode 11.0 and 11.1 but only when used with 10.15 "
  70. "(Catalina), and was fixed in Xcode 11.2. Without the fix in place, "
  71. "random segfaults will occur in Eigen operations used by Ceres that use "
  72. "AVX instructions."
  73. "\n"
  74. "Please update to at least Xcode 11.2."
  75. "\n"
  76. "[1]: https://forums.developer.apple.com/thread/121887")
  77. endif()
  78. endfunction()