0003-lib-memory-fix-indirect-static-link-with-zlib.patch
3.92 KB
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
From 008dd9771057dbbd7ce971c43bce2a0b05e2cf97 Mon Sep 17 00:00:00 2001
From: Baruch Siach <baruch@tkos.co.il>
Date: Sun, 21 Aug 2016 08:56:57 +0300
Subject: [PATCH] lib/memory: fix indirect static link with zlib
quagga SNMP support depends on netsnmp, that optionally depends on OpenSSL,
which in turn requires zlib. zlib exports the 'zcalloc' symbol, which collides
with a function of the same name in memory.c. This is not a problem when
linking dynamically, since quagga does not use zlib directly. But static
linking fails with the error:
CCLD ospfd
.../output/host/usr/mips64el-buildroot-linux-uclibc/sysroot/usr/lib/libz.a(zutil.o): In function `zcalloc':
zutil.c:(.text+0x48): multiple definition of `zcalloc'
.../output/build/quagga-1.0.20160315/lib/.libs/libzebra.a(memory.o):memory.c:(.text+0x1a0): first defined here
Rename 'zcalloc' to 'zzcalloc' to avoid symbol collision.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
Patch status: posted upstream
https://lists.quagga.net/pipermail/quagga-dev/2016-August/016109.html
lib/memory.c | 14 ++++++++------
lib/memory.h | 4 ++--
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/lib/memory.c b/lib/memory.c
index 269520d5a435..b1680a5e6f07 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -80,9 +80,11 @@ zmalloc (int type, size_t size)
/*
* Allocate memory as in zmalloc, and also clear the memory.
+ * Add an extra 'z' prefix to function name to avoid collision when linking
+ * statically with zlib that exports the 'zcalloc' symbol.
*/
void *
-zcalloc (int type, size_t size)
+zzcalloc (int type, size_t size)
{
void *memory;
@@ -97,9 +99,9 @@ zcalloc (int type, size_t size)
}
/*
- * Given a pointer returned by zmalloc or zcalloc, free it and
+ * Given a pointer returned by zmalloc or zzcalloc, free it and
* return a pointer to a new size, basically acting like realloc().
- * Requires: ptr was returned by zmalloc, zcalloc, or zrealloc with the
+ * Requires: ptr was returned by zmalloc, zzcalloc, or zrealloc with the
* same type.
* Effects: Returns a pointer to the new memory, or aborts.
*/
@@ -109,7 +111,7 @@ zrealloc (int type, void *ptr, size_t size)
void *memory;
if (ptr == NULL) /* is really alloc */
- return zcalloc(type, size);
+ return zzcalloc(type, size);
memory = realloc (ptr, size);
if (memory == NULL)
@@ -122,7 +124,7 @@ zrealloc (int type, void *ptr, size_t size)
/*
* Free memory allocated by z*alloc or zstrdup.
- * Requires: ptr was returned by zmalloc, zcalloc, or zrealloc with the
+ * Requires: ptr was returned by zmalloc, zzcalloc, or zrealloc with the
* same type.
* Effects: The memory is freed and may no longer be referenced.
*/
@@ -196,7 +198,7 @@ mtype_zcalloc (const char *file, int line, int type, size_t size)
mstat[type].c_calloc++;
mstat[type].t_calloc++;
- memory = zcalloc (type, size);
+ memory = zzcalloc (type, size);
mtype_log ("xcalloc", memory, file, line, type);
return memory;
diff --git a/lib/memory.h b/lib/memory.h
index 23962235dbfe..501352993d21 100644
--- a/lib/memory.h
+++ b/lib/memory.h
@@ -56,7 +56,7 @@ extern struct mlist mlists[];
mtype_zstrdup (__FILE__, __LINE__, (mtype), (str))
#else
#define XMALLOC(mtype, size) zmalloc ((mtype), (size))
-#define XCALLOC(mtype, size) zcalloc ((mtype), (size))
+#define XCALLOC(mtype, size) zzcalloc ((mtype), (size))
#define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size))
#define XFREE(mtype, ptr) do { \
zfree ((mtype), (ptr)); \
@@ -67,7 +67,7 @@ extern struct mlist mlists[];
/* Prototypes of memory function. */
extern void *zmalloc (int type, size_t size);
-extern void *zcalloc (int type, size_t size);
+extern void *zzcalloc (int type, size_t size);
extern void *zrealloc (int type, void *ptr, size_t size);
extern void zfree (int type, void *ptr);
extern char *zstrdup (int type, const char *str);
--
2.8.1