From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "Taylor Blau" <me@ttaylorr.com>,
git@vger.kernel.org, "Victoria Dye" <vdye@github.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH] Makefile: force -O0 when compiling with SANITIZE=leak
Date: Wed, 19 Oct 2022 08:36:17 -0700 [thread overview]
Message-ID: <xmqqfsfju8pa.fsf@gitster.g> (raw)
In-Reply-To: <Y08JZVDgJpJvrBiz@coredump.intra.peff.net> (Jeff King's message of "Tue, 18 Oct 2022 16:15:33 -0400")
Jeff King <peff@peff.net> writes:
> Subject: Makefile: force -O0 when compiling with SANITIZE=leak
>
> Compiling with -O2 can interact badly with LSan's leak-checker, causing
> false positives. Imagine a simplified example like:
>
> char *str = allocate_some_string();
> if (some_func(str) < 0)
> die("bad str");
> free(str);
>
> The compiler may eliminate "str" as a stack variable, and just leave it
> in a register. The register is preserved through most of the function,
> including across the call to some_func(), since we'd eventually need to
> free it. But because die() is marked with NORETURN, the compiler knows
> that it doesn't need to save registers, and just clobbers it.
Yup, this is one weak point in the runtime checker in that it must
see the pointer held in the stack or register to ignore a still
reachable cruft that does not matter upon program exit, which cannot
work well with certain optimizations.
Theoretically there may be no guarantee that -O0 would disable all
optimizations that are potentially problematic to what LSan expects
to see, but I fully agree with you that this is the right direction.
Will queue. Thanks.
prev parent reply other threads:[~2022-10-19 15:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 18:37 linux-leaks CI failure on master Taylor Blau
2022-10-18 19:40 ` Jeff King
2022-10-18 20:15 ` [PATCH] Makefile: force -O0 when compiling with SANITIZE=leak Jeff King
2022-10-18 21:00 ` Ævar Arnfjörð Bjarmason
2022-10-19 7:10 ` Jeff King
2022-10-20 18:57 ` Rubén Justo
2022-10-21 6:04 ` Jeff King
2022-10-19 15:36 ` Junio C Hamano [this message]
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=xmqqfsfju8pa.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=me@ttaylorr.com \
--cc=peff@peff.net \
--cc=vdye@github.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 NNTP newsgroup(s).