Skip to content

Commit

Permalink
Revert "[compiler-rt] Avoid memintrinsic calls inserted by the compiler"
Browse files Browse the repository at this point in the history
This reverts commit 4369de7.

Fails on Mac OS with "sanitizer_libc.cpp:109:5: error: aliases are not
supported on darwin".
  • Loading branch information
melver committed May 31, 2023
1 parent fc8acb5 commit 8e728ad
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 93 deletions.
2 changes: 0 additions & 2 deletions compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// ASan versions of memcpy, memmove, and memset.
//===---------------------------------------------------------------------===//

#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS

#include "asan_interceptors_memintrinsics.h"

#include "asan_interceptors.h"
Expand Down
2 changes: 0 additions & 2 deletions compiler-rt/lib/hwasan/hwasan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// sanitizer_common/sanitizer_common_interceptors.h
//===----------------------------------------------------------------------===//

#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS

#include "hwasan.h"
#include "hwasan_allocator.h"
#include "hwasan_checks.h"
Expand Down
1 change: 0 additions & 1 deletion compiler-rt/lib/interception/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ set(INTERCEPTION_TEST_CFLAGS_COMMON
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
-I${COMPILER_RT_SOURCE_DIR}/lib/interception
-DSANITIZER_COMMON_NO_REDEFINE_BUILTINS
-fno-rtti
-O2
-Werror=sign-compare)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// MemProf versions of memcpy, memmove, and memset.
//===---------------------------------------------------------------------===//

#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS

#include "memprof_interceptors_memintrinsics.h"

#include "memprof_interceptors.h"
Expand Down
2 changes: 0 additions & 2 deletions compiler-rt/lib/msan/msan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// sanitizer_common/sanitizer_common_interceptors.h
//===----------------------------------------------------------------------===//

#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS

