[LTP] [PATCH v1] syscalls/signal06: add volatile to loop variable
Cyril Hrubis
chrubis@suse.cz
Fri Aug 19 11:02:04 CEST 2022
On Fri, Aug 19, 2022 at 10:41:23AM +0200, Cyril Hrubis wrote:
> Hi!
> > Thanks! The bug was closed as 'adding "cx" worked'. Reading topperc's comment it
> > looks like there no other way to fix the issue on clang than workaround with
> > volatile. Does it mean that it's a syscall problem and clang can do nothing
> > about it?
>
> It's problem with the inline assembly in the body of the while loop, the
> call to the syscall changes the register value that is used for the D
> variable in the case of clang, so the loop exits prematurely. We have to
> add cx register to the clobber list for that asm statement so that
> compiler knows that it's changed by the assembly.
>
> Interfacing assembly with C is a bit tricky since you have to explain
> to compiler which registers are changed from the assembly otherwise the
> results are undefined.
>
> The patch should look like:
>
> diff --git a/testcases/kernel/syscalls/signal/signal06.c b/testcases/kernel/syscalls/signal/signal06.c
> index 64f886ee3..78efd0fb9 100644
> --- a/testcases/kernel/syscalls/signal/signal06.c
> +++ b/testcases/kernel/syscalls/signal/signal06.c
> @@ -73,7 +73,7 @@ void test(void)
> /* sys_tkill(pid, SIGHUP); asm to avoid save/reload
> * fp regs around c call */
> asm ("" : : "a"(__NR_tkill), "D"(pid), "S"(SIGHUP));
> - asm ("syscall" : : : "ax");
> + asm ("syscall" : : : "ax", "cx");
>
> loop++;
> }
>
> Although it may not be a complete as the llwm issue suggests we should
> have a look at calling conventions for the syscall and check if we need
> to add any other registers to the clobber list.
Looking at: https://en.wikibooks.org/wiki/X86_Assembly/Interfacing_with_Linux
We may as well add r11 as suggested by the clang issue comment and that
should be complete.
Edward will you send a patch?
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list