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 <allan.jensen@qt.io>
This commit is contained in:
Thiago Macieira 2024-09-27 09:52:15 -07:00
parent f85a17abeb
commit 6543f50536

View File

@ -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