[all-commits] [llvm/llvm-project] e614d5: [compiler-rt] Avoid memintrinsic calls inserted by...

Marco Elver via All-commits all-commits at lists.llvm.org
Wed May 31 02:50:56 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e614d5667f6c6fc6c645587cb9aee1a058285454
  Author: Marco Elver <elver at google.com>
  Date:   2023-05-31 (Wed, 31 May 2023)

  Changed paths:
    M compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
    M compiler-rt/lib/hwasan/hwasan_interceptors.cpp
    M compiler-rt/lib/interception/tests/CMakeLists.txt
    M compiler-rt/lib/memprof/memprof_interceptors_memintrinsics.cpp
    M compiler-rt/lib/msan/msan_interceptors.cpp
    M compiler-rt/lib/sanitizer_common/CMakeLists.txt
    M compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
    M compiler-rt/lib/sanitizer_common/sanitizer_common_interface.inc
    M compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
    M compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
    A compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h
    M compiler-rt/lib/tsan/rtl/tsan_interceptors_memintrinsics.cpp
    A compiler-rt/test/asan/TestCases/Linux/check_memcpy.c
    A compiler-rt/test/msan/Linux/check_memcpy.c
    M compiler-rt/test/tsan/Linux/check_memcpy.c

  Log Message:
  [compiler-rt] Avoid memintrinsic calls inserted by the compiler

D135716 introduced -ftrivial-auto-var-init=pattern where supported.
Unfortunately this introduces unwanted memset() for large stack arrays,
as shown by the new tests added for asan and msan (tsan already had this

In general, the problem of compiler-inserted memintrinsic calls
(memset/memcpy/memmove) is not new to compiler-rt, and has been a
problem before.

To avoid introducing unwanted memintrinsic calls, we redefine
memintrinsics as __sanitizer_internal_mem* at the assembly level for
most source files automatically (where sanitizer_common_internal_defs.h
is included).

In few cases, redefining a symbol in this way causes issues for
interceptors, namely the memintrinsic interceptor themselves. For such
source files we have to selectively disable the redefinition.

Other alternatives have been considered, but simply do not work well in
the context of compiler-rt:

	1. Linker --wrap:  this does not work because --wrap only
	   applies to the final link, and would not apply when building
	   sanitizer static libraries.

	2. Changing references to memset() via objcopy:  this may work,
	   but due to the complexities of the build system, introducing
	   such a post-processing step for the right object files (in
	   particular object files defining memset cannot be touched)
	   seems infeasible.

The chosen solution works well (as shown by the tests). Other libraries
have chosen the same solution where nothing else works (see e.g. glibc's

Reviewed By: vitalybuka, dvyukov

Differential Revision: https://reviews.llvm.org/D151152

More information about the All-commits mailing list