i386 get_cpuid() function looks wrong

Iru Cai vimacs at disroot.org
Wed Apr 28 03:27:05 CEST 2021


Hello,

I built libgcrypt for 32-bit x86, and it reports wrong CPU hardware 
features. After some debugging, I found the get_cpuid() function go 
wrong. This function use some inline assembly code:

   asm volatile
     ("movl %%ebx, %%edi\n\t"     /* Save GOT register.  */
      "xorl %%ebx, %%ebx\n\t"
      "cpuid\n\t"
      "movl %%ebx, %1\n\t"
      "movl %%edi, %%ebx\n\t"     /* Restore GOT register. */
      : "=a" (regs[0]), "=g" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
      : "0" (in), "2" (0), "3" (0)
      : "cc", "edi"
      );

When I build libgcrypt with CFLAGS '-m32 -march=i686 -Os', '%1' in the 
above assembly code can be assigned to ebx, thus the code go wrong. 
After checking the GCC manual, "=g" means any register, so the compiler 
can allocate ebx to it.

Regards,
Iru



More information about the Gcrypt-devel mailing list