All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Taylor Blau" <me@ttaylorr.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v3 4/4] test-lib: add "fast_unwind_on_malloc=0" to LSAN_OPTIONS
Date: Mon, 21 Feb 2022 16:58:35 +0100	[thread overview]
Message-ID: <patch-v3-4.4-d212009e517-20220221T155656Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v3-0.4-00000000000-20220221T155656Z-avarab@gmail.com>

Add "fast_unwind_on_malloc=0" to LSAN_OPTIONS to get more meaningful
stack traces from LSAN. This isn't required under ASAN which will emit
traces such as this one for a leak in "t/t0006-date.sh":

    $ ASAN_OPTIONS=detect_leaks=1 ./t0006-date.sh -vixd
    [...]
    Direct leak of 3 byte(s) in 1 object(s) allocated from:
        #0 0x488b94 in strdup (t/helper/test-tool+0x488b94)
        #1 0x9444a4 in xstrdup wrapper.c:29:14
        #2 0x5995fa in parse_date_format date.c:991:24
        #3 0x4d2056 in show_dates t/helper/test-date.c:39:2
        #4 0x4d174a in cmd__date t/helper/test-date.c:116:3
        #5 0x4cce89 in cmd_main t/helper/test-tool.c:127:11
        #6 0x4cd1e3 in main common-main.c:52:11
        #7 0x7fef3c695e49 in __libc_start_main csu/../csu/libc-start.c:314:16
        #8 0x422b09 in _start (t/helper/test-tool+0x422b09)

    SUMMARY: AddressSanitizer: 3 byte(s) leaked in 1 allocation(s).
    Aborted

Whereas LSAN would emit this instead:

    $ ./t0006-date.sh -vixd
    [...]
    Direct leak of 3 byte(s) in 1 object(s) allocated from:
        #0 0x4323b8 in malloc (t/helper/test-tool+0x4323b8)
        #1 0x7f2be1d614aa in strdup string/strdup.c:42:15

    SUMMARY: LeakSanitizer: 3 byte(s) leaked in 1 allocation(s).
    Aborted

Now we'll instead git this sensible stack trace under
LSAN. I.e. almost the same one (but starting with "malloc", as is
usual for LSAN) as under ASAN:

    Direct leak of 3 byte(s) in 1 object(s) allocated from:
        #0 0x4323b8 in malloc (t/helper/test-tool+0x4323b8)
        #1 0x7f012af5c4aa in strdup string/strdup.c:42:15
        #2 0x5cb164 in xstrdup wrapper.c:29:14
        #3 0x495ee9 in parse_date_format date.c:991:24
        #4 0x453aac in show_dates t/helper/test-date.c:39:2
        #5 0x453782 in cmd__date t/helper/test-date.c:116:3
        #6 0x451d95 in cmd_main t/helper/test-tool.c:127:11
        #7 0x451f1e in main common-main.c:52:11
        #8 0x7f012aef5e49 in __libc_start_main csu/../csu/libc-start.c:314:16
        #9 0x42e0a9 in _start (t/helper/test-tool+0x42e0a9)

    SUMMARY: LeakSanitizer: 3 byte(s) leaked in 1 allocation(s).
    Aborted

As the option name suggests this does make things slower, e.g. for
t0001-init.sh we're around 10% slower:

    $ hyperfine -L v 0,1 'LSAN_OPTIONS=fast_unwind_on_malloc={v} make T=t0001-init.sh' -r 3
    Benchmark 1: LSAN_OPTIONS=fast_unwind_on_malloc=0 make T=t0001-init.sh
      Time (mean ± σ):      2.135 s ±  0.015 s    [User: 1.951 s, System: 0.554 s]
      Range (min … max):    2.122 s …  2.152 s    3 runs

    Benchmark 2: LSAN_OPTIONS=fast_unwind_on_malloc=1 make T=t0001-init.sh
      Time (mean ± σ):      1.981 s ±  0.055 s    [User: 1.769 s, System: 0.488 s]
      Range (min … max):    1.941 s …  2.044 s    3 runs

    Summary
      'LSAN_OPTIONS=fast_unwind_on_malloc=1 make T=t0001-init.sh' ran
        1.08 ± 0.03 times faster than 'LSAN_OPTIONS=fast_unwind_on_malloc=0 make T=t0001-init.sh'

I think that's more than worth it to get the more meaningful stack
traces, we can always provide LSAN_OPTIONS=fast_unwind_on_malloc=0 for
one-off "fast" runs.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index ff13321bfd3..a96d19a332e 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -71,6 +71,7 @@ prepend_var ASAN_OPTIONS : detect_leaks=0
 export ASAN_OPTIONS
 
 prepend_var LSAN_OPTIONS : $GIT_SAN_OPTIONS
