From: Florian Weimer <fweimer@redhat.com>
To: Yang Yanchao <yangyanchao6@huawei.com>
Cc: <libc-alpha@sourceware.org>, <linfeilong@huawei.com>,
<carlos@redhat.com>, <schwab@linux-m68k.org>
Subject: Re: [PATCH v4] elf: fixes compile error when both enable -Werror and -DNDEBUG
Date: Wed, 13 Apr 2022 12:16:19 +0200 [thread overview]
Message-ID: <87tuax47bg.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20220412094741.1902-1-yangyanchao6@huawei.com> (Yang Yanchao's message of "Tue, 12 Apr 2022 17:47:41 +0800")
* Yang Yanchao:
> Use -Werror and -DNDEBUG at the same time will
> causes the following compilation errors:
>
> cache.c: In function 'save_cache':
> cache.c:758:15: error: unused variable 'old_offset' [-Werror=unused-variable]
> 758 | off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET);
> | ^~~~~~~~~~
>
> -DNDEBUG will disables the assertion.
> Therefore, only the variables used by assertions do not take effect.
> use DIAG_IGNORE_NEEDS_COMMENT to disable this warning.
> ---
> elf/cache.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/elf/cache.c b/elf/cache.c
> index dbf4c83a7a..1e5427555b 100644
> --- a/elf/cache.c
> +++ b/elf/cache.c
> @@ -36,6 +36,7 @@
> #include <dl-cache.h>
> #include <version.h>
> #include <stringtable.h>
> +#include <libc-diag.h>
>
> /* Used to store library names, paths, and other strings. */
> static struct stringtable strings;
> @@ -751,6 +752,10 @@ save_cache (const char *cache_name)
> != (ssize_t) strings_finalized.size)
> error (EXIT_FAILURE, errno, _("Writing of cache data failed"));
>
> + /* Building with -DNDEBUG, assert will be ignored,
> + so that old_offset is not used */
> + DIAG_PUSH_NEEDS_COMMENT
> + DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wunused-variable");
> if (opt_format != opt_format_old)
> {
> /* Align file position to 4. */
> @@ -758,6 +763,7 @@ save_cache (const char *cache_name)
> assert ((unsigned long long int) (extension_offset - old_offset) < 4);
> write_extensions (fd, str_offset, extension_offset);
> }
> + DIAG_POP_NEEDS_COMMENT
>
> /* Make sure user can always read cache file */
> if (chmod (temp_name, S_IROTH|S_IRGRP|S_IRUSR|S_IWUSR))
Personally I would prefer __attribute__ ((unused)) directly on the
old_offset declaration. I think it's clearer.
Not sure what others think.
Thanks,
Florian
next prev parent reply other threads:[~2022-04-13 10:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-12 9:47 Yang Yanchao
2022-04-13 10:16 ` Florian Weimer [this message]
2022-04-13 12:46 ` Andreas Schwab
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=87tuax47bg.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=carlos@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=linfeilong@huawei.com \
--cc=schwab@linux-m68k.org \
--cc=yangyanchao6@huawei.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).