Re: [Bug report] __arch_hweight32/64 x86
From: Sebastian Sumpf
Date: Mon Jun 26 2023 - 17:43:08 EST
Hello Borislav,
On 6/26/23 23:06, Borislav Petkov wrote:
Hello,
On Mon, Jun 26, 2023 at 10:49:44PM +0200, Sebastian Sumpf wrote:
The 'ALTERNATIVE' macro checks for the popcnt feature. In case this fails
the '__sw_hweight' C-function is called from inline assembly with rax and
rdi as intput/output operands. However, the code does not contain a clobber
list of any callee safe registers that might be touched by the
'__sw_height64' C-function.
Which registers are those? Can you be more specific?
Registers that are free to use by a called C-function are: rcx, rdx, rsi, rdi,
and r8-r11 for x86_64. See the "System V Application Binary Interface
AMD64 Architecture Processor Supplement" [1] page 21. x86_32 I would have to
look up.
Therefore, these registers will not be restored
upon function return by the compiler. This leads to varying
exceptions/bad behavior caused by the thus corrupted registers later
on.
How do I reproduce what you're observing so that I can take a look?
This is hard to tell, I would disable the " X86_FEATURE_POPCNT" feature and use
the ' CONFIG_ARCH_HAS_FAST_MULTIPLIER' option in order to use the multiplier
implementation in '__sw_hweight64' in 'lib/hweight.c' At least that is what
triggered it here.
Regards,
Sebastian
[1] http://www.uclibc.org/docs/psABI-x86_64.pdf
--
Sebastian Sumpf
Genode Labs
http://www.genode-labs.com · http://genode.org
Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth