From: Jakub Jelinek <jakub@redhat.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Alexander Monakov <amonakov@ispras.ru>,
Eduard-Mihai Burtescu <eddyb@lyken.rs>,
Ian Lance Taylor <iant@google.com>,
gcc-patches <gcc-patches@gcc.gnu.org>,
Ian Lance Taylor <ian@airs.com>
Subject: Re: [PATCH] Refactor rust-demangle to be independent of C++ demangling.
Date: Wed, 23 Oct 2019 17:19:00 -0000 [thread overview]
Message-ID: <20191023164614.GG2116@tucnak> (raw)
In-Reply-To: <20191023163726.GO28442@gate.crashing.org>
On Wed, Oct 23, 2019 at 11:37:26AM -0500, Segher Boessenkool wrote:
> On Wed, Oct 23, 2019 at 07:22:47PM +0300, Alexander Monakov wrote:
> > On Wed, 23 Oct 2019, Eduard-Mihai Burtescu wrote:
> > > @@ -384,6 +384,14 @@ rust_demangle_callback (const char *mangled, int options,
> > > return 0;
> > > rdm.sym_len--;
> > >
> > > + /* Legacy Rust symbols also always end with a path segment
> > > + that encodes a 16 hex digit hash, i.e. '17h[a-f0-9]{16}'.
> > > + This early check, before any parse_ident calls, should
> > > + quickly filter out most C++ symbols unrelated to Rust. */
> > > + if (!(rdm.sym_len > 19
> > > + && !strncmp (&rdm.sym[rdm.sym_len - 19], "17h", 3)))
> >
> > This can be further optimized by using memcmp in place of strncmp, since from
> > the length check you know that you won't see the null terminator among the three
> > chars you're checking.
> >
> > The compiler can expand memcmp(buf, "abc", 3) inline as two comparisons against
> > a 16-bit immediate and an 8-bit immediate. It can't do the same for strncmp.
>
> The compiler does not currently do that, but it *could*. Or why not? The
> compiler is always allowed to load 3 characters here, whether some string
> has a NUL character earlier or not.
It is valid to call strncmp (mmap(...)+page_size-1, "abc", 3), the reading
of the string should stop when 0 is seen.
Of course, it might be that there is a strlen call visible and the strlen
pass could figure out that rdm.sym_len contains the strlen, but maybe it
isn't visible or there is some call in between that might in theory
invalidate it.
Jakub
next prev parent reply other threads:[~2019-10-23 16:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-22 18:24 Eduard-Mihai Burtescu
2019-10-22 18:48 ` Ian Lance Taylor via gcc-patches
2019-10-23 14:29 ` Eduard-Mihai Burtescu
2019-10-23 16:37 ` Alexander Monakov
2019-10-23 16:41 ` Segher Boessenkool
2019-10-23 17:19 ` Jakub Jelinek [this message]
2019-10-23 17:29 ` Segher Boessenkool
2019-10-23 17:37 ` Jakub Jelinek
2019-10-23 17:43 ` Segher Boessenkool
2019-10-25 12:46 ` Eduard-Mihai Burtescu
2019-10-30 16:56 ` Eduard-Mihai Burtescu
2019-11-08 17:02 ` Eduard-Mihai Burtescu
2019-11-08 17:44 ` Ian Lance Taylor via gcc-patches
2019-11-08 19:17 ` Eduard-Mihai Burtescu
2019-11-08 19:23 ` Ian Lance Taylor via gcc-patches
2019-11-15 21:00 ` Eduard-Mihai Burtescu
2019-11-16 15:39 ` Jeff Law
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=20191023164614.GG2116@tucnak \
--to=jakub@redhat.com \
--cc=amonakov@ispras.ru \
--cc=eddyb@lyken.rs \
--cc=gcc-patches@gcc.gnu.org \
--cc=ian@airs.com \
--cc=iant@google.com \
--cc=segher@kernel.crashing.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).