Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 1 | # Ceres Solver - A fast non-linear least squares minimizer |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame] | 2 | # Copyright 2023 Google Inc. All rights reserved. |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 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 | |
| 31 | # As detailed in [1] the combination of macOS 10.15.x (Catalina) and |
| 32 | # Xcode 11.0-1 enables by default a broken version of -fstack-check which |
| 33 | # can break the alignment requirements for SIMD instructions resulting in |
| 34 | # segfaults from within Eigen. This issue was apparently fixed in Xcode 11.2 |
| 35 | # despite not appearing in the official release notes. |
| 36 | # |
| 37 | # Although this can be worked around by compiling with -fno-stack-check, we |
| 38 | # instead prevent generation as the update to Xcode 11.2 is free and failing |
| 39 | # to include -fno-stack-check *everywhere* could still result in random |
| 40 | # segfaults. |
| 41 | # |
| 42 | # [1]: https://forums.developer.apple.com/thread/121887 |
| 43 | function(detect_broken_stack_check_macos_xcode_pairing) |
| 44 | if (NOT APPLE) |
| 45 | return() |
| 46 | endif() |
| 47 | |
| 48 | execute_process(COMMAND sw_vers -productVersion |
| 49 | OUTPUT_VARIABLE MACOS_VERSION |
| 50 | ERROR_QUIET |
| 51 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 52 | |
| 53 | if (MACOS_VERSION VERSION_LESS 10.15) |
| 54 | # Only 10.15 (Catalina) is likely to be affected, irrespective of the Xcode |
| 55 | # version. Although it is possible to recreate the issue on 10.14 (Mojave) |
| 56 | # and Xcode 11.0-1 if -fstack-check is forced on, this is not the default. |
| 57 | return() |
| 58 | endif() |
| 59 | |
| 60 | execute_process(COMMAND xcodebuild -version |
| 61 | OUTPUT_VARIABLE XCODE_VERSION |
| 62 | ERROR_QUIET |
| 63 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 64 | string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}") |
| 65 | string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}") |
| 66 | |
| 67 | if ((XCODE_VERSION VERSION_EQUAL 11.0) OR |
| 68 | (XCODE_VERSION VERSION_EQUAL 11.1)) |
| 69 | message(FATAL_ERROR "Detected macOS version: ${MACOS_VERSION} and " |
| 70 | "Xcode version: ${XCODE_VERSION} which combined exhibit an " |
| 71 | "-fstack-check bug which can break alignment requirements for at least " |
| 72 | "AVX instructions as detailed here [1]." |
| 73 | "\n" |
| 74 | "This bug affected Xcode 11.0 and 11.1 but only when used with 10.15 " |
| 75 | "(Catalina), and was fixed in Xcode 11.2. Without the fix in place, " |
| 76 | "random segfaults will occur in Eigen operations used by Ceres that use " |
| 77 | "AVX instructions." |
| 78 | "\n" |
| 79 | "Please update to at least Xcode 11.2." |
| 80 | "\n" |
| 81 | "[1]: https://forums.developer.apple.com/thread/121887") |
| 82 | endif() |
| 83 | endfunction() |