From: David Malcolm <dmalcolm@redhat.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: Mir Immad <mirimnan017@gmail.com>, gcc@gcc.gnu.org
Subject: Re: [PATCH] static analysis support for posix file desccriptor APIs
Date: Tue, 21 Jun 2022 16:31:44 -0400 [thread overview]
Message-ID: <78c6ac309f6c30e003e32481bce55aebe34ef488.camel@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2206211848040.301475@digraph.polyomino.org.uk>
On Tue, 2022-06-21 at 18:50 +0000, Joseph Myers wrote:
> On Tue, 21 Jun 2022, David Malcolm via Gcc wrote:
>
> > So ultimately that's something we want to fix, though exactly how,
> > I'm
> > not quite sure; we presumably want to look up the target's
> > definitions
> > of those macros - but I don't think the analyzer has access to the
> > cpp_reader instance from the frontend.
>
> Normally that would use a target hook to specify the values of those
> macros. The default would be the traditional Unix values of 0, 1, 2
> for
> O_RDONLY, O_WRONLY, O_RDWR, while Hurd would need its own definition of
> the hook to use values 1, 2, 3 (I don't know if there are any non-Hurd
> systems not using the traditional values).
I found that it's at least theoretically possible to access the
preprocessor from within the analyzer; e.g. given:
#define O_RDONLY 42
and then breaking in the debugger in ana::run_checkers:
(gdb) p cpp_lookup (parse_in, (unsigned char *)"O_RDONLY",
(size_t)strlen ("O_RDONLY"))
$1 = (cpp_hashnode *) 0x7fffea794248
(gdb) p *$1
$2 = {ident = {str = 0x7fffea7877d0 "O_RDONLY", len = 8, hash_value =
3761648590}, is_directive = 0, directive_index = 0, rid_code = 0, flags
= 0, type = NT_USER_MACRO, deferred = 0, value = {answers =
0x7fffea7a5480, macro = 0x7fffea7a5480, builtin = 3933885568, arg_index
= 21632}}
(gdb) p $1->value.macro.exp.tokens.type
$6 = CPP_NUMBER
(gdb) p $1->value.macro.exp.tokens.val.str
$7 = {len = 2, text = 0x3ec182b "42"}
so given the C/C++ FEs it might be possible for the analyzer to try to
lookup the value of O_RDONLY.
But I'm wary of this; e.g. the LTO case, and for non-trivial macro
definitions.
Joseph: is the target hook the way to go with this? Would it look
something like:
DEFHOOK (fd_access_mode, "FIXME", int (int))
taking the build configuration's O_ access mode, and returning the
target configurations's access mode (so e.g fd_access_mode (O_RDONLY)
would return the target's int) ?
Thanks
Dave
next prev parent reply other threads:[~2022-06-21 20:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 16:30 Mir Immad
2022-06-21 16:30 ` Mir Immad
2022-06-21 18:34 ` David Malcolm
2022-06-21 18:50 ` Joseph Myers
2022-06-21 20:31 ` David Malcolm [this message]
2022-06-21 21:18 ` Joseph Myers
2022-06-23 18:28 ` Mir Immad
2022-06-24 18:05 ` David Malcolm
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=78c6ac309f6c30e003e32481bce55aebe34ef488.camel@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=joseph@codesourcery.com \
--cc=mirimnan017@gmail.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).