Refactor Boost.Stacktrace detection - #4634
Conversation
Since 8c248be the cmake build has forced the addr2line backend on every platform it supports, because if(UNIX) requested only that component, so the preference chain below it could never reach backtrace. On Ubuntu, where executables are PIE by default, addr2line resolves nothing: the runtime addresses are ASLR-slid relative to the DWARF in the file and boost does not correct for that, so traces from the SIGSEGV handler were bare hex addresses. The autotools build has preferred backtrace all along. Prefer backtrace in both, then fall back to the header-only addr2line implementation, then to boost's default backend. Never link libboost_stacktrace_addr2line: the addr2line path is compiled into that library and defaults to /usr/bin/addr2line, which macOS lacks, while header-only mode gives the same output and lets us point at the program we found. Only header-only mode reads BOOST_STACKTRACE_USE_*, since frame.hpp skips the backend dispatch entirely under BOOST_STACKTRACE_LINK. Drop the macro main.cpp defined unconditionally, where it selected nothing, and set it from the build system in the one case it has an effect. Check for libbacktrace as well as the boost component. Boost's cmake files declare -lbacktrace on the imported target without checking that it is installed, so a missing libbacktrace was a link failure rather than a fallback, and in FindBoost module mode nothing declares it at all. Also drop cmake_policy(SET CMP0167 OLD), which is fatal on the cmake 3.28 in Ubuntu 24.04 and did nothing elsewhere: cmake_policy(VERSION 3.24) already leaves CMP0167 unset, and FindBoost hands off to BoostConfig.cmake anyway. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
check_include_files defaults to the C compiler, which cannot compile this header -- it fails on "algorithm: No such file or directory" -- so HAVE_BOOST_MATH_TOOLS_ATOMIC_HPP was always undefined and Macaulay2/d/boostmath.dd never saw BOOST_MATH_NO_ATOMIC_INT. The autotools build gets this right, since AC_LANG(C++) is in effect there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Claude here (Claude Code) — Doug asked me to write up the details, so this comment is mine, not his. Everything below I verified by running it on his Ubuntu 24.04 box rather than reasoning from the docs; where a claim was only inference I've said so. The actual bug turned out to be worse than a stale policy lineThe Since 8c248be, if(UNIX)
cmake_policy(SET CMP0167 OLD)
find_package(Boost REQUIRED QUIET COMPONENTS regex OPTIONAL_COMPONENTS stacktrace_addr2line)
else()
find_package(Boost REQUIRED QUIET COMPONENTS regex OPTIONAL_COMPONENTS stacktrace_backtrace)
endif()
if(Boost_STACKTRACE_BACKTRACE_FOUND)
...
That matters because addr2line resolves nothing in a PIE executable, and Ubuntu's gcc is
So on the most common Linux platform, a cmake-built M2 was printing bare addresses out of its What the patch doesBoth builds now prefer backtrace, then fall back to the header-only addr2line implementation, then to Boost's default backend. Two findings shaped that and are worth stating because neither is guessable from the diff. 1. 2. Linking 3. libbacktrace is checked as well as the Boost component. Boost's own cmake files do this: set_property(TARGET Boost::stacktrace_backtrace APPEND PROPERTY INTERFACE_LINK_LIBRARIES
backtrace dl)Unconditionally — nothing verifies libbacktrace is installed. So a missing libbacktrace was a hard link failure rather than a graceful fallback. And in true The autotools side never needed this because it link-tests (the test is the check) and because plain On
|
Every time I went to use the cmake build on my Ubuntu 24.04 machine, I had to go comment out that
CMP0167line from #4146 because my cmake was too old.Not a great workflow, so today I finally asked, "Hey Claude, what's up with this?", and it took me down a long rabbit hole about the various ways that we can use Boost.Stacktrace. So what started out as a cmake-only branch turned into a cmake-and-autotools branch so that we end up doing the same thing in both builds.
I'll have Claude comment on the details
🤖 AI Disclosure 🤖
Claude wrote all the code, but I asked a bunch of questions and we ended up trimming down what started out as a bunch of spaghetti code into a pretty nice little patch.