All of lore.kernel.org
 help / color / mirror / Atom feed
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 13:44:55 +0100	[thread overview]
Message-ID: <Z6Sux-uScF-o3g7W@yuki.lan> (raw)
In-Reply-To: <700f4d3bc73f0deebe7fe0e41305d365135c53eb.1738835278.git.jstancek@redhat.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.

> 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?

>  #ifndef ARRAY_SIZE
>  # define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
>  #endif
> diff --git a/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c b/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c
> index 90cf4fcb3b89..51783fc22b80 100644
> --- a/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c
> +++ b/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c
> @@ -26,7 +26,7 @@ void test_mallinfo2(void)
>  	char *buf;
>  	size_t size = 2UL * 1024UL * 1024UL * 1024UL;
>  
> -	buf = malloc(size);
> +	LTP_VAR_USED(buf) = malloc(size);
>  
>  	if (!buf)
>  		tst_brk(TCONF, "Current system can not malloc 2G space, skip it");
> -- 
> 2.43.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2025-02-06 12:45 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 [this message]
2025-02-06 12:58   ` Jan Stancek
2025-02-06 13:22     ` Cyril Hrubis
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=Z6Sux-uScF-o3g7W@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.