From: Dan Carpenter <dan.carpenter@oracle.com>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Markus Elfring <Markus.Elfring@web.de>,
kernel-janitors@vger.kernel.org,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Joe Perches <joe@perches.com>, Kees Cook <keescook@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] string.h: Mark 34 functions with __must_check
Date: Wed, 09 Oct 2019 18:45:18 +0000 [thread overview]
Message-ID: <20191009184518.GF13286@kadam> (raw)
In-Reply-To: <CAKwvOd=Jkd_qJULB+i1u31VJAex6KB=wFAyXO04V0UcAAEZeXw@mail.gmail.com>
On Wed, Oct 09, 2019 at 09:31:41AM -0700, Nick Desaulniers wrote:
> On Wed, Oct 9, 2019 at 7:30 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > On Wed, Oct 09, 2019 at 04:21:20PM +0200, Rasmus Villemoes wrote:
> > > On 09/10/2019 15.56, Dan Carpenter wrote:
> > > > That's because glibc strlen is annotated with __attribute_pure__ which
> > > > means it has no side effects.
> > >
> > > I know, except it has nothing to do with glibc headers. Just try the
> > > same thing in the kernel. gcc itself knows this about __builtin_strlen()
> > > etc. If anything, we could annotate some of our non-standard functions
> > > (say, memchr_inv) with __pure - then we'd both get the Wunused-value in
> > > the nonsense cases, and allow gcc to optimize or reorder the calls.
> >
> > Huh. You're right. GCC already knows. So this patch is pointless like
> > you say.
>
> Is it? None of the functions in include/linux/string.h are currently
> marked __pure today.
I've already embarrassed myself with my ignorance once so I may as well
keep talking now... GCC did complain about the unused result even
though we don't declare them as __pure. So GCC rule must have this rule
built in.
We were discussing in a different thread that standard says that
memcpy() pointers can't be NULL (even when we're copying zero bytes) so
GCC will assume that's true. If you have:
memcpy(foo, bar, 0);
if (foo)
*foo = 0;
GCC will sometimes remove the condition. This doesn't affect the kernel
because we use -fno-delete-null-pointer-checks.
https://groups.google.com/forum/#!msg/syzkaller-netbsd-bugs/8B4CIKN0Xz8/wRvIUWxiAgAJ
Weird, huh?
regards,
dan carpenter
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Markus Elfring <Markus.Elfring@web.de>,
kernel-janitors@vger.kernel.org,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Joe Perches <joe@perches.com>, Kees Cook <keescook@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] string.h: Mark 34 functions with __must_check
Date: Wed, 9 Oct 2019 21:45:18 +0300 [thread overview]
Message-ID: <20191009184518.GF13286@kadam> (raw)
In-Reply-To: <CAKwvOd=Jkd_qJULB+i1u31VJAex6KB=wFAyXO04V0UcAAEZeXw@mail.gmail.com>
On Wed, Oct 09, 2019 at 09:31:41AM -0700, Nick Desaulniers wrote:
> On Wed, Oct 9, 2019 at 7:30 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > On Wed, Oct 09, 2019 at 04:21:20PM +0200, Rasmus Villemoes wrote:
> > > On 09/10/2019 15.56, Dan Carpenter wrote:
> > > > That's because glibc strlen is annotated with __attribute_pure__ which
> > > > means it has no side effects.
> > >
> > > I know, except it has nothing to do with glibc headers. Just try the
> > > same thing in the kernel. gcc itself knows this about __builtin_strlen()
> > > etc. If anything, we could annotate some of our non-standard functions
> > > (say, memchr_inv) with __pure - then we'd both get the Wunused-value in
> > > the nonsense cases, and allow gcc to optimize or reorder the calls.
> >
> > Huh. You're right. GCC already knows. So this patch is pointless like
> > you say.
>
> Is it? None of the functions in include/linux/string.h are currently
> marked __pure today.
I've already embarrassed myself with my ignorance once so I may as well
keep talking now... GCC did complain about the unused result even
though we don't declare them as __pure. So GCC rule must have this rule
built in.
We were discussing in a different thread that standard says that
memcpy() pointers can't be NULL (even when we're copying zero bytes) so
GCC will assume that's true. If you have:
memcpy(foo, bar, 0);
if (foo)
*foo = 0;
GCC will sometimes remove the condition. This doesn't affect the kernel
because we use -fno-delete-null-pointer-checks.
https://groups.google.com/forum/#!msg/syzkaller-netbsd-bugs/8B4CIKN0Xz8/wRvIUWxiAgAJ
Weird, huh?
regards,
dan carpenter
next prev parent reply other threads:[~2019-10-09 18:45 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-09 12:14 [PATCH] string.h: Mark 34 functions with __must_check Markus Elfring
2019-10-09 12:14 ` Markus Elfring
2019-10-09 13:26 ` Rasmus Villemoes
2019-10-09 13:26 ` Rasmus Villemoes
2019-10-09 13:56 ` Dan Carpenter
2019-10-09 13:56 ` Dan Carpenter
2019-10-09 14:21 ` Rasmus Villemoes
2019-10-09 14:21 ` Rasmus Villemoes
2019-10-09 14:30 ` Dan Carpenter
2019-10-09 14:30 ` Dan Carpenter
2019-10-09 16:31 ` Nick Desaulniers
2019-10-09 16:31 ` Nick Desaulniers
2019-10-09 18:45 ` Dan Carpenter [this message]
2019-10-09 18:45 ` Dan Carpenter
2019-10-10 7:20 ` Rasmus Villemoes
2019-10-10 7:20 ` Rasmus Villemoes
2019-10-09 16:37 ` Nick Desaulniers
2019-10-09 16:37 ` Nick Desaulniers
2019-10-09 16:42 ` Markus Elfring
2019-10-09 16:42 ` Markus Elfring
2019-10-11 5:15 ` [Cocci] Searching for missing variable checks Markus Elfring
2019-10-11 5:15 ` Markus Elfring
2019-10-11 5:15 ` Markus Elfring
2019-10-09 15:09 ` [PATCH] string.h: Mark 34 functions with __must_check Steven Rostedt
2019-10-09 15:09 ` Steven Rostedt
2019-10-09 16:13 ` Nick Desaulniers
2019-10-09 16:13 ` Nick Desaulniers
2019-10-09 16:27 ` Steven Rostedt
2019-10-09 16:27 ` Steven Rostedt
2019-10-09 16:40 ` Nick Desaulniers
2019-10-09 16:40 ` Nick Desaulniers
2019-10-09 17:04 ` Markus Elfring
2019-10-09 17:04 ` Markus Elfring
2019-10-09 17:33 ` Nick Desaulniers
2019-10-09 17:33 ` Nick Desaulniers
2019-10-09 18:06 ` [Cocci] " Markus Elfring
2019-10-09 18:06 ` Markus Elfring
2019-10-09 18:06 ` Markus Elfring
2019-10-09 16:38 ` [PATCH] " Joe Perches
2019-10-09 16:38 ` Joe Perches
2019-10-09 17:33 ` Nick Desaulniers
2019-10-09 17:33 ` Nick Desaulniers
2019-10-10 14:27 ` David Sterba
2019-10-10 14:27 ` David Sterba
2019-10-10 14:34 ` Joe Perches
2019-10-10 14:34 ` Joe Perches
2019-10-11 5:00 ` Markus Elfring
2019-10-11 5:00 ` Markus Elfring
2019-10-10 15:46 ` [PATCH] " David Laight
2019-10-10 15:46 ` David Laight
2019-10-09 20:06 ` Markus Elfring
2019-10-09 20:06 ` Markus Elfring
2019-10-10 5:29 ` Andy Shevchenko
2019-10-10 5:29 ` Andy Shevchenko
2019-10-10 7:25 ` Markus Elfring
2019-10-10 7:25 ` Markus Elfring
2019-12-21 9:30 ` Markus Elfring
2019-12-21 9:30 ` Markus Elfring
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=20191009184518.GF13286@kadam \
--to=dan.carpenter@oracle.com \
--cc=Markus.Elfring@web.de \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=ndesaulniers@google.com \
--cc=rostedt@goodmis.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 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.