#include "interception/interception.h"
#include "msan.h"
#include "msan_chained_origin_depot.h"
Expand Down
1 change: 0 additions & 1 deletion compiler-rt/lib/sanitizer_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ set(SANITIZER_IMPL_HEADERS
sanitizer_procmaps.h
sanitizer_ptrauth.h
sanitizer_quarantine.h
sanitizer_redefine_builtins.h
sanitizer_report_decorator.h
sanitizer_ring_buffer.h
sanitizer_signal_interceptors.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
// Memintrinsic function interceptors for tools like AddressSanitizer,
// ThreadSanitizer, MemorySanitizer, etc.
//
// These interceptors are part of the common interceptors, but separated out so
// that implementations may add them, if necessary, to a separate source file
// that should define SANITIZER_COMMON_NO_REDEFINE_BUILTINS at the top.
//
// This file should be included into the tool's memintrinsic interceptor file,
// which has to define its own macros:
// COMMON_INTERCEPTOR_ENTER
Expand All @@ -24,10 +20,6 @@
// COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED
//===----------------------------------------------------------------------===//

#ifdef SANITIZER_REDEFINE_BUILTINS_H
#error "Define SANITIZER_COMMON_NO_REDEFINE_BUILTINS in .cpp file"
#endif

#include "interception/interception.h"
#include "sanitizer_platform_interceptors.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,3 @@ INTERFACE_FUNCTION(__sanitizer_purge_allocator)
INTERFACE_FUNCTION(__sanitizer_print_memory_profile)
INTERFACE_WEAK_FUNCTION(__sanitizer_free_hook)
INTERFACE_WEAK_FUNCTION(__sanitizer_malloc_hook)
// Memintrinsic functions.
INTERFACE_FUNCTION(__sanitizer_internal_memcpy)
INTERFACE_FUNCTION(__sanitizer_internal_memmove)
INTERFACE_FUNCTION(__sanitizer_internal_memset)
1 change: 0 additions & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define SANITIZER_DEFS_H

#include "sanitizer_platform.h"
#include "sanitizer_redefine_builtins.h"

#ifndef SANITIZER_DEBUG
# define SANITIZER_DEBUG 0
Expand Down
22 changes: 3 additions & 19 deletions compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
// run-time libraries. See sanitizer_libc.h for details.
//===----------------------------------------------------------------------===//

// Do not redefine builtins; this file is defining the builtin replacements.
#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS

#include "sanitizer_allocator_internal.h"
#include "sanitizer_common.h"
#include "sanitizer_libc.h"
Expand Down Expand Up @@ -49,19 +46,15 @@ int internal_memcmp(const void* s1, const void* s2, uptr n) {
return 0;
}

extern "C" {
SANITIZER_INTERFACE_ATTRIBUTE void *__sanitizer_internal_memcpy(void *dest,
const void *src,
uptr n) {
void *internal_memcpy(void *dest, const void *src, uptr n) {
char *d = (char*)dest;
const char *s = (const char *)src;
for (uptr i = 0; i < n; ++i)
d[i] = s[i];
return dest;
}

SANITIZER_INTERFACE_ATTRIBUTE void *__sanitizer_internal_memmove(
void *dest, const void *src, uptr n) {
void *internal_memmove(void *dest, const void *src, uptr n) {
char *d = (char*)dest;
const char *s = (const char *)src;
sptr i, signed_n = (sptr)n;
Expand All @@ -79,8 +72,7 @@ SANITIZER_INTERFACE_ATTRIBUTE void *__sanitizer_internal_memmove(
return dest;
}

SANITIZER_INTERFACE_ATTRIBUTE void *__sanitizer_internal_memset(void *s, int c,
uptr n) {
void *internal_memset(void* s, int c, uptr n) {
// Optimize for the most performance-critical case:
if ((reinterpret_cast<uptr>(s) % 16) == 0 && (n % 16) == 0) {
u64 *p = reinterpret_cast<u64*>(s);
Expand All @@ -103,14 +95,6 @@ SANITIZER_INTERFACE_ATTRIBUTE void *__sanitizer_internal_memset(void *s, int c,
}
return s;
}
} // extern "C"

void *internal_memcpy(void *dest, const void *src, uptr n)
ALIAS(__sanitizer_internal_memcpy);
void *internal_memmove(void *dest, const void *src, uptr n)
ALIAS(__sanitizer_internal_memmove);
void *internal_memset(void *s, int c, uptr n)
ALIAS(__sanitizer_internal_memset);

uptr internal_strcspn(const char *s, const char *reject) {
uptr i;
Expand Down
27 changes: 0 additions & 27 deletions compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h

This file was deleted.

2 changes: 0 additions & 2 deletions compiler-rt/lib/tsan/rtl/tsan_interceptors_memintrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
//
//===----------------------------------------------------------------------===//

#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS

#include "tsan_interceptors.h"
#include "tsan_interface.h"

Expand Down
4 changes: 1 addition & 3 deletions compiler-rt/lib/ubsan_minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ set(UBSAN_MINIMAL_SOURCES

include_directories(..)

set(UBSAN_CFLAGS
${SANITIZER_COMMON_CFLAGS}
-DSANITIZER_COMMON_NO_REDEFINE_BUILTINS)
set(UBSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
append_rtti_flag(OFF UBSAN_CFLAGS)

set(UBSAN_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
Expand Down
8 changes: 0 additions & 8 deletions compiler-rt/test/asan/TestCases/Linux/check_memcpy.c

This file was deleted.

8 changes: 0 additions & 8 deletions compiler-rt/test/msan/Linux/check_memcpy.c

This file was deleted.

13 changes: 10 additions & 3 deletions compiler-rt/test/tsan/Linux/check_memcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
// This could fail if using a static libunwind because that static libunwind
// could be uninstrumented and contain memcpy/memmove calls not intercepted by
// tsan.
// REQUIRES: shared_unwind, x86_64-target-arch
// REQUIRES: shared_unwind

// RUN: %clang_tsan -O1 %s -o %t
// RUN: llvm-objdump -d -l %t | FileCheck --implicit-check-not="{{(callq|jmpq) .*<(__interceptor_.*)?mem(cpy|set|move)>}}" %s
// RUN: llvm-objdump -d -l %t | FileCheck %s

int main() {
return 0;
}

// CHECK-NOT: callq {{.*<(__interceptor_)?mem(cpy|set)>}}
// tail calls:
// CHECK-NOT: jmpq {{.*<(__interceptor_)?mem(cpy|set)>}}

int main() { return 0; }

0 comments on commit 8e728ad

Please sign in to comment.