[PATCH] D122789: [compiler-rt] [scudo] Use -mcrc32 on x86 when available

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 31 01:16:20 PDT 2022


mgorny created this revision.
mgorny added reviewers: kostyakozko, MaskRay, alekseyshl, tianqing, pengfei.
mgorny added a project: Sanitizers.
Herald added subscribers: StephenFan, cryptoad, dberris.
Herald added a project: All.
mgorny requested review of this revision.

Update the hardware CRC32 logic in SCudo to support using `-mcrc32`
instead of `-msse4.2`.  The CRC32 intrinsics use the former flag
in the newer compiler versions, e.g. in clang since 12fa608af44a <https://reviews.llvm.org/rG12fa608af44a80de8b655a8a984cd095908e7e80>.
With these compilers, passing `-msse4.2` is insufficient to enable
the instructions and causes build failures when `-march` does not enable
CRC32:

  /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.cpp:20:10: error: always_inline function '_mm_crc32_u32' requires target feature 'crc32', but would be inlined into function 'computeHardwareCRC32' that is compiled without support for 'crc32'
    return CRC32_INTRINSIC(Crc, Data);
           ^
  /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.h:27:27: note: expanded from macro 'CRC32_INTRINSIC'
  #  define CRC32_INTRINSIC FIRST_32_SECOND_64(_mm_crc32_u32, _mm_crc32_u64)
                            ^
  /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/../sanitizer_common/sanitizer_platform.h:132:36: note: expanded from macro 'FIRST_32_SECOND_64'
  #  define FIRST_32_SECOND_64(a, b) (a)
                                     ^
  1 error generated.

For backwards compatibility, use `-mcrc32` when available and fall back
to `-msse4.2`.  The `<smmintrin.h>` header remains in use as it still
works and is compatible with GCC, while clang's `<crc32intrin.h>`
is not.

Originally reported in https://bugs.gentoo.org/835870.


https://reviews.llvm.org/D122789

Files:
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/scudo/CMakeLists.txt
  compiler-rt/lib/scudo/scudo_allocator.cpp
  compiler-rt/lib/scudo/scudo_crc32.cpp
  compiler-rt/lib/scudo/scudo_crc32.h
  compiler-rt/lib/scudo/standalone/CMakeLists.txt
  compiler-rt/lib/scudo/standalone/checksum.h
  compiler-rt/lib/scudo/standalone/chunk.h
  compiler-rt/lib/scudo/standalone/crc32_hw.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122789.419360.patch
Type: text/x-patch
Size: 7701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220331/c23a3c72/attachment-0001.bin>


More information about the cfe-commits mailing list