unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Vibhav Pant <vibhavp@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: feature/asan-gc-poisoning: Better memory checks using AddressSanitizer
Date: Tue, 6 Dec 2022 02:05:36 +0530	[thread overview]
Message-ID: <CA+T2Sh3CF34drunaKb89c2MXo4VS9HRPAqSKfm1+O8sV9RKPqQ@mail.gmail.com> (raw)

As part of trying to debug the deluge of GC borks in
scratch/comp-static-data, I took a slight detour through Emacs' memory
management code and the sanity checks that it optionally comes with.
The changes in feature/asan-gc-poisoning attempt to augment the
latter, specifically when Emacs is built with '-fsanitize=address'.

When enabled, almost all memory management operations are instrumented
with calls to ASan's "(un)poisoning" functions, which allow ASan to
mark allocated but not freed addresses as "poisoned", triggering
errors whenever they have been accessed. The idea behind this is to
add another layer of checks against code that makes use of free lists
and arena based allocators, only allowing access to regions of the
memory that are actually intended to be accessible (aka "unpoisoned"
in ASan parlance) by non alloc-related C code. An instance of this is
any object on a free list, or a vectorlike with the type PVEC_FREE (we
do abort whenever we come across such a vector, but this ideally
catches the bug way earlier in the flow, and therefore closer to the
source of the actual problem). Additional documentation explaining
this feature is available both on src/alloc.c and the "Running Emacs
with address sanitization" section in etc/DEBUG.

The branch bootstraps successfully both with native-comp enabled and
disabled, and passes everything on the test suite on my machine.
Because enabling Address Sanitizer comes with a significant
performance + memory overhead, using it as a daily driver isn't
without a decent bit of sluggishness, although building with -O2 and
native compilation seems to help, at least a little.
I plan to get install this in `master` soon, so both feedback and
testing from other users would be greatly appreciated. The current
codebase quite likely does everything alloc related correctly, so an
ASan error might be indicative of a snag in this branch instead of
Emacs itself (fingers crossed for the opposite, however :)).

Thanks,
Vibhav
-- 
Vibhav Pant
vibhavp@gmail.com
GPG: 7ED1 D48C 513C A024 BE3A  785F E3FB 28CB 6AB5 9598



             reply	other threads:[~2022-12-05 20:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 20:35 Vibhav Pant [this message]
2022-12-17 20:08 ` feature/asan-gc-poisoning: Better memory checks using AddressSanitizer Vibhav Pant
2022-12-17 20:24   ` Eli Zaretskii
2022-12-18 14:59     ` Vibhav Pant

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+T2Sh3CF34drunaKb89c2MXo4VS9HRPAqSKfm1+O8sV9RKPqQ@mail.gmail.com \
    --to=vibhavp@gmail.com \
    --cc=emacs-devel@gnu.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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).