Score:1

nvcc/gcc broken in Ubuntu 20.04/21.04: how to patch gcc (installed via apt)?

mt flag

Question: What is the step-by-step solution to apply a gcc patch, in particular when it is installed via apt? (I want to apply the one mentioned here)

I tried following multiple guides on how to patch gcc, but they either rely on that gcc was installed via source, or via git. Furthermore, for less experienced users, it is extremely confusing WHAT the patch is/which file it is/how it looks like, how to obtain it from the bug report, and how to apply it. When following the steps outlined in guides, I either get an error that the downloaded patch cannot be parsed correctly, or nothing seems to happen. Is this the patch?

Background: There is a bug in gcc 10.3: "Compiler crashes with segmentation fault on a chrono library using nvcc" (see error message below). The patch mentioned in the bug report is not included in the version that comes with apt. Therefore, Ubuntu 20.04 (possibly 21.04, as well as other Linux distros) ship with the broken version, such that CUDA code cannot be compiled. Note that the bug is supposed to be fixed in gcc 11, but this seems unsupported by CUDA.

Error message:

/usr/include/c++/10/chrono: In substitution of ‘template<class _Rep, class _Period> template<class _Period2> using __is_harmonic = std::__bool_constant<(std::ratio<((_Period2::num / std::chrono::duration<_Rep, _Period>::_S_gcd(_Period2::num, _Period::num)) * (_Period::den / std::chrono::duration<_Rep, _Period>::_S_gcd(_Period2::den, _Period::den))), ((_Period2::den / std::chrono::duration<_Rep, _Period>::_S_gcd(_Period2::den, _Period::den)) * (_Period::num / std::chrono::duration<_Rep, _Period>::_S_gcd(_Period2::num, _Period::num)))>::den == 1)> [with _Period2 = _Period2; _Rep = _Rep; _Period = _Period]’:
/usr/include/c++/10/chrono:473:154:   required from here
/usr/include/c++/10/chrono:428:27: internal compiler error: Segmentation fault
  428 |  _S_gcd(intmax_t __m, intmax_t __n) noexcept
      |                           ^~~~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.
ninja: build stopped: subcommand failed.

What I tried so far:

  • completely purging everything Nvidia/CUDA related and reinstalling (I tried CUDA versions 11.2, 11.3, 11.4)
  • upgrading to gcc-11 g++-11, but this seems unsupported by CUDA
  • patching gcc, but I either failed or this does not seem to do anything
  • downgrading to gcc-9 solves the issue, but is not a long-term solution in my opinion

Related:

cc flag
Wouldn't downgrading to 10.2 solve the issue also?
mt flag
@ubfan1 yes I believe you are right. I didn't find an easy way of doing this though, at least not with apt since I can only choose "gcc-10", not the subverison.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.