ClickHouse/src/Common/malloc.cpp

49 lines
1.5 KiB
C++
Raw Normal View History

2019-12-05 11:22:43 +00:00
#if defined(OS_LINUX)
#include <stdlib.h>
/// Interposing these symbols explicitly. The idea works like this: malloc.cpp compiles to a
/// dedicated object (namely clickhouse_malloc.o), and it will show earlier in the link command
/// than malloc libs like libjemalloc.a. As a result, these symbols get picked in time right after.
2019-12-15 06:34:43 +00:00
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
2019-12-05 11:22:43 +00:00
extern "C"
{
void *malloc(size_t size);
void free(void *ptr);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
int posix_memalign(void **memptr, size_t alignment, size_t size);
void *aligned_alloc(size_t alignment, size_t size);
void *valloc(size_t size);
void *memalign(size_t alignment, size_t size);
2021-10-15 21:12:51 +00:00
#if !defined(USE_MUSL)
2019-12-05 11:22:43 +00:00
void *pvalloc(size_t size);
2021-10-15 21:12:51 +00:00
#endif
2019-12-05 11:22:43 +00:00
}
2019-12-15 06:34:43 +00:00
#pragma GCC diagnostic pop
2019-12-05 11:22:43 +00:00
template<typename T>
inline void ignore(T x __attribute__((unused)))
{
}
static void dummyFunctionForInterposing() __attribute__((used));
static void dummyFunctionForInterposing()
{
void* dummy;
2020-03-18 18:26:40 +00:00
/// Suppression for PVS-Studio and clang-tidy.
free(nullptr); // -V575 NOLINT
ignore(malloc(0)); // -V575 NOLINT
ignore(calloc(0, 0)); // -V575 NOLINT
ignore(realloc(nullptr, 0)); // -V575 NOLINT
ignore(posix_memalign(&dummy, 0, 0)); // -V575 NOLINT
ignore(aligned_alloc(1, 0)); // -V575 NOLINT
2020-03-18 18:26:40 +00:00
ignore(valloc(0)); // -V575 NOLINT
ignore(memalign(0, 0)); // -V575 NOLINT
2021-10-15 21:12:51 +00:00
#if !defined(USE_MUSL)
2020-03-18 18:26:40 +00:00
ignore(pvalloc(0)); // -V575 NOLINT
2021-10-15 21:12:51 +00:00
#endif
2019-12-05 11:22:43 +00:00
}
#endif