public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Siddhesh Poyarekar <siddhesh@sourceware.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] cdefs: Limit definition of fortification macros
Date: Wed, 01 Feb 2023 18:48:13 +0100	[thread overview]
Message-ID: <87cz6tuvj6.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20230130133217.497398-1-siddhesh@sourceware.org> (Siddhesh Poyarekar's message of "Mon, 30 Jan 2023 08:32:17 -0500")

* Siddhesh Poyarekar:

> Define the __glibc_fortify and other macros only when __FORTIFY_LEVEL >
> 0.  This has the effect of not defining these macros on older C90
> compilers that do not have support for variable length argument lists.
>
> Also trim off the trailing backslashes from the definition of
> __glibc_fortify and __glibc_fortify_n macros.
>
> Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
> ---
>
> Only tested for sanity.  Florian, can you please verify that this
> resolves the original problem?
>
>  misc/sys/cdefs.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
> index 66d6702123..c37a3ff637 100644
> --- a/misc/sys/cdefs.h
> +++ b/misc/sys/cdefs.h
> @@ -152,6 +152,7 @@
>  # define __glibc_objsize(__o) __bos (__o)
>  #endif
>  
> +#if __USE_FORTIFY_LEVEL > 0
>  /* Compile time conditions to choose between the regular, _chk and _chk_warn
>     variants.  These conditions should get evaluated to constant and optimized
>     away.  */
> @@ -187,7 +188,7 @@
>     ? __ ## f ## _alias (__VA_ARGS__)					      \
>     : (__glibc_unsafe_len (__l, __s, __osz)				      \
>        ? __ ## f ## _chk_warn (__VA_ARGS__, __osz)			      \
> -      : __ ## f ## _chk (__VA_ARGS__, __osz)))			      \
> +      : __ ## f ## _chk (__VA_ARGS__, __osz)))
>  
>  /* Fortify function f, where object size argument passed to f is the number of
>     elements and not total size.  */
> @@ -197,7 +198,8 @@
>     ? __ ## f ## _alias (__VA_ARGS__)					      \
>     : (__glibc_unsafe_len (__l, __s, __osz)				      \
>        ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s))		      \
> -      : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))))		      \
> +      : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))))
> +#endif
>  
>  #if __GNUC_PREREQ (4,3)
>  # define __warnattr(msg) __attribute__((__warning__ (msg)))

Seems reasonable, thanks.  I believe it works with those old compilers.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Florian


      reply	other threads:[~2023-02-01 17:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30  7:58 C90 header compatibility Florian Weimer
2023-01-30 12:26 ` Siddhesh Poyarekar
2023-01-30 12:43   ` Florian Weimer
2023-01-30 13:32     ` [PATCH] cdefs: Limit definition of fortification macros Siddhesh Poyarekar
2023-02-01 17:48       ` Florian Weimer [this message]

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=87cz6tuvj6.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=siddhesh@sourceware.org \
    /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).