From: David Lamparter <equinox@diac24.net>
To: linux-kbuild@vger.kernel.org
Subject: gcc extended format checking plugin
Date: Sun, 19 Apr 2020 23:55:58 +0200 [thread overview]
Message-ID: <20200419215558.GU30496@eidolon.nox.tf> (raw)
Hello kernel build hackers,
in case it is of interest to anyone, we've recently added an extended
format string checking plugin in the FRRouting project. We took
inspiration from the Linux kernel and modified a printf (funnily enough,
the one from FreeBSD) to support things like %pI4, and we wanted better
warnings for this. Since the scheme is the same as in the Linux kernel,
it may or may not be worth someone's time to take a look.
The plugin is found here:
https://github.com/FRRouting/frr/tree/master/tools/gcc-plugins
It's derived from gcc's "c-format.c", as such it may make sense to look
at the diff instead of the straight source. The original GCC code is in
the git history there. It's tested against gcc 9.3.0, YMMV on other
versions.
Note that the plugin needs a single-line GCC source code modification:
https://github.com/FRRouting/frr/blob/master/tools/gcc-plugins/gcc-retain-typeinfo.patch
this is to stop GCC from prematurely stripping information, specifically
from casts in function parameters. It does work without the change, but
it may produce false-positive/negative warnings.
Aside from %pXX suffix support, the plugin also contains two other
changes that are probably irrelevant to kernel land:
- it makes some typedefs "final" types since these are not guaranteed to
be consistent in size across platforms and therefore can't be
printf'd without a cast (e.g. pid_t, uid_t, time_t, etc.)
- it reserves %Lu for uint64_t
Please don't expect too much on its code quality, I'm not a GCC
developer and essentially wrote this by trial and error ;)
Cheers,
-David
next reply other threads:[~2020-04-19 22:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-19 21:55 David Lamparter [this message]
2020-04-19 22:34 ` gcc extended format checking plugin Masahiro Yamada
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=20200419215558.GU30496@eidolon.nox.tf \
--to=equinox@diac24.net \
--cc=linux-kbuild@vger.kernel.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