From 6543f50536f3547b43a27b32af59d68f28a60247 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 27 Sep 2024 09:52:15 -0700 Subject: Remove dead code in checkRdrndWorks() if __RDRND__ is defined The only place where we call qRandomCpu() in qrandom.cpp is guarded by a check using qCpuHasFeature(): if (qHasHwrng() && (uint(qt_randomdevice_control.loadAcquire()) & SkipHWRNG) == 0) filled += qRandomCpu(buffer, count); static inline bool qHasHwrng() { return qCpuHasFeature(RDRND); } Since qCpuHasFeature() also checks if __RDRND__ was defined, we ignore the result of checkRdrndWorks(). Users of CPUs without RNG must compile with an -march= flag that doesn't enable it or must pass -mno-rdrnd to keep the runtime detection code. Task-number: QTBUG-69423 Task-number: QTBUG-129193 Pick-to: 6.8 Change-Id: Ib7819f80041fe330d033fffda7e7c160141d7dd8 Reviewed-by: Allan Sandfeld Jensen --- src/corelib/global/qsimd.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib/global/qsimd.cpp') diff --git a/src/corelib/global/qsimd.cpp b/src/corelib/global/qsimd.cpp index b4fff814e6c..6f1e12312f9 100644 --- a/src/corelib/global/qsimd.cpp +++ b/src/corelib/global/qsimd.cpp @@ -747,6 +747,12 @@ static bool checkRdrndWorks() noexcept constexpr qsizetype TestBufferSize = 4; unsigned testBuffer[TestBufferSize] = {}; + // But if the RDRND feature was statically enabled by the compiler, we + // assume that the RNG works. That's because the calls to qRandomCpu() will + // be guarded by qCpuHasFeature(RDRND) and that will be a constant true. + if (_compilerCpuFeatures & CpuFeatureRDRND) + return true; + unsigned *end = qt_random_rdrnd(testBuffer, testBuffer + TestBufferSize); if (end < testBuffer + 3) { // Random generation didn't produce enough data for us to make a -- cgit v1.2.3