aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/binutils/binutils/0019-Fix-gold-to-use-mallinfo2-if-available-instead-of-de.patch
blob: d6e4e25b3d187931f1914f81087a1acc15e06630 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 5a47430c1dc7b998b9db3ca9e4c93394c7a9972e Mon Sep 17 00:00:00 2001
From: Duncan Simpson <dr.duncan.p.simpson@gmail.com>
Date: Fri, 19 Mar 2021 14:22:08 -0700
Subject: [PATCH] Fix gold to use mallinfo2 if available instead of deprecated
 mallinfo.

gold/
	PR gold/26585
	* configure.ac: Add check for mallinfo2.
	* configure: Regenerate.
	* main.cc (main): Use mallinfo2 if available.

Upstream-Status: Backport [4ee60495054 Fix gold to use mallinfo2 if available instead of deprecated mallinfo.]

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 gold/configure    | 2 +-
 gold/configure.ac | 2 +-
 gold/main.cc      | 9 +++++++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/gold/configure b/gold/configure
index e264a65ac3c..b9f062b68eb 100755
--- a/gold/configure
+++ b/gold/configure
@@ -9967,7 +9967,7 @@ case "$ac_cv_search_dlopen" in
 esac
 
 
-for ac_func in mallinfo posix_fallocate fallocate readv sysconf times mkdtemp
+for ac_func in mallinfo mallinfo2 posix_fallocate fallocate readv sysconf times mkdtemp
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/gold/configure.ac b/gold/configure.ac
index eed45664093..1716a779416 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -636,7 +636,7 @@ case "$ac_cv_search_dlopen" in
 esac
 AC_SUBST(DLOPEN_LIBS)
 
-AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times mkdtemp)
+AC_CHECK_FUNCS(mallinfo mallinfo2 posix_fallocate fallocate readv sysconf times mkdtemp)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
 # Use of ::std::tr1::unordered_map::rehash causes undefined symbols
diff --git a/gold/main.cc b/gold/main.cc
index ea77ca3ebbe..89bc40b22af 100644
--- a/gold/main.cc
+++ b/gold/main.cc
@@ -25,7 +25,7 @@
 #include <cstdio>
 #include <cstring>
 
-#ifdef HAVE_MALLINFO
+#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
 #include <malloc.h>
 #endif
 
@@ -290,11 +290,16 @@ main(int argc, char** argv)
               elapsed.sys / 1000, (elapsed.sys % 1000) * 1000,
               elapsed.wall / 1000, (elapsed.wall % 1000) * 1000);
 
-#ifdef HAVE_MALLINFO
+#if defined(HAVE_MALLINFO2)
+      struct mallinfo m = mallinfo2();
+      fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
+	      program_name, static_cast<long long>(m.arena));
+#elif defined(HAVE_MALLINFO)
       struct mallinfo m = mallinfo();
       fprintf(stderr, _("%s: total space allocated by malloc: %lld bytes\n"),
 	      program_name, static_cast<long long>(m.arena));
 #endif
+
       File_read::print_stats();
       Archive::print_stats();
       Lib_group::print_stats();