]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - package/quagga/0003-lib-memory-fix-indirect-static-link-with-zlib.patch
lrzsz: install symlinks for XMODEM and YMODEM
[coffee/buildroot.git] / package / quagga / 0003-lib-memory-fix-indirect-static-link-with-zlib.patch
1 From 008dd9771057dbbd7ce971c43bce2a0b05e2cf97 Mon Sep 17 00:00:00 2001
2 From: Baruch Siach <baruch@tkos.co.il>
3 Date: Sun, 21 Aug 2016 08:56:57 +0300
4 Subject: [PATCH] lib/memory: fix indirect static link with zlib
5
6 quagga SNMP support depends on netsnmp, that optionally depends on OpenSSL,
7 which in turn requires zlib. zlib exports the 'zcalloc' symbol, which collides
8 with a function of the same name in memory.c. This is not a problem when
9 linking dynamically, since quagga does not use zlib directly. But static
10 linking fails with the error:
11
12   CCLD     ospfd
13 .../output/host/usr/mips64el-buildroot-linux-uclibc/sysroot/usr/lib/libz.a(zutil.o): In function `zcalloc':
14 zutil.c:(.text+0x48): multiple definition of `zcalloc'
15 .../output/build/quagga-1.0.20160315/lib/.libs/libzebra.a(memory.o):memory.c:(.text+0x1a0): first defined here
16
17 Rename 'zcalloc' to 'zzcalloc' to avoid symbol collision.
18
19 Signed-off-by: Baruch Siach <baruch@tkos.co.il>
20 ---
21 Patch status: posted upstream
22 https://lists.quagga.net/pipermail/quagga-dev/2016-August/016109.html
23
24  lib/memory.c | 14 ++++++++------
25  lib/memory.h |  4 ++--
26  2 files changed, 10 insertions(+), 8 deletions(-)
27
28 diff --git a/lib/memory.c b/lib/memory.c
29 index 269520d5a435..b1680a5e6f07 100644
30 --- a/lib/memory.c
31 +++ b/lib/memory.c
32 @@ -80,9 +80,11 @@ zmalloc (int type, size_t size)
33  
34  /*
35   * Allocate memory as in zmalloc, and also clear the memory.
36 + * Add an extra 'z' prefix to function name to avoid collision when linking
37 + * statically with zlib that exports the 'zcalloc' symbol.
38   */
39  void *
40 -zcalloc (int type, size_t size)
41 +zzcalloc (int type, size_t size)
42  {
43    void *memory;
44  
45 @@ -97,9 +99,9 @@ zcalloc (int type, size_t size)
46  }
47  
48  /* 
49 - * Given a pointer returned by zmalloc or zcalloc, free it and
50 + * Given a pointer returned by zmalloc or zzcalloc, free it and
51   * return a pointer to a new size, basically acting like realloc().
52 - * Requires: ptr was returned by zmalloc, zcalloc, or zrealloc with the
53 + * Requires: ptr was returned by zmalloc, zzcalloc, or zrealloc with the
54   * same type.
55   * Effects: Returns a pointer to the new memory, or aborts.
56   */
57 @@ -109,7 +111,7 @@ zrealloc (int type, void *ptr, size_t size)
58    void *memory;
59  
60    if (ptr == NULL)              /* is really alloc */
61 -      return zcalloc(type, size);
62 +      return zzcalloc(type, size);
63  
64    memory = realloc (ptr, size);
65    if (memory == NULL)
66 @@ -122,7 +124,7 @@ zrealloc (int type, void *ptr, size_t size)
67  
68  /*
69   * Free memory allocated by z*alloc or zstrdup.
70 - * Requires: ptr was returned by zmalloc, zcalloc, or zrealloc with the
71 + * Requires: ptr was returned by zmalloc, zzcalloc, or zrealloc with the
72   * same type.
73   * Effects: The memory is freed and may no longer be referenced.
74   */
75 @@ -196,7 +198,7 @@ mtype_zcalloc (const char *file, int line, int type, size_t size)
76    mstat[type].c_calloc++;
77    mstat[type].t_calloc++;
78  
79 -  memory = zcalloc (type, size);
80 +  memory = zzcalloc (type, size);
81    mtype_log ("xcalloc", memory, file, line, type);
82  
83    return memory;
84 diff --git a/lib/memory.h b/lib/memory.h
85 index 23962235dbfe..501352993d21 100644
86 --- a/lib/memory.h
87 +++ b/lib/memory.h
88 @@ -56,7 +56,7 @@ extern struct mlist mlists[];
89    mtype_zstrdup (__FILE__, __LINE__, (mtype), (str))
90  #else
91  #define XMALLOC(mtype, size)       zmalloc ((mtype), (size))
92 -#define XCALLOC(mtype, size)       zcalloc ((mtype), (size))
93 +#define XCALLOC(mtype, size)       zzcalloc ((mtype), (size))
94  #define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size))
95  #define XFREE(mtype, ptr)          do { \
96                                       zfree ((mtype), (ptr)); \
97 @@ -67,7 +67,7 @@ extern struct mlist mlists[];
98  
99  /* Prototypes of memory function. */
100  extern void *zmalloc (int type, size_t size);
101 -extern void *zcalloc (int type, size_t size);
102 +extern void *zzcalloc (int type, size_t size);
103  extern void *zrealloc (int type, void *ptr, size_t size);
104  extern void  zfree (int type, void *ptr);
105  extern char *zstrdup (int type, const char *str);
106 -- 
107 2.8.1
108