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
Change-Id: Ib7819f80041fe330d033fffda7e7c160141d7dd8
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit 6543f50536f3547b43a27b32af59d68f28a60247)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2024-09-27 09:52:15 -07:00 committed by Qt Cherry-pick Bot
parent f0758fb113
commit 30d40a8890

View File

@ -720,6 +720,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