[LTP] [PATCH] syscalls/mallinfo02: introduce LTP_VAR_USED to avoid optimization

Jan Stancek jstancek@redhat.com
Fri Feb 7 10:49:20 CET 2025


On Thu, Feb 6, 2025 at 2:23 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > > > gcc 15 is a bit more clever and noticed that 'buf' isn't used
> > > > for anything so it optimized it out, including call to malloc.
> > > > So, there's also no mmap() call behind it and test fails,
> > > > because nothing was allocated.
> > >
> > > Huh, that sounds like the optimizations are getting more and more evil
> > > over the time.
> >
> > Also see the next patch for bpf.
>
> Sigh...
>
> > > > Introduce LTP_VAR_USED macro, that makes compiler aware of the
> > > > variable and doesn't optimize it out.
> > > >
> > > > Signed-off-by: Jan Stancek <jstancek@redhat.com>
> > > > ---
> > > >  include/tst_common.h                               | 2 ++
> > > >  testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c | 2 +-
> > > >  2 files changed, 3 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/include/tst_common.h b/include/tst_common.h
> > > > index b14bbae04077..3de826acd0ec 100644
> > > > --- a/include/tst_common.h
> > > > +++ b/include/tst_common.h
> > > > @@ -13,6 +13,8 @@
> > > >  #define LTP_ATTRIBUTE_UNUSED         __attribute__((unused))
> > > >  #define LTP_ATTRIBUTE_UNUSED_RESULT  __attribute__((warn_unused_result))
> > > >
> > > > +#define LTP_VAR_USED(p) asm volatile("" :: "m"(p)); p
> > >
> > > Shouldn't __attribute__((used)) suffice?
> >
> > It's ignored for local variables. It does work for global ones.
>
> Maybe mention that in the commit description...

Pushed with updated description.

>
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>



More information about the ltp mailing list