This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Use Fuchsia-native CPRNG for std::random_device
ClosedPublic

Authored by mcgrathr on Jan 2 2022, 11:54 AM.

Details

Summary

Use the zx_cprng_draw system call directly rather than going
through the libc getentropy function. The libc function is a
trivial wrapper around the system call, and is not a standard C
function. Avoiding it reduces the Fuchsia libc ABI surface that
libc++ depends on.

Diff Detail

Event Timeline

mcgrathr created this revision.Jan 2 2022, 11:54 AM
mcgrathr requested review of this revision.Jan 2 2022, 11:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 2 2022, 11:54 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne accepted this revision.Jan 3 2022, 1:36 PM
ldionne added a subscriber: ldionne.
ldionne added inline comments.
libcxx/src/random.cpp
188

This pragma is magic. It leaves a breadcrumb in the .o and the linker will pick it up automatically?

On what platforms does this work?

This revision is now accepted and ready to land.Jan 3 2022, 1:36 PM
mcgrathr added inline comments.Jan 4 2022, 9:06 AM
libcxx/src/random.cpp
188

Correct. The pragma syntax comes from MSVC and works there and in Clang on PE-COFF and ELF formats. The ELF linker magic it uses is only supported by lld last I checked (it emits an extra non-allocated section that other linkers would just ignore). For Fuchsia, we are fine assuming that current Clang and LLD are the only tools used.

ldionne added inline comments.Jan 4 2022, 9:21 AM
libcxx/src/random.cpp
188

This is pretty awesome, we could use that for mach-o as well.

This revision was landed with ongoing or failed builds.Jan 4 2022, 10:24 AM
This revision was automatically updated to reflect the committed changes.