public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH RFC 00/11] Add Memory Sanitizer support
@ 2023-02-06 22:25 Ilya Leoshkevich
  2023-02-06 22:25 ` [PATCH RFC 01/11] libdwfl: Fix debuginfod_client redefinition Ilya Leoshkevich
                   ` (11 more replies)
  0 siblings, 12 replies; 27+ messages in thread
From: Ilya Leoshkevich @ 2023-02-06 22:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Ilya Leoshkevich

Hi,

This series adds minimalistic support for Memory Sanitizer (MSan) [1].
MSan is compiler instrumentation for detecting accesses to
uninitialized memory.

The motivation behind this is to be able to link elfutils into projects
instrumented with MSan, since it essentially requires all the code
running in a process to be instrumented.

The goal is to provide a setup where elfutils is linked only with zlib
and most tests pass. Here is the description of the setup that I'm
using:

- LLVM with argp_parse() instrumentation [2].

- zlib-ng instrumented with MSan:

  git clone git@github.com:zlib-ng/zlib-ng.git
  cmake -DWITH_SANITIZER=Memory -DZLIB_COMPAT=ON -DWITH_GTEST=OFF \
        -DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/tmp/zlib-ng
  make install
  export CPATH=/tmp/zlib-ng/include
  export LIBRARY_PATH=/tmp/zlib-ng/lib

- Hack: zlib is used by a lot of system utilities, so adding
  MSan-instrumented zlib to LD_LIBRARY_PATH causes a lot of grief.
  Let elfutils test infrastructure add it there only for running
  tests:

  ln -s /tmp/zlib-ng/lib/libz.so.1 libelf/

- elfutils uses printf("%n"), so tweak MSan to unpoison the respective
  arguments. Also disable fast unwinding to get better backtraces:

  export MSAN_OPTIONS=check_printf=1,fast_unwind_on_malloc=0

- Minimal configuration of elfutils instrumented with MSan:

  autoreconf -i
  CC=clang ./configure --enable-maintainer-mode \
                       --enable-sanitize-memory --without-bzlib \
                       --without-lzma --without-zstd \
                       --disable-debuginfod --disable-libdebuginfod \
                       --disable-demangler

Results:

  ============================================================================
  Testsuite summary for elfutils 0.188
  ============================================================================
  # TOTAL: 235
  # PASS:  221
  # SKIP:  14
  # XFAIL: 0
  # FAIL:  0
  # XPASS: 0
  # ERROR: 0
  ============================================================================

The patches take care of the following:

- Fixing clang build.
- Adding small tweaks to get rid of false positives (no real issues
  were found, most likely because elfutils is already tested with
  valgrind).
- Dealing with "-self" tests, which now see MSan runtime compiled
  into elfutils binaries.
- MSan enablement itself.

[1] https://clang.llvm.org/docs/MemorySanitizer.html
[2] https://reviews.llvm.org/D143330

Best regards,
Ilya

Ilya Leoshkevich (11):
  libdwfl: Fix debuginfod_client redefinition
  libasm: Fix xdefault_pattern initialization
  printversion: Fix unused variable
  readelf: Fix set but not used parameter
  readelf: Fix set but not used variable
  Initialize reglocs for VMCOREINFO
  addr2line: Do not test demangling in run-addr2line-i-test.sh
  x86_64_return_value_location: Support lvalue and rvalue references
  configure: Use -fno-addrsig if possible
  configure: Add --disable-demangle
  configure: Add --enable-sanitize-memory

 backends/linux-core-note.c    |  1 +
 backends/x86_64_retval.c      |  2 ++
 configure.ac                  | 40 ++++++++++++++++++++++++++++++++++-
 debuginfod/Makefile.am        |  3 ++-
 lib/printversion.h            |  3 ++-
 libasm/Makefile.am            |  3 ++-
 libasm/asm_newscn.c           |  5 ++---
 libdw/Makefile.am             |  3 ++-
 libdwfl/debuginfod-client.c   |  2 +-
 libdwfl/libdwfl.h             |  5 +----
 libdwfl/libdwflP.h            |  4 ++--
 libelf/Makefile.am            |  3 ++-
 src/readelf.c                 |  3 +--
 tests/Makefile.am             | 10 ++++++++-
 tests/run-addr2line-i-test.sh | 14 ++++++------
 tests/run-readelf-self.sh     |  5 +++++
 tests/run-strip-reloc.sh      |  5 +++++
 tests/run-varlocs-self.sh     |  5 +++++
 18 files changed, 90 insertions(+), 26 deletions(-)

-- 
2.39.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2023-02-09 14:58 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-06 22:25 [PATCH RFC 00/11] Add Memory Sanitizer support Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 01/11] libdwfl: Fix debuginfod_client redefinition Ilya Leoshkevich
2023-02-07 19:22   ` Mark Wielaard
2023-02-07 19:47     ` Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 02/11] libasm: Fix xdefault_pattern initialization Ilya Leoshkevich
2023-02-07 19:41   ` Mark Wielaard
2023-02-07 19:49     ` Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 03/11] printversion: Fix unused variable Ilya Leoshkevich
2023-02-07 20:44   ` Mark Wielaard
2023-02-08 12:22     ` Ilya Leoshkevich
2023-02-09 14:04       ` Mark Wielaard
2023-02-09 14:57         ` Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 04/11] readelf: Fix set but not used parameter Ilya Leoshkevich
2023-02-08 16:52   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 05/11] readelf: Fix set but not used variable Ilya Leoshkevich
2023-02-08 17:09   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 06/11] Initialize reglocs for VMCOREINFO Ilya Leoshkevich
2023-02-08 17:27   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 07/11] addr2line: Do not test demangling in run-addr2line-i-test.sh Ilya Leoshkevich
2023-02-08 18:15   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 08/11] x86_64_return_value_location: Support lvalue and rvalue references Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 09/11] configure: Use -fno-addrsig if possible Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 10/11] configure: Add --disable-demangle Ilya Leoshkevich
2023-02-08 18:14   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 11/11] configure: Add --enable-sanitize-memory Ilya Leoshkevich
2023-02-07 19:05 ` [PATCH RFC 00/11] Add Memory Sanitizer support Mark Wielaard
2023-02-07 19:46   ` Ilya Leoshkevich

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