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
|
Fix temacs segmentation fault due to endless calloc loop.
https://bugs.gentoo.org/609680
Backported from Emacs 25:
commit 4b1436b702d56eedd27a0777fc7232cdfb7ac4f6
Author: Wolfgang Jenkner <wjenkner@inode.at>
Date: Sat Dec 26 12:12:02 2015 -0800
Always define gmalloc etc. in src/gmalloc.c
This is a work-around to prevent the compiler from using semantic
knowledge about malloc for optimization purposes. E.g., gcc 5.2
with -O2 replaces most of calloc's definition by a call to calloc;
see Bug#22085.
* src/gmalloc.c [!HYBRID_MALLOC] (malloc, realloc, calloc)
(aligned_alloc, free): Do not undef. Instead, define these as
functions (perhaps renamed to gmalloc etc.) in terms of gmalloc etc.
--- emacs-24.5-orig/src/gmalloc.c
+++ emacs-24.5/src/gmalloc.c
@@ -42,6 +42,16 @@
extern void emacs_abort (void);
#endif
+#undef malloc
+#undef realloc
+#undef calloc
+#undef free
+#define malloc gmalloc
+#define realloc grealloc
+#define calloc gcalloc
+#define aligned_alloc galigned_alloc
+#define free gfree
+
#ifdef __cplusplus
extern "C"
{
@@ -1747,6 +1757,42 @@
return aligned_alloc (pagesize, size);
}
+#undef malloc
+#undef realloc
+#undef calloc
+#undef aligned_alloc
+#undef free
+
+void *
+malloc (size_t size)
+{
+ return gmalloc (size);
+}
+
+void *
+calloc (size_t nmemb, size_t size)
+{
+ return gcalloc (nmemb, size);
+}
+
+void
+free (void *ptr)
+{
+ gfree (ptr);
+}
+
+void *
+aligned_alloc (size_t alignment, size_t size)
+{
+ return galigned_alloc (alignment, size);
+}
+
+void *
+realloc (void *ptr, size_t size)
+{
+ return grealloc (ptr, size);
+}
+
#ifdef GC_MCHECK
/* Standard debugging hooks for `malloc'.
|