From ea35d14585746056e0f3542103a0f30619766cb2 Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Sat, 14 Sep 2024 17:24:20 -0400 Subject: [PATCH] stop checking unused malloc_hook "subsection" Originally at Google they had to do 2 subsections for hookable functions because of some linking detais (in bazel infrastructure they still do different libraries as .so-s for tests). So "generic" hooks (such as mmap/sbrk) were in malloc_hook section and tcmalloc's were/are in google_malloc. Since those are different bazel/blaze libraries. And we kept this distinction simply because no-one bothered to undo it, despite us never needing it. We recently refactored mmap/sbrk hooking. And we don't use section stuff anymore for those hooks. And so there are no malloc_hook anymore. And so we were getting bogus and useless warnings about empty section. So lets avoid this. --- src/gperftools/malloc_hook.h | 2 +- src/malloc_hook.cc | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/gperftools/malloc_hook.h b/src/gperftools/malloc_hook.h index ab655f6..565a291 100644 --- a/src/gperftools/malloc_hook.h +++ b/src/gperftools/malloc_hook.h @@ -55,7 +55,7 @@ // // CAVEAT: If you add new MallocHook::Invoke* calls then those calls must be // directly in the code of the (de)allocation function that is provided to the -// user and that function must have an ATTRIBUTE_SECTION(malloc_hook) attribute. +// user and that function must have an ATTRIBUTE_SECTION(google_malloc) attribute. // // Note: the Invoke*Hook() functions are defined in malloc_hook-inl.h. If you // need to invoke a hook (which you shouldn't unless you're part of tcmalloc), diff --git a/src/malloc_hook.cc b/src/malloc_hook.cc index 96d93b2..afeaf3f 100644 --- a/src/malloc_hook.cc +++ b/src/malloc_hook.cc @@ -320,9 +320,6 @@ void MallocHook::InvokeDeleteHookSlow(const void* p) { DEFINE_ATTRIBUTE_SECTION_VARS(google_malloc); DECLARE_ATTRIBUTE_SECTION_VARS(google_malloc); // actual functions are in debugallocation.cc or tcmalloc.cc -DEFINE_ATTRIBUTE_SECTION_VARS(malloc_hook); -DECLARE_ATTRIBUTE_SECTION_VARS(malloc_hook); - // actual functions are in this file, malloc_hook.cc, and low_level_alloc.cc #define ADDR_IN_ATTRIBUTE_SECTION(addr, name) \ (reinterpret_cast(ATTRIBUTE_SECTION_START(name)) <= \ @@ -334,8 +331,7 @@ DECLARE_ATTRIBUTE_SECTION_VARS(malloc_hook); // that calls one of our hooks via MallocHook:Invoke*. // A helper for GetCallerStackTrace. static inline bool InHookCaller(const void* caller) { - return ADDR_IN_ATTRIBUTE_SECTION(caller, google_malloc) || - ADDR_IN_ATTRIBUTE_SECTION(caller, malloc_hook); + return ADDR_IN_ATTRIBUTE_SECTION(caller, google_malloc); // We can use one section for everything except tcmalloc_or_debug // due to its special linkage mode, which prevents merging of the sections. } @@ -352,12 +348,6 @@ static inline void CheckInHookCaller() { RAW_LOG(ERROR, "google_malloc section is missing, " "thus InHookCaller is broken!"); } - INIT_ATTRIBUTE_SECTION_VARS(malloc_hook); - if (ATTRIBUTE_SECTION_START(malloc_hook) == - ATTRIBUTE_SECTION_STOP(malloc_hook)) { - RAW_LOG(ERROR, "malloc_hook section is missing, " - "thus InHookCaller is broken!"); - } checked_sections = true; } }