From 4e809c79cf113d991a11782ad2154bc35e17f51b Mon Sep 17 00:00:00 2001 From: Michael Hamburg Date: Sun, 28 May 2017 12:44:15 -0700 Subject: [PATCH] ok so the cpuid problem was an fPIC issue. Hopefully this fixes it... --- src/spongerng.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/spongerng.c b/src/spongerng.c index fbcef7c..52b424c 100644 --- a/src/spongerng.c +++ b/src/spongerng.c @@ -30,7 +30,21 @@ static void get_cpu_entropy(uint8_t *entropy, size_t len) { static char tested = 0, have_rdrand = 0; if (!tested) { uint32_t a,b,c,d; +#if defined(__i386__) && defined(__PIC__) + /* Don't clobber ebx. The compiler doesn't like when when __PIC__ */ + __asm__("mov %%ebx, %[not_ebx]\n\t" + "cpuid\n\t" + "xchg %%ebx, %[not_ebx]" : "=a"(a), [not_ebx]"=r"(b), "=c"(c), "=d"(d) : "0"(1)); +#elif defined(__x86_64__) && defined(__PIC__) + /* Don't clobber rbx. The compiler doesn't like when when __PIC__ */ + uint64_t b64; + __asm__("mov %%rbx, %[not_rbx]\n\t" + "cpuid\n\t" + "xchg %%rbx, %[not_rbx]" : "=a"(a), [not_rbx]"=r"(b64), "=c"(c), "=d"(d) : "0"(1)); + b = b64; +#else __asm__("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(1)); +#endif have_rdrand = (c>>30)&1; tested = 1; }