* [Qemu-devel] [PATCH] linux-user/flatload: fix initial stack pointer alignment
@ 2018-10-24 2:38 Max Filippov
2018-10-24 11:35 ` Laurent Vivier
0 siblings, 1 reply; 4+ messages in thread
From: Max Filippov @ 2018-10-24 2:38 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier, Max Filippov
Stack pointer alignment code incorrectly adds stack_size to sp instead
of subtracting it. It also does not take flat_argvp_envp_on_stack() into
account when calculating stack_size. This results in initial stack
pointer misalignment with certain set of command line arguments and
environment variables and correct alignment for the same binary with a
different set of arguments. This misalignment causes failures in the
following tests in the testsuite of gcc built for xtensa uclinux:
gcc.dg/torture/vshuf-v64qi.c
gcc.dg/torture/vshuf-v8sf.c
gcc.dg/torture/vshuf-v8si.c
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
linux-user/flatload.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/linux-user/flatload.c b/linux-user/flatload.c
index 2eefe55e5000..1893966b5b30 100644
--- a/linux-user/flatload.c
+++ b/linux-user/flatload.c
@@ -771,10 +771,12 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info)
/* Enforce final stack alignment of 16 bytes. This is sufficient
for all current targets, and excess alignment is harmless. */
stack_len = bprm->envc + bprm->argc + 2;
- stack_len += 3; /* argc, arvg, argp */
+ stack_len += flat_argvp_envp_on_stack() ? 2 : 0; /* arvg, argp */
+ stack_len += 1; /* argc */
stack_len *= sizeof(abi_ulong);
- if ((sp + stack_len) & 15)
- sp -= 16 - ((sp + stack_len) & 15);
+ if ((sp - stack_len) & 15) {
+ sp -= ((sp - stack_len) & 15);
+ }
sp = loader_build_argptr(bprm->envc, bprm->argc, sp, p,
flat_argvp_envp_on_stack());
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user/flatload: fix initial stack pointer alignment
2018-10-24 2:38 [Qemu-devel] [PATCH] linux-user/flatload: fix initial stack pointer alignment Max Filippov
@ 2018-10-24 11:35 ` Laurent Vivier
2018-10-24 17:19 ` Max Filippov
0 siblings, 1 reply; 4+ messages in thread
From: Laurent Vivier @ 2018-10-24 11:35 UTC (permalink / raw)
To: Max Filippov, qemu-devel
On 24/10/2018 03:38, Max Filippov wrote:
> Stack pointer alignment code incorrectly adds stack_size to sp instead
> of subtracting it. It also does not take flat_argvp_envp_on_stack() into
> account when calculating stack_size. This results in initial stack
> pointer misalignment with certain set of command line arguments and
> environment variables and correct alignment for the same binary with a
> different set of arguments. This misalignment causes failures in the
> following tests in the testsuite of gcc built for xtensa uclinux:
>
> gcc.dg/torture/vshuf-v64qi.c
> gcc.dg/torture/vshuf-v8sf.c
> gcc.dg/torture/vshuf-v8si.c
>
> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
> ---
> linux-user/flatload.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/linux-user/flatload.c b/linux-user/flatload.c
> index 2eefe55e5000..1893966b5b30 100644
> --- a/linux-user/flatload.c
> +++ b/linux-user/flatload.c
> @@ -771,10 +771,12 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info)
> /* Enforce final stack alignment of 16 bytes. This is sufficient
> for all current targets, and excess alignment is harmless. */
> stack_len = bprm->envc + bprm->argc + 2;
> - stack_len += 3; /* argc, arvg, argp */
> + stack_len += flat_argvp_envp_on_stack() ? 2 : 0; /* arvg, argp */
> + stack_len += 1; /* argc */> stack_len *= sizeof(abi_ulong);
> - if ((sp + stack_len) & 15)
> - sp -= 16 - ((sp + stack_len) & 15);
> + if ((sp - stack_len) & 15) {
> + sp -= ((sp - stack_len) & 15);
> + }
If I understand correctly the purpose, I think it could be clearer like:
sp = (sp - stack_len) & ~15;
Thanks,
Laurent
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user/flatload: fix initial stack pointer alignment
2018-10-24 11:35 ` Laurent Vivier
@ 2018-10-24 17:19 ` Max Filippov
2018-10-24 18:30 ` Max Filippov
0 siblings, 1 reply; 4+ messages in thread
From: Max Filippov @ 2018-10-24 17:19 UTC (permalink / raw)
To: Laurent Vivier; +Cc: qemu-devel
On Wed, Oct 24, 2018 at 4:35 AM Laurent Vivier <laurent@vivier.eu> wrote:
> > diff --git a/linux-user/flatload.c b/linux-user/flatload.c
> > index 2eefe55e5000..1893966b5b30 100644
> > --- a/linux-user/flatload.c
> > +++ b/linux-user/flatload.c
> > - sp -= 16 - ((sp + stack_len) & 15);
> > + if ((sp - stack_len) & 15) {
> > + sp -= ((sp - stack_len) & 15);
> > + }
>
> If I understand correctly the purpose, I think it could be clearer like:
>
> sp = (sp - stack_len) & ~15;
Yes, you're right. I'll send v2.
--
Thanks.
-- Max
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user/flatload: fix initial stack pointer alignment
2018-10-24 17:19 ` Max Filippov
@ 2018-10-24 18:30 ` Max Filippov
0 siblings, 0 replies; 4+ messages in thread
From: Max Filippov @ 2018-10-24 18:30 UTC (permalink / raw)
To: Laurent Vivier; +Cc: qemu-devel
On Wed, Oct 24, 2018 at 10:19 AM Max Filippov <jcmvbkbc@gmail.com> wrote:
>
> On Wed, Oct 24, 2018 at 4:35 AM Laurent Vivier <laurent@vivier.eu> wrote:
> > > diff --git a/linux-user/flatload.c b/linux-user/flatload.c
> > > index 2eefe55e5000..1893966b5b30 100644
> > > --- a/linux-user/flatload.c
> > > +++ b/linux-user/flatload.c
>
> > > - sp -= 16 - ((sp + stack_len) & 15);
> > > + if ((sp - stack_len) & 15) {
> > > + sp -= ((sp - stack_len) & 15);
> > > + }
> >
> > If I understand correctly the purpose, I think it could be clearer like:
> >
> > sp = (sp - stack_len) & ~15;
>
> Yes, you're right. I'll send v2.
Well, not exactly. The sp is not moved down stack_len + alignment bytes,
only the alignment bytes. I'll send v2 anyway.
--
Thanks.
-- Max
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-10-24 18:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-24 2:38 [Qemu-devel] [PATCH] linux-user/flatload: fix initial stack pointer alignment Max Filippov
2018-10-24 11:35 ` Laurent Vivier
2018-10-24 17:19 ` Max Filippov
2018-10-24 18:30 ` Max Filippov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).