depends: Add a nasty qt hack to work around clang non-determinism #20436

pull theuni wants to merge 1 commits into bitcoin:0.21 from theuni:fix-clang-qt-determinism changing 1 files +2 −1
  1. theuni commented at 8:00 pm on November 20, 2020: member

    PR’ing into 0.21 because I don’t think we want a hack like this in master.

    Clang fixed a determinism bug in the 9.x series: https://github.com/llvm/llvm-project/commit/db101864bdc938deb1d63fe4f7da761bd38e5cae

    It was never backported to 8.x, however. I have manually back-ported the fix to 8.x here in case it’s useful (with Guix, for example): https://github.com/theuni/llvm-project/commit/df4158d8577618c1f728f89ca88aad5eead656a7

    Credit Carl Dong for discovering the determinism problem while working on Guix.

    Clang 8.x emits non-deterministic code, but only with certain compile options enabled (-O2 is fine but -O3 is problematic; I haven’t tracked down the exact guilty flag), and only when compiling very specific code.

    Qt builds with -O3, so we special-case the source file that manages to trigger the bug and force it to -O2. gcc/clang honor the last -O option, so appending is fine.

    I suspect @fanquake will hate the fact that we’re echoing into a generated file. This would be much cleaner if done at the qmake level, but I’m not sure how to do that.

    This is a quick nasty work-around, so here are some other potential options:

    • Bump to clang9 where this is fixed
    • As @dongcarl suggested: rewrite the some of the qt function (qt_intersect_spans in qpaintengine_raster.cpp) to avoid hitting the non-determinism
    • Disable the buggy behavior via cmdline option

    I’ve opted for the last option (Using -O2 as a large hammer), because it was the quickest to write, but the second option would be fine as well. I don’t have much of a preference, this is a huge layer violation either way. :)

    I’d prefer not to bump clang this late in the release process, though.

  2. depends: Add a nasty qt hack to work around clang non-determinism
    Clang fixed a determinism bug in the 9.x series:
    https://github.com/llvm/llvm-project/commit/db101864bdc938deb1d63fe4f7da761bd38e5cae
    
    It was never backported to 8.x, however. I have manually back-ported the fix to
    8.x here:
    https://github.com/theuni/llvm-project/commit/df4158d8577618c1f728f89ca88aad5eead656a7
    
    Credit Carl Dong for discovering the determinism problem while working on Guix.
    
    Clang 8.x emits non-deterministic code, but only with certain compile options
    enabled (-O2 is fine but -O3 is problematic), and only when compiling very
    specific code.
    
    Qt builds with -O3, so we special-case the source file that manages to trigger
    the bug and force it to -O2. gcc/clang honor the _last_ -O option, so appending
    is fine.
    ddec62c26e
  3. jonatack commented at 9:30 pm on November 20, 2020: member
    Concept ACK (in the absence of a nicer-and-reliable-yet-quick alternative).
  4. DrahtBot added the label Backport on Nov 20, 2020
  5. fanquake removed the label Backport on Nov 20, 2020
  6. fanquake added the label Build system on Nov 20, 2020
  7. sipa commented at 10:32 pm on November 20, 2020: member
    Concept ACK. I can’t imagine we’d care about the performance difference of -O3 vs -O2 for one object file inside Qt…
  8. fanquake commented at 3:23 am on November 21, 2020: member

    I suspect @fanquake will hate the fact that we’re echoing into a generated file. This would be much cleaner if done at the qmake level, but I’m not sure how to do that.

    Thanks for the explainer and potential fix. I’m going to propose an alternative using a macOS scoped patch, which should be suiteable to merge into master and backport.

  9. laanwj commented at 9:08 am on November 21, 2020: member

    As I’ve asked on IRC too—O3 has the nasty habit of exposing compiler issues, why not build the whole thing with O2?

    Concept ACK anyhow if this solves the non-determinism issue.

  10. MarcoFalke commented at 12:39 pm on November 21, 2020: member
  11. theuni commented at 2:20 pm on November 21, 2020: member

    @laanwj Depends sets a default of -O2, but some things (qt obviously, boost, recently secp256k1 iirc) override it. We’ve never really tried fighting that, afaik.

    I just wanted to demonstrate the minimal determinism fix here. If you’d prefer to switch the whole thing to -O2, I’d be happy to whip that up instead.

  12. fanquake commented at 6:43 am on November 23, 2020: member
    Thanks for the great detective work, and initial patch. However I’m going to close this in favour of #20447.
  13. fanquake closed this on Nov 23, 2020

  14. fanquake referenced this in commit 31c9987976 on Nov 24, 2020
  15. sidhujag referenced this in commit b5fbf10b7d on Nov 24, 2020
  16. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me