jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.71k stars 605 forks source link

Crashes building on older machines #295

Open jacereda opened 2 years ago

jacereda commented 2 years ago

I had to disable the rdrand path to avoid crashes on my box.

https://github.com/jart/cosmopolitan/blob/39bf41f4eb25dc6b295bda6b3c254d4615cae1d4/third_party/python/Python/random.c#L464

Could this use cpuid to check the presence of rdrand and fallback to the old code in that case?

jart commented 2 years ago

Thank you for reporting this. This should be a simple fix since I had intended to remove that function. LIBC_RAND provides a uint64_t rdrand() function which can serve as a drop-in replacement. It performs all the appropriate CPUID checks. It's even smart enough to know if you're using a CPU model where RDRAND is buggy or slow (i.e. most AMD models) and will use the getrandom() system call instead. See:

Contributions welcome to help us simplify and improve consistency of random code. More eyeballs on the random code would also help too, due to its importance.