public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Sergey Bugaev <bugaevc@gmail.com>
Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	libc-alpha@sourceware.org
Subject: Re: [PATCH v2 3/3] io: Add FORTIFY_SOURCE check for fcntl arguments
Date: Tue, 30 May 2023 11:50:04 +0200	[thread overview]
Message-ID: <871qiyw3lf.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CAN9u=Hc6m8n9C6qtgt_GRQtQ+2JsF_KUUU+P-zdqeRe1pQ1Cig@mail.gmail.com> (Sergey Bugaev's message of "Tue, 30 May 2023 12:07:44 +0300")

* Sergey Bugaev:

> Hello,
>
> On Tue, May 30, 2023 at 10:41 AM Florian Weimer <fweimer@redhat.com> wrote:
>> The noinline attribute does exactly what it says: it prevents inlining,
>> but it does not prevent inter-procedural analysis.  So if a function
>> returns a constrant, the compiler will still use that constant
>> elsewhere.  Newer GCC versions support the noipa attribute.  If you drop
>> the static, you can use the weak attribute for compatibility with pretty
>> much all GCC versions.
>>
>> But I think using volatile (without noinline for clarity) is fine here.
>
> So do I read this right that you're saying I should just do
>
> static int
> hide_constant (int value)
> {
>   volatile int v = value;
>   return v;
> }
>
> ? After the yesterday's discussion with Adhemerval, I was thinking of doing
>
> static inline int
> hide_constant (int value)
> {
>   asm ("" : "+rm" (value));
>   return value;
> }
>
> This does *not* prevent the whole computation from being optimized out
> if the result is unused (i.e. there's no 'volatile'), but it does
> prevent the compiler from assuming anything about the return value.

I think both variants are fine in this case.  If Adhemerval prefers the
second, please use that.

Thanks,
Florian


  reply	other threads:[~2023-05-30  9:50 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-28 17:20 [PATCH v2 0/3] fcntl fortification Sergey Bugaev
2023-05-28 17:20 ` [PATCH v2 1/3] support: Add support_fcntl_support_ofd_locks () Sergey Bugaev
2023-05-29 13:18   ` Adhemerval Zanella Netto
2023-05-28 17:20 ` [PATCH v2 2/3] cdefs.h: Define __glibc_warn_system_headers_{begin,end} Sergey Bugaev
2023-05-29 14:50   ` [PATCH v2 2/3] cdefs.h: Define __glibc_warn_system_headers_{begin, end} Adhemerval Zanella Netto
2023-05-28 17:20 ` [PATCH v2 3/3] io: Add FORTIFY_SOURCE check for fcntl arguments Sergey Bugaev
2023-05-29 16:54   ` Adhemerval Zanella Netto
2023-05-29 17:31     ` Sergey Bugaev
2023-05-29 18:09       ` Adhemerval Zanella Netto
2023-05-29 19:57         ` Sergey Bugaev
2023-05-29 20:14           ` Adhemerval Zanella Netto
2023-05-29 20:49             ` Sergey Bugaev
2023-05-29 21:09               ` Adhemerval Zanella Netto
2023-05-29 21:59                 ` Sergey Bugaev
2023-05-30 11:34                   ` Adhemerval Zanella Netto
2023-05-30  7:41         ` Florian Weimer
2023-05-30  9:07           ` Sergey Bugaev
2023-05-30  9:50             ` Florian Weimer [this message]
2023-05-30 11:35               ` Adhemerval Zanella Netto
2023-05-30  8:09 ` [PATCH v2 0/3] fcntl fortification Florian Weimer
2023-05-30 10:46   ` Sergey Bugaev
2023-05-30 11:08     ` Florian Weimer
2023-05-30 11:34       ` Sergey Bugaev
2023-05-30 11:50         ` Florian Weimer
2023-05-30 11:51         ` Florian Weimer
2023-05-30 12:15           ` Sergey Bugaev
2023-05-30 12:26             ` Florian Weimer

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=871qiyw3lf.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=bugaevc@gmail.com \
    --cc=libc-alpha@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).