Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

PCG lacks a module in cmake/ #2

Open
ringerc opened this issue Jun 5, 2018 · 14 comments
Open

PCG lacks a module in cmake/ #2

ringerc opened this issue Jun 5, 2018 · 14 comments

Comments

@ringerc
Copy link

ringerc commented Jun 5, 2018

There's no FindPGC.cmake

$ cmake -DHUNTER_ENABLED=0 .
CMake Error at CMakeLists.txt:130 (find_package):
  By not providing "Findpcg.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "pcg", but
  CMake did not find one.

  Could not find a package configuration file provided by "pcg" with any of
  the following names:

    pcgConfig.cmake
    pcg-config.cmake

  Add the installation prefix of "pcg" to CMAKE_PREFIX_PATH or set "pcg_DIR"
  to a directory containing one of the above files.  If "pcg" provides a
  separate development package or SDK, be sure it has been installed.
@ringerc
Copy link
Author

ringerc commented Jun 5, 2018

Per #1 I don't understand why PGC is used at all.

You don't use GRD_RANDOM so the only way the GRD_NONBLOCK flag is useful is if the urandom pool isn't initialized yet, and that's not likely to be an issue for the sorts of things Jaeger is used for. The nonblocking call is very suspect given that you don't retry or loop, anyway, so you might fail to initialize the seed at all. You also call the syscall directly instead of using the glibc wrapper where available.

On Linux it's sufficient for all but the strongest crypto purposes (and probably even then) to simply use random_r from <stdlib.h> and there's no need for PGC.

So it seems to me that PGC isn't found properly, and the seed isn't guaranteed safely initialized when using SYS_getrandom. Also, the macros aren't overly safe; better to use a static inline and accept the size arg separately.

I'll send a pull.

@ringerc
Copy link
Author

ringerc commented Jun 5, 2018

OK, so the reason for the direct syscall is https://lwn.net/Articles/711013/ . Fair enough, glibc support came much later than kernel support for this syscall. However, it's unsafe to determine its availability at configure-time and not check for ENOSYS at runtime, because you don't know if your build kernel will be the same as your runtime kernel.

@ringerc
Copy link
Author

ringerc commented Jun 5, 2018

Ok, and glibc's random_r etc are probably unsafe or at least hard to get right.

Edit: probably safe for Jaeger's apparent uses, but with care and the caveats in the docs considered.

So this comes down to "why can't you use the global RNG?"

Is it not wanting to rely on or contaminate the app's use of the RNG? That's fair enough if so, but most users won't care, and I'd rather cut a dependency most of the time instead.

@ringerc
Copy link
Author

ringerc commented Jun 5, 2018

.... and PGC isn't packaged in Fedora - and I don't see it in Debian either. Nor is it documented in the README as required. So it seems the lib is already broken for !HUNTER builds.

Would you accept a fallback implementation to the system RNG?

@isaachier
Copy link
Owner

Honestly, it isn't a huge deal. I just wanted a "good random function," and this has a great website: http://www.pcg-random.org/. What would you recommend?

@ringerc
Copy link
Author

ringerc commented Jun 6, 2018 via email

@ringerc
Copy link
Author

ringerc commented Jun 7, 2018

@isaachier Working on this now. Confused as to why non-hot paths for random init, etc are static inlines in src/jaegertracingc/internal/random.h but the hot code jaeger_random64 is in src/jaegertracingc/random.c. Seems odd to separate them out explicitly like that, especially since the compiler is plenty smart enough to inline a normal static function.

@ringerc
Copy link
Author

ringerc commented Jun 7, 2018

@isaachier Please confirm if you want me to make PCG optional, or if you're OK with removing it entirely. I recommend removal unless you know you need very strong randomness.

@isaachier
Copy link
Owner

We can use system randomness. I'm not sure it is wise to put so much in the headers. As of now I followed your advice to keep it in the headers, but I wanted to benchmark this approach against a more opaque implementation. Link time optimization could help, and it would keep the library flexible. Bottom line, people shouldn't be using Jaeger functions directly if they can use OpenTracing calls instead.

@ringerc
Copy link
Author

ringerc commented Jun 8, 2018 via email

@isaachier
Copy link
Owner

I just pushed a commit that should fix this. Sorry to preempt your PR. Please let me know what you think.

@ringerc
Copy link
Author

ringerc commented Jun 11, 2018

For reference of other readers that's 49513a5

ringerc added a commit to 2ndQuadrant/jaeger-client-c that referenced this issue Jun 11, 2018
@isaachier
Copy link
Owner

I'll try to pull in some of these changes. Thank you!

@ringerc
Copy link
Author

ringerc commented Jun 12, 2018

Improvements for this are in PR #3

@isaachier isaachier changed the title PGC lacks a module in cmake/ PCG lacks a module in cmake/ Jun 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants