From: Cyril Hrubis <chrubis@suse.cz>
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] syscalls/mallinfo02: introduce LTP_VAR_USED to avoid optimization
Date: Thu, 6 Feb 2025 14:22:57 +0100 [thread overview]
Message-ID: <Z6S3sYucYPK6DuZu@yuki.lan> (raw)
In-Reply-To: <CAASaF6zuFMWJhph-8U4RRMhd0uHt1_mOVU5Bu0pZ=CVoLf+igw@mail.gmail.com>
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...
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-02-06 13:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 9:49 [LTP] [PATCH] syscalls/mallinfo02: introduce LTP_VAR_USED to avoid optimization Jan Stancek
2025-02-06 12:44 ` Cyril Hrubis
2025-02-06 12:58 ` Jan Stancek
2025-02-06 13:22 ` Cyril Hrubis [this message]
2025-02-07 9:49 ` Jan Stancek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z6S3sYucYPK6DuZu@yuki.lan \
--to=chrubis@suse.cz \
--cc=jstancek@redhat.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox