summaryrefslogtreecommitdiffstats
path: root/tools/valgrind/intercept_tcmalloc.patch
blob: 3f4755673019e18af03640c9d203712c958ba036 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Index: coregrind/m_replacemalloc/vg_replace_malloc.c
===================================================================
--- coregrind/m_replacemalloc/vg_replace_malloc.c	(revision 10880)
+++ coregrind/m_replacemalloc/vg_replace_malloc.c	(working copy)
@@ -193,6 +193,18 @@
 // malloc
 ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, malloc,      malloc);
 ALLOC_or_NULL(VG_Z_LIBC_SONAME,      malloc,      malloc);
+// Handle libtcmalloc's malloc() function.
+// Similar interceptors are added below to handle other libtcmalloc
+// allocation/deallocation functions.
+// soname=NONE means that a user's allocation function is intercepted.
+ALLOC_or_NULL(NONE,                  malloc,      malloc);
+// Bash has sh_malloc() and sh_free() along with standard malloc() and free().
+// Sometimes these functions are called inconsistently (e.g. free() after
+// sh_malloc()). To deal with this we have to intercept the sh_*() functions
+// as well.
+ALLOC_or_NULL(NONE,                  sh_malloc,      malloc);
+// Handle Python's malloc.
+ALLOC_or_NULL(NONE,                  PyObject_Malloc,      malloc);
 #if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
 ALLOC_or_NULL(VG_Z_LIBC_SONAME,      malloc_common, malloc);
 #elif defined(VGO_darwin)
@@ -205,20 +217,24 @@
 // operator new(unsigned int), not mangled (for gcc 2.96)
 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  builtin_new,    __builtin_new);
 ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       builtin_new,    __builtin_new);
+ALLOC_or_BOMB(NONE,                   builtin_new,    __builtin_new);
 
 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  __builtin_new,  __builtin_new);
 ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       __builtin_new,  __builtin_new);
+ALLOC_or_BOMB(NONE,                   __builtin_new,  __builtin_new);
 
 // operator new(unsigned int), GNU mangling
 #if VG_WORDSIZE == 4
  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj,          __builtin_new);
  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znwj,          __builtin_new);
+ ALLOC_or_BOMB(NONE,                  _Znwj,          __builtin_new);
 #endif
 
 // operator new(unsigned long), GNU mangling
 #if VG_WORDSIZE == 8 || defined(VGP_ppc32_aix5) || defined(VGO_darwin)
  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm,          __builtin_new);
  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znwm,          __builtin_new);
+ ALLOC_or_BOMB(NONE,                  _Znwm,          __builtin_new);
 #endif
 
 // operator new(unsigned long), ARM/cfront mangling
@@ -233,12 +249,14 @@
 #if VG_WORDSIZE == 4
  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t,  __builtin_new);
  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnwjRKSt9nothrow_t,  __builtin_new);
+ ALLOC_or_NULL(NONE,                  _ZnwjRKSt9nothrow_t,  __builtin_new);
 #endif
 
 // operator new(unsigned long, std::nothrow_t const&), GNU mangling
 #if VG_WORDSIZE == 8 || defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) || defined(VGO_darwin)
  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t,  __builtin_new);
  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnwmRKSt9nothrow_t,  __builtin_new);
+ ALLOC_or_NULL(NONE,                  _ZnwmRKSt9nothrow_t,  __builtin_new);
 #endif
 
 // operator new(unsigned long, std::nothrow_t const&), ARM/cfront mangling
@@ -252,17 +270,20 @@
 // operator new[](unsigned int), not mangled (for gcc 2.96)
 ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  __builtin_vec_new, __builtin_vec_new );
 ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       __builtin_vec_new, __builtin_vec_new );
+ALLOC_or_BOMB(NONE,                   __builtin_vec_new, __builtin_vec_new );
 
 // operator new[](unsigned int), GNU mangling
 #if VG_WORDSIZE == 4
  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj,             __builtin_vec_new );
  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znaj,             __builtin_vec_new );
+ ALLOC_or_BOMB(NONE,                  _Znaj,             __builtin_vec_new );
 #endif
 
 // operator new[](unsigned long), GNU mangling
 #if VG_WORDSIZE == 8 || defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) || defined(VGO_darwin)
  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam,             __builtin_vec_new );
  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znam,             __builtin_vec_new );
+ ALLOC_or_BOMB(NONE,                  _Znam,             __builtin_vec_new );
 #endif
 
 // operator new[](unsigned long), ARM/cfront mangling
@@ -277,12 +298,14 @@
 #if VG_WORDSIZE == 4
  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnajRKSt9nothrow_t, __builtin_vec_new );
+ ALLOC_or_NULL(NONE,                  _ZnajRKSt9nothrow_t, __builtin_vec_new );
 #endif
 
 // operator new[](unsigned long, std::nothrow_t const&), GNU mangling
 #if VG_WORDSIZE == 8 || defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) || defined(VGO_darwin)
  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnamRKSt9nothrow_t, __builtin_vec_new );
+ ALLOC_or_NULL(NONE,                  _ZnamRKSt9nothrow_t, __builtin_vec_new );
 #endif
 
 // operator new [](unsigned long, std::nothrow_t const&), ARM/cfront mangling
@@ -323,6 +346,9 @@
 // free
 FREE(VG_Z_LIBSTDCXX_SONAME,  free,                 free );
 FREE(VG_Z_LIBC_SONAME,       free,                 free );
+FREE(NONE,                   free,                 free );
+FREE(NONE,                   sh_free,              free );
+FREE(NONE,                   PyObject_Free,        free );
 #if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
 FREE(VG_Z_LIBC_SONAME,       free_common,          free );
 #elif defined(VGO_darwin)
@@ -335,16 +361,20 @@
 // cfree
 FREE(VG_Z_LIBSTDCXX_SONAME,  cfree,                free );
 FREE(VG_Z_LIBC_SONAME,       cfree,                free );
+FREE(NONE,                   cfree,                free );
+FREE(NONE,                   sh_cfree,             free );
 
 
 /*---------------------- delete ----------------------*/
 // operator delete(void*), not mangled (for gcc 2.96)
 FREE(VG_Z_LIBSTDCXX_SONAME,   __builtin_delete,     __builtin_delete );
 FREE(VG_Z_LIBC_SONAME,        __builtin_delete,     __builtin_delete );
+FREE(NONE,                    __builtin_delete,     __builtin_delete );
 
 // operator delete(void*), GNU mangling
 FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdlPv,               __builtin_delete );
 FREE(VG_Z_LIBC_SONAME,       _ZdlPv,               __builtin_delete );
+FREE(NONE,                   _ZdlPv,               __builtin_delete );
 
 // operator delete(void*), ARM/cfront mangling
 #if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
@@ -357,16 +387,19 @@
 // operator delete(void*, std::nothrow_t const&), GNU mangling
 FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t,  __builtin_delete );
 FREE(VG_Z_LIBC_SONAME,      _ZdlPvRKSt9nothrow_t,  __builtin_delete );
+FREE(NONE,                  _ZdlPvRKSt9nothrow_t,  __builtin_delete );
 
 
 /*---------------------- delete [] ----------------------*/
 // operator delete[](void*), not mangled (for gcc 2.96)
 FREE(VG_Z_LIBSTDCXX_SONAME,   __builtin_vec_delete, __builtin_vec_delete );
 FREE(VG_Z_LIBC_SONAME,        __builtin_vec_delete, __builtin_vec_delete );
+FREE(NONE,                    __builtin_vec_delete, __builtin_vec_delete );
 
 // operator delete[](void*), GNU mangling
 FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdaPv,               __builtin_vec_delete );
 FREE(VG_Z_LIBC_SONAME,       _ZdaPv,               __builtin_vec_delete );
+FREE(NONE,                   _ZdaPv,               __builtin_vec_delete );
 
 // operator delete[](void*), ARM/cfront mangling
 #if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
@@ -379,6 +412,7 @@
 // operator delete[](void*, std::nothrow_t const&), GNU mangling
 FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
 FREE(VG_Z_LIBC_SONAME,       _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
+FREE(NONE,                   _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
 
 
 /*---------------------- calloc ----------------------*/
@@ -416,6 +450,8 @@
    }
 
 CALLOC(VG_Z_LIBC_SONAME, calloc);
+CALLOC(NONE,             calloc);
+CALLOC(NONE,             sh_calloc);
 #if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
 CALLOC(VG_Z_LIBC_SONAME, calloc_common);
 #elif defined(VGO_darwin)
@@ -474,6 +510,9 @@
    }
 
 REALLOC(VG_Z_LIBC_SONAME, realloc);
+REALLOC(NONE,             realloc);
+REALLOC(NONE,             sh_realloc);
+REALLOC(NONE,             PyObject_Realloc);
 #if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
 REALLOC(VG_Z_LIBC_SONAME, realloc_common);
 #elif defined(VGO_darwin)
@@ -530,6 +569,8 @@
    }
 
 MEMALIGN(VG_Z_LIBC_SONAME, memalign);
+MEMALIGN(NONE,             memalign);
+MEMALIGN(NONE,          sh_memalign);
 #if defined(VGO_darwin)
 ZONEMEMALIGN(VG_Z_LIBC_SONAME, malloc_zone_memalign);
 #endif
@@ -572,6 +613,8 @@
    }
 
 VALLOC(VG_Z_LIBC_SONAME, valloc);
+VALLOC(NONE,             valloc);
+VALLOC(NONE,          sh_valloc);
 #if defined(VGO_darwin)
 ZONEVALLOC(VG_Z_LIBC_SONAME, malloc_zone_valloc);
 #endif
@@ -592,6 +635,7 @@
    }
 
 MALLOPT(VG_Z_LIBC_SONAME, mallopt);
+MALLOPT(NONE,             mallopt);
 
 
 /*---------------------- malloc_trim ----------------------*/
@@ -628,6 +672,7 @@
    }
 
 MALLOC_TRIM(VG_Z_LIBC_SONAME, malloc_trim);
+MALLOC_TRIM(NONE,             malloc_trim);
 
 
 /*---------------------- posix_memalign ----------------------*/
@@ -658,6 +703,7 @@
    }
 
 POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
+POSIX_MEMALIGN(NONE,             posix_memalign);
 #if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
 /* 27 Nov 07: it appears that xlc links into executables, a
    posix_memalign, which calls onwards to memalign_common, with the
@@ -688,6 +734,7 @@
 
 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
 MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
+MALLOC_USABLE_SIZE(NONE,             malloc_size);
 
 
 /*---------------------- (unimplemented) ----------------------*/
@@ -742,6 +789,7 @@
    }
 
 MALLINFO(VG_Z_LIBC_SONAME, mallinfo);
+MALLINFO(NONE,             mallinfo);
 
 
 #if defined(VGO_darwin)