musl does not implement mallinfo()/mallinfo2() (or rather, malloc-ng, musl's allocator, doesn't) -- diff --git a/base/trace_event/malloc_dump_provider.cc b/base/trace_event/malloc_dump_provider.cc index 6e64aed..d962ae2 100644 --- a/base/trace_event/malloc_dump_provider.cc +++ b/base/trace_event/malloc_dump_provider.cc @@ -198,7 +198,6 @@ void ReportMallinfoStats(ProcessMemoryDump* pmd, #define MALLINFO2_FOUND_IN_LIBC struct mallinfo2 info = mallinfo2(); #endif -#endif // defined(__GLIBC__) && defined(__GLIBC_PREREQ) #if !defined(MALLINFO2_FOUND_IN_LIBC) struct mallinfo info = mallinfo(); #endif @@ -220,6 +219,7 @@ void ReportMallinfoStats(ProcessMemoryDump* pmd, MemoryAllocatorDump::kUnitsBytes, total_allocated_size); } +#endif // defined(__GLIBC__) && defined(__GLIBC_PREREQ) } #endif @@ -358,7 +358,7 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, &allocated_objects_count); #elif BUILDFLAG(IS_FUCHSIA) // TODO(fuchsia): Port, see https://crbug.com/706592. -#else +#elif defined(__GLIBC__) ReportMallinfoStats(/*pmd=*/nullptr, &total_virtual_size, &resident_size, &allocated_objects_size, &allocated_objects_count); #endif diff --git a/base/process/process_metrics_posix.cc b/base/process/process_metrics_posix.cc index 9a25ea7..eb294ba 100644 --- a/base/process/process_metrics_posix.cc +++ b/base/process/process_metrics_posix.cc @@ -106,7 +106,7 @@ void IncreaseFdLimitTo(unsigned int max_descriptors) { #endif // !BUILDFLAG(IS_FUCHSIA) -#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) +#if (BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) namespace { size_t GetMallocUsageMallinfo() { @@ -124,7 +124,7 @@ size_t GetMallocUsageMallinfo() { } } // namespace -#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || +#endif // (BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || BUILDFLAG(IS_CHROMEOS) || // BUILDFLAG(IS_ANDROID) size_t ProcessMetrics::GetMallocUsage() { @@ -132,9 +132,9 @@ size_t ProcessMetrics::GetMallocUsage() { malloc_statistics_t stats = {0}; malloc_zone_statistics(nullptr, &stats); return stats.size_in_use; -#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) +#elif (BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) return GetMallocUsageMallinfo(); -#elif BUILDFLAG(IS_FUCHSIA) +#else // TODO(fuchsia): Not currently exposed. https://crbug.com/735087. return 0; #endif diff --git a/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc b/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc index 9a4428e..e3c2379 100644 --- a/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc +++ b/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc @@ -38,7 +38,7 @@ bool MemoryUsage::IsSupported() { MemoryUsage GetMemoryUsage() { MemoryUsage result; -#ifdef __linux__ +#if defined(__linux__) && defined(__GLIBC__) rusage res; if (getrusage(RUSAGE_SELF, &res) == 0) { result.mem_footprint_kb = res.ru_maxrss; --- ./third_party/swiftshader/third_party/llvm-subzero/lib/Support/Unix/Process.inc.orig +++ ./third_party/swiftshader/third_party/llvm-subzero/lib/Support/Unix/Process.inc @@ -86,11 +86,11 @@ } size_t Process::GetMallocUsage() { -#if defined(HAVE_MALLINFO2) +#if defined(HAVE_MALLINFO2) && defined(__GLIBC__) struct mallinfo2 mi; mi = ::mallinfo2(); return mi.uordblks; -#elif defined(HAVE_MALLINFO) +#elif defined(HAVE_MALLINFO) && defined(__GLIBC__) struct mallinfo mi; mi = ::mallinfo(); return mi.uordblks; diff --git a/third_party/swiftshader/third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h b/third_party/swiftshader/third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h index 7392898..0bf7c4a 100644 --- a/third_party/swiftshader/third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h +++ b/third_party/swiftshader/third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h @@ -125,7 +125,9 @@ /* #undef HAVE_MALLCTL */ /* Define to 1 if you have the `mallinfo' function. */ +#if defined(__GLIBC__) #define HAVE_MALLINFO 1 +#endif /* Define to 1 if you have the header file. */ /* #undef HAVE_MALLOC_MALLOC_H */ diff --git a/base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.cc b/base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.cc index 4f7a87d..016a4bb 100644 --- a/base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.cc +++ b/base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.cc @@ -744,7 +744,7 @@ SHIM_ALWAYS_EXPORT int mallopt(int cmd, int value) __THROW { #endif // !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_ANDROID) -#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) +#if 0 SHIM_ALWAYS_EXPORT struct mallinfo mallinfo(void) __THROW { partition_alloc::SimplePartitionStatsDumper allocator_dumper; Allocator()->DumpStats("malloc", true, &allocator_dumper); diff --git a/base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc_unittest.cc b/base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc_unittest.cc index 0dcc19c..c0daee0 100644 --- a/base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc_unittest.cc +++ b/base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc_unittest.cc @@ -25,7 +25,7 @@ namespace allocator_shim::internal { #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) // Platforms on which we override weak libc symbols. -#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) +#if (BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || BUILDFLAG(IS_CHROMEOS) PA_NOINLINE void FreeForTest(void* data) { free(data);