[compiler-rt] r375296 - [hwasan] Remove system allocator fallback.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 18 15:36:25 PDT 2019
Author: eugenis
Date: Fri Oct 18 15:36:25 2019
New Revision: 375296
URL: http://llvm.org/viewvc/llvm-project?rev=375296&view=rev
Log:
[hwasan] Remove system allocator fallback.
Summary:
This has been an experiment with late malloc interposition, made
possible by a non-standard feature of the Android dynamic loader.
Reviewers: pcc, mmalcomson
Subscribers: srhines, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D69199
Removed:
compiler-rt/trunk/test/hwasan/TestCases/Posix/system-allocator-fallback.cpp
Modified:
compiler-rt/trunk/lib/hwasan/hwasan_allocator.cpp
compiler-rt/trunk/lib/hwasan/hwasan_allocator.h
compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cpp
Modified: compiler-rt/trunk/lib/hwasan/hwasan_allocator.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_allocator.cpp?rev=375296&r1=375295&r2=375296&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_allocator.cpp (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_allocator.cpp Fri Oct 18 15:36:25 2019
@@ -22,11 +22,6 @@
#include "hwasan_thread.h"
#include "hwasan_report.h"
-#if HWASAN_WITH_INTERCEPTORS
-DEFINE_REAL(void *, realloc, void *ptr, uptr size)
-DEFINE_REAL(void, free, void *ptr)
-#endif
-
namespace __hwasan {
static Allocator allocator;
@@ -301,14 +296,6 @@ void *hwasan_calloc(uptr nmemb, uptr siz
void *hwasan_realloc(void *ptr, uptr size, StackTrace *stack) {
if (!ptr)
return SetErrnoOnNull(HwasanAllocate(stack, size, sizeof(u64), false));
-
-#if HWASAN_WITH_INTERCEPTORS
- // A tag of 0 means that this is a system allocator allocation, so we must use
- // the system allocator to realloc it.
- if (!flags()->disable_allocator_tagging && GetTagFromPointer((uptr)ptr) == 0)
- return REAL(realloc)(ptr, size);
-#endif
-
if (size == 0) {
HwasanDeallocate(stack, ptr);
return nullptr;
@@ -381,13 +368,6 @@ int hwasan_posix_memalign(void **memptr,
}
void hwasan_free(void *ptr, StackTrace *stack) {
-#if HWASAN_WITH_INTERCEPTORS
- // A tag of 0 means that this is a system allocator allocation, so we must use
- // the system allocator to free it.
- if (!flags()->disable_allocator_tagging && GetTagFromPointer((uptr)ptr) == 0)
- return REAL(free)(ptr);
-#endif
-
return HwasanDeallocate(stack, ptr);
}
@@ -400,15 +380,6 @@ void __hwasan_enable_allocator_tagging()
}
void __hwasan_disable_allocator_tagging() {
-#if HWASAN_WITH_INTERCEPTORS
- // Allocator tagging must be enabled for the system allocator fallback to work
- // correctly. This means that we can't disable it at runtime if it was enabled
- // at startup since that might result in our deallocations going to the system
- // allocator. If tagging was disabled at startup we avoid this problem by
- // disabling the fallback altogether.
- CHECK(flags()->disable_allocator_tagging);
-#endif
-
atomic_store_relaxed(&hwasan_allocator_tagging_enabled, 0);
}
Modified: compiler-rt/trunk/lib/hwasan/hwasan_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_allocator.h?rev=375296&r1=375295&r2=375296&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_allocator.h (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_allocator.h Fri Oct 18 15:36:25 2019
@@ -13,7 +13,6 @@
#ifndef HWASAN_ALLOCATOR_H
#define HWASAN_ALLOCATOR_H
-#include "interception/interception.h"
#include "sanitizer_common/sanitizer_allocator.h"
#include "sanitizer_common/sanitizer_allocator_checks.h"
#include "sanitizer_common/sanitizer_allocator_interface.h"
@@ -26,11 +25,6 @@
#error Unsupported platform
#endif
-#if HWASAN_WITH_INTERCEPTORS
-DECLARE_REAL(void *, realloc, void *ptr, uptr size)
-DECLARE_REAL(void, free, void *ptr)
-#endif
-
namespace __hwasan {
struct Metadata {
Modified: compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cpp?rev=375296&r1=375295&r2=375296&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cpp (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_interceptors.cpp Fri Oct 18 15:36:25 2019
@@ -260,8 +260,6 @@ void InitializeInterceptors() {
#if !defined(__aarch64__)
INTERCEPT_FUNCTION(pthread_create);
#endif // __aarch64__
- INTERCEPT_FUNCTION(realloc);
- INTERCEPT_FUNCTION(free);
#endif
inited = 1;
Removed: compiler-rt/trunk/test/hwasan/TestCases/Posix/system-allocator-fallback.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/hwasan/TestCases/Posix/system-allocator-fallback.cpp?rev=375295&view=auto
==============================================================================
--- compiler-rt/trunk/test/hwasan/TestCases/Posix/system-allocator-fallback.cpp (original)
+++ compiler-rt/trunk/test/hwasan/TestCases/Posix/system-allocator-fallback.cpp (removed)
@@ -1,54 +0,0 @@
-// RUN: %clangxx %s -o %t -ldl
-// RUN: %clangxx_hwasan -shared %s -o %t.so -DSHARED_LIB -shared-libsan -Wl,-rpath,%compiler_rt_libdir
-// RUN: %env_hwasan_opts=disable_allocator_tagging=0 %run %t
-
-// The dynamic loader on Android O appears to have a bug where it crashes when
-// dlopening DF_1_GLOBAL libraries.
-// REQUIRES: android-28
-
-#include <stddef.h>
-
-// Test that allocations made by the system allocator can be realloc'd and freed
-// by the hwasan allocator.
-
-typedef void run_test_fn(void *(*system_malloc)(size_t size));
-
-#ifdef SHARED_LIB
-
-// Call the __sanitizer_ versions of these functions so that the test
-// doesn't require the Android dynamic loader.
-extern "C" void *__sanitizer_realloc(void *ptr, size_t size);
-extern "C" void __sanitizer_free(void *ptr);
-
-extern "C" run_test_fn run_test;
-void run_test(void *(*system_malloc)(size_t size)) {
- void *mem = system_malloc(64);
- mem = __sanitizer_realloc(mem, 128);
- __sanitizer_free(mem);
-}
-
-#else
-
-#include <dlfcn.h>
-#include <stdlib.h>
-#include <string>
-
-int main(int argc, char **argv) {
- std::string path = argv[0];
- path += ".so";
- void *lib = dlopen(path.c_str(), RTLD_NOW);
- if (!lib) {
- printf("error in dlopen(): %s\n", dlerror());
- return 1;
- }
-
- auto run_test = reinterpret_cast<run_test_fn *>(dlsym(lib, "run_test"));
- if (!run_test) {
- printf("failed dlsym\n");
- return 1;
- }
-
- run_test(malloc);
-}
-
-#endif
More information about the llvm-commits
mailing list