represent c++ abi compatibility by adding "compiler variants" to the spec model #35411
Replies: 4 comments 3 replies
-
Ah, @giordano notes in #28541 (comment) that this is probably best done as part of the compiler-as-dependency work, which makes sense. I would prefer to use that solution instead of specially handling this case. I'll try to find where this fits in to that larger work. |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for capturing this out of slack! ABI compatibility is a pretty big deal and def something I'd appreciate having good tools to control. A feature like this might make spack super attractive to us at $work :) This issue goes a bit deeper than just the CXX11_ABI flag though. GCC has a page noting all the minor tweaks they've made to abi: https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options . These are mostly bug fixes, but it's worth considering what the implications are on packaging tools. i.e. consider this one:
which I can imagine would change behavior of certain UB-laden code. |
Beta Was this translation helpful? Give feedback.
-
This will be handled in the "Compiler as dependencies" project, which is still under development. We have a couple of issues linked to this epic: That show which model we are currently trying to achieve with compilers and runtime libraries. |
Beta Was this translation helpful? Give feedback.
-
Hey @cosmicexplorer / @alalazo. Checking in on ISC I noticed that the spack compiler-as-a-dep has been released! I see notes here: https://github.com/spack/spack/releases/tag/v0.22.0 Does this mean the way to do something like pin the ABI, or pin a certain sanitizer, is to create something like a compiler wrapper that ensures the flag is set, then build everything in a package tree against that special compiler? I don't see a good place in compilers.yaml or packages.yaml to stick these flags |
Beta Was this translation helpful? Give feedback.
-
This discussion proposes the introduction of "compiler variants" as an extension of spec variants. This is motivated by the desire to ensure spack doesn't try to build C++ packages with different values of the glibcxx abi together in the same environment. The necessary changes are detailed in the "work scope" section.
Problem
In response to a separate discussion over Slack, @dpzmick wrote:
When I worked in packaging tensorflow's native libraries at Twitter, I recall vividly how google's python packages were officially documented to have
-D_GLIBCXX_USE_CXX11_ABI=0
, but in practice, specific releases would have=1
, which caused a compile error: see my failed attempt to get them to fix this at tensorflow/tensorflow#27078. This kind of compatibility issue seems like exactly what Spack is supposed to solve.Existing Workarounds
Using
cppflags
Managing
_GLIBCXX_USE_CXX11_ABI
viacppflags
does not ensure compatibility, since spack does not consider it a conflict if one package is built withcppflags=-D_GLIBCXX_USE_CXX11_ABI=0
and its dependency is built withcppflags=-D_GLIBCXX_USE_CXX11_ABI=1
:Package Recipes Hardcoding Flags
I was glad to see that the string
CXX11_ABI
was only found a few times in spack package definitions:However, it's clearly something multiple packages care about, and in the case of
julia
, it appears theMake.inc
file in thejulia
codebase has a special method to obtain_GLIBCXX_USE_CXX11_ABI
from the list of flags (so this value clearly affects how the package is built).Reported Build Failures
When searching "C++ ABI" or "cxx abi" in this repo, I only found #28541, which I couldn't immediately understand, but also appears to be about
gfortran
and C++ ABI compatibility. I'm not sure if this is the same issue, but it seems related.Proposed Solution
Represent C++ ABI configuration as a "compiler variant", and read that config to set appropriate compile flags in the compiler wrapper. This might look something like:
If we tried to do the same thing we did earlier and set different values for the cxx abi in a dependency, spack should error:
Work Scope
This change would require modifying:
spack.spec.Spec
object, to retain a separateVariantMap
for "compiler variants".concretize.lp
, to raise a constraint error when compiler variants do not match.+
or~
variant after a%
as a "compiler variant".spack.compiler.Compiler
object, to accept parameters from "compiler variant" values.cc
wrapper, to inject-D_GLIBCXX_USE_CXX11_ABI={0,1}
into allgcc
compiles depending on the value of thecxx11_abi
compiler variant.Alternatives
Special Variant Name (like
cppflags
)We could instead make
cxx11_abi
into a "special variant name" (likecppflags
) to avoid modifying the spec parser. That could look like:Since
_GLIBCXX_USE_CXX11_ABI
is specific tog++
, I think it would be confusing to allow this "compiler variant" to be set without attaching it to a compiler spec. I think it makes more sense to attach "compiler variants" to compiler specs, but if we want to be cautious about changing the spec syntax, we could do this instead.Separate Compiler Name
We could avoid having to modify the
spack.compiler.Compiler
object to allow parameters if we instead create a copy of thegcc
compiler object namedgcc_cxx11
or something. This would probably require a lot of annoying changes to package recipes to explicitly allow thegcc_cxx11
compiler, so we probably shouldn't do this.Beta Was this translation helpful? Give feedback.
All reactions