0003-lib-memory-fix-indirect-static-link-with-zlib.patch 3.9 KB

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