+prepend_var LSAN_OPTIONS : fast_unwind_on_malloc=0
 export LSAN_OPTIONS
 
 if test ! -f "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
-- 
2.35.1.1132.ga1fe46f8690


  parent reply	other threads:[~2022-02-21 15:59 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 21:01 [PATCH 0/4] test-lib: improve LSAN + ASAN stack traces Ævar Arnfjörð Bjarmason
2022-02-18 21:01 ` [PATCH 1/4] test-lib: add XSAN_OPTIONS, inherit [AL]SAN_OPTIONS Ævar Arnfjörð Bjarmason
2022-02-18 23:20   ` Junio C Hamano
2022-02-19  2:41     ` Taylor Blau
2022-02-19  2:48       ` Ævar Arnfjörð Bjarmason
2022-02-19  2:57         ` Taylor Blau
2022-02-19  3:02           ` Ævar Arnfjörð Bjarmason
2022-02-19  3:51             ` Taylor Blau
2022-02-18 21:01 ` [PATCH 2/4] test-lib: make $GIT_BUILD_DIR an absolute path Ævar Arnfjörð Bjarmason
2022-02-18 23:30   ` Junio C Hamano
2022-02-19  1:58     ` Ævar Arnfjörð Bjarmason
2022-02-19 11:29 ` [PATCH v2 0/4] test-lib: improve LSAN + ASAN stack traces Ævar Arnfjörð Bjarmason
2022-02-19 11:29   ` [PATCH v2 1/4] test-lib: add GIT_XSAN_OPTIONS, inherit [AL]SAN_OPTIONS Ævar Arnfjörð Bjarmason
2022-02-20  7:52     ` Junio C Hamano
2022-02-19 11:29   ` [PATCH v2 2/4] test-lib: correct commentary on TEST_DIRECTORY overriding Ævar Arnfjörð Bjarmason
2022-02-19 11:29   ` [PATCH v2 3/4] test-lib: make $GIT_BUILD_DIR an absolute path Ævar Arnfjörð Bjarmason
2022-02-19 11:29   ` [PATCH v2 4/4] test-lib: add "fast_unwind_on_malloc=0" to LSAN_OPTIONS Ævar Arnfjörð Bjarmason
2022-02-21  2:30   ` [PATCH v2 0/4] test-lib: improve LSAN + ASAN stack traces Taylor Blau
2022-02-21 15:58   ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2022-02-21 15:58     ` [PATCH v3 1/4] test-lib: add GIT_SAN_OPTIONS, inherit [AL]SAN_OPTIONS Ævar Arnfjörð Bjarmason
2022-02-21 15:58     ` [PATCH v3 2/4] test-lib: correct commentary on TEST_DIRECTORY overriding Ævar Arnfjörð Bjarmason
2022-02-21 15:58     ` [PATCH v3 3/4] test-lib: make $GIT_BUILD_DIR an absolute path Ævar Arnfjörð Bjarmason
2022-02-21 17:29       ` Taylor Blau
2022-02-21 18:55         ` Ævar Arnfjörð Bjarmason
2022-02-22  7:19           ` Junio C Hamano
2022-02-22 10:14             ` Ævar Arnfjörð Bjarmason
2022-02-23 20:16               ` Junio C Hamano
2022-02-24  9:14                 ` Ævar Arnfjörð Bjarmason
2022-02-24 20:05                   ` Junio C Hamano
2022-02-21 15:58     ` Ævar Arnfjörð Bjarmason [this message]
2022-02-21 17:32       ` [PATCH v3 4/4] test-lib: add "fast_unwind_on_malloc=0" to LSAN_OPTIONS Taylor Blau
2022-02-21 18:59         ` Ævar Arnfjörð Bjarmason
2022-02-21 17:16     ` [PATCH v3 0/4] test-lib: improve LSAN + ASAN stack traces Junio C Hamano
2022-02-21 18:55       ` Ævar Arnfjörð Bjarmason
2022-02-27 10:25     ` [PATCH v4 " Ævar Arnfjörð Bjarmason
2022-02-27 10:25       ` [PATCH v4 1/4] test-lib: add GIT_SAN_OPTIONS, inherit [AL]SAN_OPTIONS Ævar Arnfjörð Bjarmason
2022-02-27 10:25       ` [PATCH v4 2/4] test-lib: correct and assert TEST_DIRECTORY overriding Ævar Arnfjörð Bjarmason
2022-02-27 10:25       ` [PATCH v4 3/4] test-lib: make $GIT_BUILD_DIR an absolute path Ævar Arnfjörð Bjarmason
2022-02-27 10:25       ` [PATCH v4 4/4] test-lib: add "fast_unwind_on_malloc=0" to LSAN_OPTIONS Ævar Arnfjörð Bjarmason

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=patch-v3-4.4-d212009e517-20220221T155656Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.