[VM] error: ‘mallinfo mallinfo()’ is deprecated

Apparently libc 2.33 deprecates the mallinfo API in favor of the
new mallinfo2 API. The API stays nearly the same, only the types
in the struct containing the malloc information has changed.
Fields in the new API are size_t instead of int.

These changes would allow use of mallinfo2 as a build time
configuration on systems that have mallinfo2 available.

TEST=cq

BUG=

Change-Id: Ib074dea3fb1f7c971c2987d8117319bf073ce732
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218161
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
asiva 2021-12-08 00:25:10 +00:00 committed by Commit Bot
parent b06b60702b
commit 965333d95c
5 changed files with 23 additions and 0 deletions

View file

@ -132,6 +132,9 @@ config("dart_config") {
defines += [ "DART_USE_TCMALLOC" ]
include_dirs += [ "../third_party/tcmalloc/gperftools/src" ]
}
if (dart_use_mallinfo2) {
defines += [ "DART_USE_MALLINFO2" ]
}
if (dart_use_compressed_pointers) {
defines += [ "DART_COMPRESSED_POINTERS" ]

View file

@ -46,6 +46,10 @@ declare_args() {
# the VM enables this only for Linux builds.
dart_use_tcmalloc = false
# Whether to use mallinfo2 instead of mallinfo which is deprecated starting
# with libc 2.33
dart_use_mallinfo2 = false
# Whether to link Crashpad library for crash handling. Only supported on
# Windows for now.
dart_use_crashpad = false

View file

@ -341,7 +341,11 @@ bool MallocHooks::Active() {
bool MallocHooks::GetStats(intptr_t* used,
intptr_t* capacity,
const char** implementation) {
#if defined(DART_USE_MALLINFO2)
struct mallinfo2 info = mallinfo2();
#else
struct mallinfo info = mallinfo();
#endif // defined(DART_USE_MALLINFO2)
*used = info.uordblks;
*capacity = *used + info.fordblks;
*implementation = "tcmalloc";

View file

@ -70,7 +70,11 @@ bool MallocHooks::GetStats(intptr_t* used,
}
#endif
#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
#if defined(DART_USE_MALLINFO2)
struct mallinfo2 info = mallinfo2();
#else
struct mallinfo info = mallinfo();
#endif // defined(DART_USE_MALLINFO2)
*used = info.uordblks;
*capacity = *used + info.fordblks;
*implementation = "unknown";

View file

@ -215,6 +215,9 @@ def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash):
(gn_args['target_cpu'] != 'arm') and
sanitizer == 'none')
# Use mallinfo2 if specified on the command line
gn_args['dart_use_mallinfo2'] = args.use_mallinfo2
if gn_args['target_os'] == 'linux':
if gn_args['target_cpu'] == 'arm':
# Default to -mfloat-abi=hard and -mfpu=neon for arm on Linux as we're
@ -490,6 +493,11 @@ def AddCommonGnOptionArgs(parser):
'-s',
type=str,
help='Comma-separated list of arch=/path/to/sysroot mappings')
parser.add_argument('--use-mallinfo2',
help='Use mallinfo2 to collect malloc stats.',
default=False,
dest='use_mallinfo2',
action='store_true')
def AddCommonConfigurationArgs(parser):