depends: add new LLVM debug macro #29781

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:llvm_18_hardening_mode changing 1 files +5 −1
  1. fanquake commented at 5:01 pm on April 1, 2024: member

    LIBCXX_HARDENING_MODE is the new macro, the previous one was removed in LLVM 18.

    See https://libcxx.llvm.org/Hardening.html.

    Required before https://github.com/google/oss-fuzz/pull/11725 will do anything (with the bump to 18.x).

    Seems reasonable to do now that almost all our test infra is using LLVM 18.

  2. DrahtBot commented at 5:01 pm on April 1, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK theuni

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. DrahtBot added the label Build system on Apr 1, 2024
  4. theuni commented at 5:39 pm on April 1, 2024: member
    I don’t see any harm in keeping both?
  5. fanquake commented at 5:41 pm on April 1, 2024: member
    IIRC usage was turned into a compile error (maybe only intermittently, will check again).
  6. DrahtBot added the label CI failed on Apr 2, 2024
  7. fanquake force-pushed on Apr 3, 2024
  8. fanquake renamed this:
    depends: switch to new LLVM debug macro
    depends: add new LLVM debug macro
    on Apr 3, 2024
  9. fanquake commented at 10:08 am on April 3, 2024: member

    IIRC usage was turned into a compile error (maybe only intermittently, will check again).

    I think I was thinking of something else here. Have changed this to just adding the new macro.

  10. fanquake marked this as ready for review on Apr 3, 2024
  11. in depends/hosts/linux.mk:20 in 3fb8cb4bf5 outdated
    12@@ -13,7 +13,12 @@ linux_release_CXXFLAGS=$(linux_release_CFLAGS)
    13 linux_debug_CFLAGS=-O1 -g
    14 linux_debug_CXXFLAGS=$(linux_debug_CFLAGS)
    15 
    16-linux_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_LIBCPP_ENABLE_DEBUG_MODE=1
    17+# https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode.html
    18+linux_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
    19+
    20+# https://libcxx.llvm.org/Hardening.html
    21+# _LIBCPP_ENABLE_DEBUG_MODE is the legacy define, it was last used in LLVM 17.
    


    maflcko commented at 5:29 pm on April 3, 2024:

    I have a hard time following what llvm does each release here. Why is https://libcxx.llvm.org/Hardening.html not available as versioned URL per release?

    https://discourse.llvm.org/t/rfc-hardening-in-libc/73925 claims there are no breaking changes in the 18 release. So I wonder if everything can be kept as-is for now, because I suspect no one will be compiling with 19 for now?


    fanquake commented at 5:43 pm on April 3, 2024:

    Why is https://libcxx.llvm.org/Hardening.html not available as versioned URL per release?

    Looks like it’s here: https://releases.llvm.org/18.1.0/projects/libcxx/docs/Hardening.html

    claims there are no breaking changes in the 18 release.

    I’ve also had a hard time following, and I think some of the changes were landed, reverted, and finally re-landed. According too https://releases.llvm.org/18.1.0/projects/libcxx/docs/ReleaseNotes/18.html:

    New hardened modes for the library have been added, replacing the legacy debug mode that was removed in the LLVM 17 release. Unlike the legacy debug mode, some of these hardening modes are also intended to be used in production. See Hardening Modes for more details.


    maflcko commented at 6:10 pm on April 3, 2024:

    Ah, I see. The page may have only been written for the 18 release, or not included in the 17 release for some reason.

    According to commit 4a825039a509c43ba20b2cd7aab448b3be16bcc3, “From LLVM 17, _LIBCPP_ENABLE_DEBUG_MODE can be used instead.” C.f. https://web.archive.org/web/20230815180109/https://libcxx.llvm.org/Hardening.html

    This makes me wonder if it is worth it to support clang 17 debug mode, if clang 14,15, and 16 isn’t supported either.

    It seems fine to require clang 18, if someone want to use clang, depends, and D_LIBCPP_HARDENING_MODE.

    Is there anyone other than OSS-Fuzz and a CI config interested in this?


    fanquake commented at 11:17 am on April 4, 2024:

    It seems fine to require clang 18, if someone want to use clang, depends, and D_LIBCPP_HARDENING_MODE. Is there anyone other than OSS-Fuzz and a CI config interested in this?

    Yea; my main interest is our CIs, fuzzing infra and other external test infra, which is all running LLVM 18 (oss-fuzz soon to be).

  12. DrahtBot removed the label CI failed on Apr 4, 2024
  13. theuni commented at 4:55 pm on April 5, 2024: member

    Trying to make sense of all of this, I found this RFC helpful:

    • LLVM 18: first release that supports hardening modes and ways to enable them as described in the RFC.
      • The safe mode (available since the LLVM 15 release) is still supported; the release notes will mention that projects using the safe mode have to transition to use the hardened mode or the debug-lite mode instead (debug-lite is the rough equivalent of the old safe mode).
      • A few checks that used to be in the safe mode might become excluded (internally, safe will be mapped to debug-lite). In LLVM 17, the safe mode contains every check that isn’t explicitly marked as debug-only, but finer-grained categorization might allow trimming it down further.
      • The safe mode will no longer use __libcpp_verbose_abort when a check fails (__builtin_trap will be used instead). Overriding __libcpp_verbose_abort will no longer have an effect on the behavior of the safemode.
      • The meaning of the debug mode will change. The legacy debug mode has been removed in LLVM 17 1. The new debug mode that is part of hardening will be enabled using the mechanisms explained in the RFC and will function differently (e.g. it won’t require a global database).
    • LLVM 19: the safe mode will be deprecated. The LIBCXX_ENABLE_ASSERTIONS CMake variable and the _LIBCPP_ENABLE_ASSERTIONS macro will be deprecated (with a warning) and users will be given a message to migrate to the hardened mode or the debug-lite mode instead.
    • LLVM 20: the safe mode will be removed along with the associated macros and the CMake variable.
  14. theuni commented at 5:05 pm on April 5, 2024: member

    Oh, heh, I missed that @maflcko had already linked that. See also here for an RFC about the deprecation.

    I think I’m inclined to agree that it’s not worth supporting the old mode. It seems it’s old and janky and deprecated for good reason.

  15. fanquake force-pushed on Apr 5, 2024
  16. fanquake commented at 5:10 pm on April 5, 2024: member
    Dropped the older define.
  17. theuni commented at 8:33 pm on April 5, 2024: member
    utACK. Should darwin get this too though since it also uses libc++ ?
  18. fanquake commented at 9:46 am on April 7, 2024: member

    utACK. Should darwin get this too though since it also uses libc++ ?

    Maybe we could look into this once we switch the Darwin cross builds to use LLVM 18 (currently 17)? At this point the newest Apple Clang is still also based on LLVM 16.

  19. depends: add the new LLVM debug macro
    `LIBCPP_HARDENING_MODE` is the new macro, the previous one was removed in
    LLVM 18.
    
    See https://libcxx.llvm.org/Hardening.html.
    5efebc0edb
  20. fanquake force-pushed on Apr 7, 2024
  21. theuni approved
  22. theuni commented at 1:02 pm on April 8, 2024: member
    ACK 5efebc0edbb479d2041b3fb2d43be3a77e817b3e
  23. fanquake merged this on Apr 9, 2024
  24. fanquake closed this on Apr 9, 2024

  25. fanquake deleted the branch on Apr 9, 2024
  26. maflcko commented at 7:41 am on April 9, 2024: member

    My understanding is that the previous macro does not exist in llvm 18 (what this CI task is using). (git grep LIBCPP_ENABLE_DEBUG_MODE upstream_push/release/18.x is empty).

    It could make sense to double check that this can still catch issues.

  27. Pttn referenced this in commit 461e5cb256 on Apr 13, 2024
  28. maflcko commented at 4:12 pm on April 23, 2024: member

    Looks like it worked in https://github.com/bitcoin/bitcoin/runs/24156835563

    0/msan/cxx_build/include/c++/v1/string_view:399: assertion __pos < size() failed: string_view[] index out of bounds
    

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-12-22 12:12 UTC

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