[systemd-devel] rdrand generated with march=winchip-c6 in systemd-241
Lennart Poettering
lennart at poettering.net
Tue May 7 13:59:06 UTC 2019
On Di, 07.05.19 08:50, tedheadster (tedheadster at gmail.com) wrote:
> GCC and systemd teams:
> I compiled systemd-241 and expressly set march=winchip-c6 (an i486
> class cpu). It generated illegal instructions (rdrand) in the code.
> Oddly, it does NOT do this when I set march=i486:
>
> Dump of assembler code for function rdrand:
> 0xb7e21440 <+0>: push %esi
> 0xb7e21441 <+1>: push %ebx
> 0xb7e21442 <+2>: call 0xb7e0af5d <__x86.get_pc_thunk.si>
> 0xb7e21447 <+7>: add $0x1acb39,%esi
> 0xb7e2144d <+13>: mov 0x2870(%esi),%ecx
> 0xb7e21453 <+19>: test %ecx,%ecx
> 0xb7e21455 <+21>: js 0xb7e21480 <rdrand+64>
> 0xb7e21457 <+23>: test %ecx,%ecx
> 0xb7e21459 <+25>: je 0xb7e214e0 <rdrand+160>
> 0xb7e2145f <+31>: rdrand %ecx <------ bad opcode
> 0xb7e21462 <+34>: setb %al
> 0xb7e21465 <+37>: mov 0xc(%esp),%edx
> 0xb7e21469 <+41>: mov %ecx,(%edx)
> 0xb7e2146b <+43>: cmp $0x1,%al
> 0xb7e2146d <+45>: sbb %eax,%eax
> 0xb7e2146f <+47>: and $0xfffffff5,%eax
> 0xb7e21472 <+50>: pop %ebx
> 0xb7e21473 <+51>: pop %esi
> 0xb7e21474 <+52>: ret
> ...
>
> It sure looks like systemd-v241 is trying to detect support for this
> instruction before using it:
>
> https://github.com/systemd/systemd/blob/v241/src/basic/random-util.c#L36
WE are using gcc's __get_cpuid() call to query the cpuid feature
set. We then look for rdrand support in it and only then use the
opcode.
It appears that there's some wrong with this gcc feature if this
detection doesn't work correctly.
Note that generation of the opcode should not be a problem generally,
but the execution should. Normally we shouldn't get that far though,
if the __get_cpuid() detection works correctly.
To me this appears like something you need to contact the gcc folks
about.
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list