0001-build-Always-use-EXTERN_UNLESS_MAIN_MODULE-pattern.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. From 45ef4455a60929932d1499cf718c1c9f59af9f26 Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  3. Date: Tue, 26 May 2020 22:57:05 +0200
  4. Subject: [PATCH] build: Always use EXTERN_UNLESS_MAIN_MODULE pattern
  5. This patch is loosely based on upstream commit
  6. 6aff8a132815a84bab69401c1e7de96ec549fbf2 ("build: Always use
  7. EXTERN_UNLESS_MAIN_MODULE pattern."). However, this upstream commit
  8. applies to gnupg2, and the code base has changed quite significantly
  9. compared to gnupg 1.x, so upstream's patch cannot be applied
  10. as-is. The goal of the patch is to make sure each variable is only
  11. defined once, ass gcc 10 now default to -fno-common.
  12. Essentially, this patch mainly fixes the EXTERN_UNLESS_MAIN_MODULE
  13. define so that it really expands to "extern" when
  14. INCLUDED_BY_MAIN_MODULE is not defined, even on non-RiscOS
  15. systems. Contrary to upstream's patch we however do not factorize the
  16. multiple EXTERN_UNLESS_MAIN_MODULE definitions into a single place as
  17. it requires too many changes: instead we simply fix the few
  18. definitions of this macro.
  19. Once the macro is fixed, two places need to define
  20. INCLUDED_BY_MAIN_MODULE: tools/bftest.c and tools/mpicalc.c so that
  21. when they include the common headers, their variables are at least
  22. defined once.
  23. The iobuf.{c,h} case is handled differently: iobuf.h gains an
  24. unconditional "extern", with the variable being added to iobuf.c. This
  25. is identical to what upstream's
  26. 6aff8a132815a84bab69401c1e7de96ec549fbf2 is doing.
  27. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  28. ---
  29. g10/options.h | 3 +--
  30. include/cipher.h | 2 +-
  31. include/iobuf.h | 9 +--------
  32. include/memory.h | 2 +-
  33. include/mpi.h | 2 +-
  34. tools/bftest.c | 1 +
  35. tools/mpicalc.c | 1 +
  36. util/iobuf.c | 2 ++
  37. 8 files changed, 9 insertions(+), 13 deletions(-)
  38. diff --git a/g10/options.h b/g10/options.h
  39. index 0ac6e7755..bae19e9e3 100644
  40. --- a/g10/options.h
  41. +++ b/g10/options.h
  42. @@ -26,8 +26,7 @@
  43. #include "packet.h"
  44. #ifndef EXTERN_UNLESS_MAIN_MODULE
  45. -/* Norcraft can't cope with common symbols */
  46. -#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
  47. +#if !defined (INCLUDED_BY_MAIN_MODULE)
  48. #define EXTERN_UNLESS_MAIN_MODULE extern
  49. #else
  50. #define EXTERN_UNLESS_MAIN_MODULE
  51. diff --git a/include/cipher.h b/include/cipher.h
  52. index dd4af18cb..6ef6e6829 100644
  53. --- a/include/cipher.h
  54. +++ b/include/cipher.h
  55. @@ -115,7 +115,7 @@ struct gcry_md_context {
  56. typedef struct gcry_md_context *MD_HANDLE;
  57. #ifndef EXTERN_UNLESS_MAIN_MODULE
  58. -#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
  59. +#if !defined (INCLUDED_BY_MAIN_MODULE)
  60. #define EXTERN_UNLESS_MAIN_MODULE extern
  61. #else
  62. #define EXTERN_UNLESS_MAIN_MODULE
  63. diff --git a/include/iobuf.h b/include/iobuf.h
  64. index 030f8c8e9..b4d26b7e1 100644
  65. --- a/include/iobuf.h
  66. +++ b/include/iobuf.h
  67. @@ -69,14 +69,7 @@ struct iobuf_struct {
  68. } unget;
  69. };
  70. -#ifndef EXTERN_UNLESS_MAIN_MODULE
  71. -#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
  72. -#define EXTERN_UNLESS_MAIN_MODULE extern
  73. -#else
  74. -#define EXTERN_UNLESS_MAIN_MODULE
  75. -#endif
  76. -#endif
  77. -EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode;
  78. +extern int iobuf_debug_mode;
  79. void iobuf_enable_special_filenames ( int yes );
  80. int iobuf_is_pipe_filename (const char *fname);
  81. diff --git a/include/memory.h b/include/memory.h
  82. index d414a9b2e..6698337e3 100644
  83. --- a/include/memory.h
  84. +++ b/include/memory.h
  85. @@ -91,7 +91,7 @@ unsigned secmem_get_flags(void);
  86. #define DBG_MEMSTAT memory_stat_debug_mode
  87. #ifndef EXTERN_UNLESS_MAIN_MODULE
  88. -#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
  89. +#if !defined (INCLUDED_BY_MAIN_MODULE)
  90. #define EXTERN_UNLESS_MAIN_MODULE extern
  91. #else
  92. #define EXTERN_UNLESS_MAIN_MODULE
  93. diff --git a/include/mpi.h b/include/mpi.h
  94. index a4c16f5af..7a45ff805 100644
  95. --- a/include/mpi.h
  96. +++ b/include/mpi.h
  97. @@ -36,7 +36,7 @@
  98. #include "memory.h"
  99. #ifndef EXTERN_UNLESS_MAIN_MODULE
  100. -#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
  101. +#if !defined (INCLUDED_BY_MAIN_MODULE)
  102. #define EXTERN_UNLESS_MAIN_MODULE extern
  103. #else
  104. #define EXTERN_UNLESS_MAIN_MODULE
  105. diff --git a/tools/bftest.c b/tools/bftest.c
  106. index 8a1572c2b..5afd7e125 100644
  107. --- a/tools/bftest.c
  108. +++ b/tools/bftest.c
  109. @@ -26,6 +26,7 @@
  110. #include <fcntl.h>
  111. #endif
  112. +#define INCLUDED_BY_MAIN_MODULE
  113. #include "util.h"
  114. #include "cipher.h"
  115. #include "i18n.h"
  116. diff --git a/tools/mpicalc.c b/tools/mpicalc.c
  117. index 46e5fc824..31acd82a4 100644
  118. --- a/tools/mpicalc.c
  119. +++ b/tools/mpicalc.c
  120. @@ -31,6 +31,7 @@
  121. #include <stdlib.h>
  122. #include <ctype.h>
  123. +#define INCLUDED_BY_MAIN_MODULE
  124. #include "util.h"
  125. #include "mpi.h"
  126. #include "i18n.h"
  127. diff --git a/util/iobuf.c b/util/iobuf.c
  128. index c8442929a..0d9ee4cec 100644
  129. --- a/util/iobuf.c
  130. +++ b/util/iobuf.c
  131. @@ -113,6 +113,8 @@ typedef struct {
  132. static CLOSE_CACHE close_cache;
  133. #endif
  134. +int iobuf_debug_mode;
  135. +
  136. #ifdef _WIN32
  137. typedef struct {
  138. int sock;
  139. --
  140. 2.26.2