conan-center-index icon indicating copy to clipboard operation
conan-center-index copied to clipboard

zeromq: Add options to enable sanitizers

Open pblxptr opened this issue 6 months ago • 3 comments

Summary

Changes to recipe: zeromq/4.3.5

Motivation

This PR adds CMake options to enable AddressSanitizer (ASAN), ThreadSanitizer (TSAN), UndefinedBehaviorSanitizer (UBSAN), and atomic intrinsics support. These options help developers catch memory errors, data races, and undefined behavior during development and testing, improving code safety and reliability.

Details

TSAN may report many false positives in libzmq because thread synchronization is often managed by design assumptions rather than explicit enforcement. The configuration below allows building libzmq with basic TSAN support, mainly for compatibility when linking with other TSAN-instrumented code e.g. applications using ZeroMQ and tested under various sanitizers.

  • Added ENABLE_ASAN, ENABLE_TSAN, and ENABLE_UBSAN options to allow building with sanitizers for better bug detection.
  • Added ENABLE_INTRINSICS option to use compiler intrinsics for atomic operations, improving performance and correctness.

More information can be found here https://github.com/zeromq/libzmq/issues/3919


pblxptr avatar May 27 '25 14:05 pblxptr

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 27 '25 14:05 CLAassistant

Hi, just checking in to see if there’s anything I can do to move this forward. Happy to make changes if needed.

pblxptr avatar Jun 08 '25 09:06 pblxptr

Hi @pblxptr - thanks for your PR.

Adding specific options for sanitizers is not something that we typically handle at the recipe level, because it can be done outside of the recipes altogether, in your profile.

For example, for asan

os=Linux
compiler=gcc
...

[conf]
tools.build:cflags=["-fsanitize=address","-fsanitize-address-use-after-scope","-fno-omit-frame-pointer"]
tools.build:cxxflags=["-fsanitize=address","-fsanitize-address-use-after-scope","-fno-omit-frame-pointer"]
tools.build:exelinkflags=["-fsanitize=address","-fsanitize-address-use-after-scope"]
tools.build:sharedlinkflags=["-fsanitize=address","-fsanitize-address-use-after-scope"]

These are generally preferred, since using sanitizers typically means all dependencies need to be built with sanitizers (otherwise there may be false positives or false negatives).

If you wish to enforce this for zeromq only, this can also be injected via the profile or command line without the recipe having to be modified:

[conf]
zeromq/*:tools.cmake.cmaketoolchain:extra_variables={'ENABLE_ASAN': 'ON'}

Let us know if you have questions about how to inject these.

Happy to consider ENABLE_INTRINSICS as an option for the recipe, as that one seems to be specific to zmq.

jcar87 avatar Jun 20 '25 09:06 jcar87