diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-06-16 17:36:22 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-06-16 17:37:49 -0700 |
commit | cafe24f039e117d53288387c2720f44f27deecd0 (patch) | |
tree | caf2211861bc7da04768cb11e79b8e6860176559 /src | |
parent | de8db47b7ff351f3287c5efb85102ba8836058d6 (diff) | |
parent | 9af207c810b5c4b09ccbdec75582b3e34e32e8cc (diff) |
Merge #10614: random: fix crash on some 64bit platforms
9af207c81 random: fix crash on some 64bit platforms (Cory Fields)
Tree-SHA512: c9516b69bec224c7e650dfc7c50f04cdd93a1006d515699bc64a311a03662d4ad33a834861194a1649ed212b37fb50aadfb004954cdf8b9bc1dc82f3ea962897
Diffstat (limited to 'src')
-rw-r--r-- | src/random.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/random.cpp b/src/random.cpp index 7916643263..67efc7d945 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -72,10 +72,16 @@ static bool rdrand_supported = false; static constexpr uint32_t CPUID_F1_ECX_RDRAND = 0x40000000; static void RDRandInit() { - //! When calling cpuid function #1, ecx register will have this set if RDRAND is available. + uint32_t eax, ecx, edx; +#if defined(__i386__) && ( defined(__PIC__) || defined(__PIE__)) // Avoid clobbering ebx, as that is used for PIC on x86. - uint32_t eax, tmp, ecx, edx; + uint32_t tmp; __asm__ ("mov %%ebx, %1; cpuid; mov %1, %%ebx": "=a"(eax), "=g"(tmp), "=c"(ecx), "=d"(edx) : "a"(1)); +#else + uint32_t ebx; + __asm__ ("cpuid": "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1)); +#endif + //! When calling cpuid function #1, ecx register will have this set if RDRAND is available. if (ecx & CPUID_F1_ECX_RDRAND) { LogPrintf("Using RdRand as entropy source\n"); rdrand_supported = true; |