aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hamburg <mike@shiftleft.org>2017-05-28 12:44:15 -0700
committerMichael Hamburg <mike@shiftleft.org>2017-05-28 12:44:15 -0700
commit4e809c79cf113d991a11782ad2154bc35e17f51b (patch)
treea636032cd85ec680433e9364ea12d951c7a80214
parentavoid warning for uninitialized entropy; change asm cpuid to look more like cpuid.h in the vain hope that this will compile better (diff)
downloadgoldilocks-4e809c79cf113d991a11782ad2154bc35e17f51b.tar.xz
goldilocks-4e809c79cf113d991a11782ad2154bc35e17f51b.zip
ok so the cpuid problem was an fPIC issue. Hopefully this fixes it...
-rw-r--r--src/spongerng.c14
1 files changed, 14 insertions, 0 deletions
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;
}