Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some build-checks ignored with cmake #4067

Open
jasom opened this issue Oct 20, 2020 · 1 comment
Open

Some build-checks ignored with cmake #4067

jasom opened this issue Oct 20, 2020 · 1 comment
Labels

Comments

@jasom
Copy link

jasom commented Oct 20, 2020

Issue description

I first noticed this when running zeromq inside a chroot on nixos; it was trying to open /dev/urandom and failing. Building manually, I noticed that cmake checks for getrandom() in zmq_check_getrandom() but then never sets -DZMQ_HAVE_GETRANDOM at buildtime

Environment

  • libzmq version (commit hash if unreleased): 4.3.2
  • OS: Linux/NixOS

Minimal test code / Steps to reproduce the issue

  1. Start with source on any system with getrandom()
  2. mkdir build
  3. cd build
  4. cmake ..
    • Ensure the following in output:
      -- Performing Test ZMQ_HAVE_GETRANDOM
      -- Performing Test ZMQ_HAVE_GETRANDOM - Success
      
  5. make VERBOSE=1 src/tweetnacl.o
  6. grep getrandom CMakeFiles/objects.dir/src/tweetnacl.c.o
  7. Build the whole system, strace any program that initializes zeromq

What's the actual result? (include assertion message & call stack if applicable)

In step #5 above, -DZMQ_HAVE_GETRANDOM does not appear on the command line
In step #6 above tweenacl,c.o has no match to the string "getrandom"
In step #7 above, observe that "/dev/urandom" is being opened, indicating getrandom is not in use

What's the expected result?

  • We should see -DZMQ_HAVE_GETRANDOM on the build command-line
  • grep should find a "getrandom" string in the tweentnacl binary file
  • initializing zeromq should not open /dev/urandom

Patch that fixes the problem

The following patch fixes the issue for getrandom(). I don't know if it's the idiomatic way to do it with cmake, and I suspect that most of the other checks will need updating as well (e.g. ZMQ_HAVE_NOEXCEPT seems to similarly have no effect), so I didn't make a PR:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8eb3411f..455369f5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -980,6 +980,10 @@ if(ZMQ_HAVE_TIPC)
   list(APPEND cxx-sources tipc_address.cpp tipc_connecter.cpp tipc_listener.cpp)
 endif()
 
+if(ZMQ_HAVE_GETRANDOM)
+  add_definitions(-DZMQ_HAVE_GETRANDOM)
+endif()
+
 #-----------------------------------------------------------------------------
 # source generators
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant