From: Alexander Monakov <amonakov@ispras.ru>
To: Sam James <sam@gentoo.org>
Cc: "Daniil Frolov" <exactlywb@ispras.ru>,
"Arsen Arsenović" <arsen@aarsen.me>,
gcc-patches@gcc.gnu.org
Subject: Re: [RFC PATCH] Detecting lifetime-dse issues via Valgrind [PR66487]
Date: Sun, 12 Nov 2023 12:00:46 +0300 (MSK) [thread overview]
Message-ID: <f2e216c0-358b-a576-e59b-d67604ccc32b@ispras.ru> (raw)
In-Reply-To: <87zfzj6hvx.fsf@gentoo.org>
On Sat, 11 Nov 2023, Sam James wrote:
> > Valgrind client requests are offered as macros that emit inline asm. For use
> > in code generation, we need to wrap it in a built-in. We know that implementing
> > such a built-in in libgcc is undesirable, [...].
>
> Perhaps less objectionable than you think, at least given the new CFR
> stuff from oliva from the other week that landed.
Yeah; we haven't found any better solution anyway.
> This is a really neat idea (it also makes me wonder if there's any other
> opportunities for Valgrind integration like this?).
To (attempt to) answer the parenthetical question, note that the patch is not
limited to instrumenting C++ cdtors, it annotates all lifetime CLOBBER marks,
so Valgrind should see lifetime boundaries of various on-stack arrays too.
(I hope positioning the new pass after build_ssa is sufficient to avoid
annotating too much, like non-address-taken local scalars)
> LLVM was the most recent example but it wasn't the first, and this has
> come up with LLVM in a few other places too (same root cause, wasn't
> obvious at all).
I'm very curious what you mean by "this has come up with LLVM [] too": ttbomk,
LLVM doesn't do such lifetime-based optimization yet, which is why compiling
LLVM with LLVM doesn't break it. Can you share some examples? Or do you mean
instances when libLLVM-miscompiled-with-GCC was linked elsewhere, and that
program crashed mysteriously as a result?
Indeed this work is inspired by the LLVM incident in PR 106943. Unforunately
we don't see many other instances with -flifetime-dse workarounds in public.
Grepping Gentoo Portage reveals only openjade. Arch applies the workaround to
a jvm package too, and we know that Firefox and LLVM apply it on their own.
This patch finds the issue in LLVM and openjade; testing it on Spidermonkey
is TODO. Suggestions for other interesting tests would be welcome.
> > --- a/libgcc/configure.ac
> > +++ b/libgcc/configure.ac
> > @@ -269,6 +269,54 @@ GCC_CHECK_SJLJ_EXCEPTIONS
> > GCC_CET_FLAGS(CET_FLAGS)
> > AC_SUBST(CET_FLAGS)
> >
> > +AC_CHECK_HEADER(valgrind.h, have_valgrind_h=yes, have_valgrind_h=no)
>
> Consider using PKG_CHECK_MODULES and falling back to a manual search.
Thanks. autotools bits in this patch are one-to-one copy of the pre-existing
Valgrind detection in the 'gcc' subdirectory where it's necessary for
running the compiler under Valgrind without false positives.
I guess the right solution is to move Valgrind detection into the top-level
'config' directory (and apply the cleanups you mention), but as we are not
familiar with autotools we just made the copy-paste for this RFC.
With the patch, --enable-valgrind-annotations becomes "overloaded" to
simultaneously instrument the compiler and enhance libgcc to support
-fvalgrind-emit-annotations, but those are independent and in practice
people may need the latter without the former.
Alexander
next prev parent reply other threads:[~2023-11-12 9:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-24 14:11 [RFC PATCH] Detecting lifetime-dse issues via Valgrind exactlywb
2023-11-11 22:25 ` [RFC PATCH] Detecting lifetime-dse issues via Valgrind [PR66487] Sam James
2023-11-12 9:00 ` Alexander Monakov [this message]
2023-11-12 9:05 ` Sam James
2023-11-12 22:53 ` Sam James
2023-11-15 9:58 ` Daniil Frolov
2023-11-11 22:26 ` [RFC PATCH] Detecting lifetime-dse issues via Valgrind Arsen Arsenović
2023-11-12 8:07 ` Alexander Monakov
2023-11-13 12:00 ` Richard Biener
2023-11-13 14:29 ` Alexander Monakov
2023-11-13 16:25 ` Richard Biener
2023-11-21 7:52 ` Alexander Monakov
2023-11-21 7:59 ` Alexander Monakov
2023-11-21 8:02 ` Richard Biener
2023-11-21 8:56 ` Alexander Monakov
2023-11-21 9:40 ` Richard Biener
2023-11-21 21:42 ` Hans-Peter Nilsson
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=f2e216c0-358b-a576-e59b-d67604ccc32b@ispras.ru \
--to=amonakov@ispras.ru \
--cc=arsen@aarsen.me \
--cc=exactlywb@ispras.ru \
--cc=gcc-patches@gcc.gnu.org \
--cc=sam@gentoo.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).