git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Makefile: force -O0 when compiling with SANITIZE=leak

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 19, 2022, 15:36 UTC
Message-ID
<xmqqfsfju8pa.fsf@gitster.g>
In-Reply-To
<Y08JZVDgJpJvrBiz@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 15 quoted lines
> 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.
Previous: Jeff King
Message 8 of 8 in “linux-leaks CI failure on master”
  1. Taylor BlauOct 18, 2022
  2. Jeff KingOct 18, 2022
  3. Makefile: force -O0 when compiling with SANITIZE=leakJeff King, Oct 18, 2022
  4. Ævar Arnfjörð BjarmasonOct 18, 2022
  5. Jeff KingOct 19, 2022
  6. Rubén JustoOct 20, 2022
  7. Jeff KingOct 21, 2022
  8. Junio C HamanoOct 19, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.