0002-lapi-Add-sysinfo.h-to-fix-build-with-MUSL-libc.patch 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. From ac3e262cba81889c0bb04ce87a50a1709f2726e7 Mon Sep 17 00:00:00 2001
  2. From: Petr Vorel <petr.vorel@gmail.com>
  3. Date: Thu, 1 Oct 2020 23:28:39 +0200
  4. Subject: [PATCH] lapi: Add sysinfo.h to fix build with MUSL libc
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. The reason is to avoid indirect <linux/sysinfo.h> include when using
  9. some network headers: <linux/netlink.h> or others -> <linux/kernel.h>
  10. -> <linux/sysinfo.h>
  11. This indirect include causes on MUSL redefinition of struct sysinfo when
  12. included both <sys/sysinfo.h> and some of UAPI headers:
  13. In file included from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/kernel.h:5,
  14. from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/netlink.h:5,
  15. from ../include/tst_netlink.h:14,
  16. from tst_crypto.c:13:
  17. x86_64-buildroot-linux-musl/sysroot/usr/include/linux/sysinfo.h:8:8: error: redefinition of ‘struct sysinfo’
  18. struct sysinfo {
  19. ^~~~~~~
  20. In file included from ../include/tst_safe_macros.h:15,
  21. from ../include/tst_test.h:93,
  22. from tst_crypto.c:11:
  23. x86_64-buildroot-linux-musl/sysroot/usr/include/sys/sysinfo.h:10:8: note: originally defined here
  24. Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
  25. [ upstream status: https://patchwork.ozlabs.org/project/ltp/patch/20201001231256.6930-1-petr.vorel@gmail.com/ ]
  26. ---
  27. include/lapi/sysinfo.h | 22 +++++++++++++++++++
  28. include/tst_safe_macros.h | 2 +-
  29. lib/safe_macros.c | 2 +-
  30. lib/tst_memutils.c | 2 +-
  31. testcases/kernel/mem/mtest01/mtest01.c | 2 +-
  32. testcases/kernel/syscalls/madvise/madvise06.c | 2 +-
  33. testcases/kernel/syscalls/sysinfo/sysinfo01.c | 2 +-
  34. testcases/kernel/syscalls/sysinfo/sysinfo02.c | 2 +-
  35. testcases/kernel/syscalls/sysinfo/sysinfo03.c | 2 +-
  36. 9 files changed, 30 insertions(+), 8 deletions(-)
  37. create mode 100644 include/lapi/sysinfo.h
  38. diff --git a/include/lapi/sysinfo.h b/include/lapi/sysinfo.h
  39. new file mode 100644
  40. index 000000000..d0e0e93d7
  41. --- /dev/null
  42. +++ b/include/lapi/sysinfo.h
  43. @@ -0,0 +1,22 @@
  44. +// SPDX-License-Identifier: GPL-2.0-or-later
  45. +/*
  46. + * Copyright (c) 2020 Petr Vorel <petr.vorel@gmail.com>
  47. + */
  48. +
  49. +#ifndef SYSINFO_H__
  50. +
  51. +/*
  52. + * Don't use <sys/sysinfo.h> as it breaks build MUSL toolchain.
  53. + * Use <linux/sysinfo.h> instead.
  54. + *
  55. + * Some kernel UAPI headers do indirect <linux/sysinfo.h> include:
  56. + * <linux/netlink.h> or others -> <linux/kernel.h> -> <linux/sysinfo.h>
  57. + *
  58. + * This indirect include causes on MUSL redefinition of struct sysinfo when
  59. + * included both <sys/sysinfo.h> and some of UAPI headers:
  60. + */
  61. +#include <linux/sysinfo.h>
  62. +
  63. +#define SYSINFO_H__
  64. +
  65. +#endif /* SYSINFO_H__ */
  66. diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
  67. index 053c3bcf9..61ea2076d 100644
  68. --- a/include/tst_safe_macros.h
  69. +++ b/include/tst_safe_macros.h
  70. @@ -12,7 +12,7 @@
  71. #include <sys/resource.h>
  72. #include <sys/stat.h>
  73. #include <sys/vfs.h>
  74. -#include <sys/sysinfo.h>
  75. +#include <linux/sysinfo.h>
  76. #include <fcntl.h>
  77. #include <libgen.h>
  78. #include <signal.h>
  79. diff --git a/lib/safe_macros.c b/lib/safe_macros.c
  80. index 4f48d7529..d8ee03dae 100644
  81. --- a/lib/safe_macros.c
  82. +++ b/lib/safe_macros.c
  83. @@ -11,7 +11,6 @@
  84. #include <sys/wait.h>
  85. #include <sys/mount.h>
  86. #include <sys/xattr.h>
  87. -#include <sys/sysinfo.h>
  88. #include <errno.h>
  89. #include <fcntl.h>
  90. #include <libgen.h>
  91. @@ -23,6 +22,7 @@
  92. #include <malloc.h>
  93. #include "test.h"
  94. #include "safe_macros.h"
  95. +#include "lapi/sysinfo.h"
  96. char *safe_basename(const char *file, const int lineno,
  97. void (*cleanup_fn) (void), char *path)
  98. diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
  99. index f134d90c9..647db951e 100644
  100. --- a/lib/tst_memutils.c
  101. +++ b/lib/tst_memutils.c
  102. @@ -5,11 +5,11 @@
  103. #include <unistd.h>
  104. #include <limits.h>
  105. -#include <sys/sysinfo.h>
  106. #include <stdlib.h>
  107. #define TST_NO_DEFAULT_MAIN
  108. #include "tst_test.h"
  109. +#include "lapi/sysinfo.h"
  110. #define BLOCKSIZE (16 * 1024 * 1024)
  111. diff --git a/testcases/kernel/mem/mtest01/mtest01.c b/testcases/kernel/mem/mtest01/mtest01.c
  112. index f08d3943f..9b4d856f8 100644
  113. --- a/testcases/kernel/mem/mtest01/mtest01.c
  114. +++ b/testcases/kernel/mem/mtest01/mtest01.c
  115. @@ -20,7 +20,6 @@
  116. */
  117. #include <sys/types.h>
  118. -#include <sys/sysinfo.h>
  119. #include <sys/wait.h>
  120. #include <limits.h>
  121. #include <signal.h>
  122. @@ -29,6 +28,7 @@
  123. #include <unistd.h>
  124. #include "lapi/abisize.h"
  125. +#include "lapi/sysinfo.h"
  126. #include "tst_test.h"
  127. #define FIVE_HUNDRED_MB (500ULL*1024*1024)
  128. diff --git a/testcases/kernel/syscalls/madvise/madvise06.c b/testcases/kernel/syscalls/madvise/madvise06.c
  129. index f76f3f6aa..b2613670b 100644
  130. --- a/testcases/kernel/syscalls/madvise/madvise06.c
  131. +++ b/testcases/kernel/syscalls/madvise/madvise06.c
  132. @@ -24,8 +24,8 @@
  133. #include <errno.h>
  134. #include <stdio.h>
  135. #include <sys/mount.h>
  136. -#include <sys/sysinfo.h>
  137. #include "tst_test.h"
  138. +#include "lapi/sysinfo.h"
  139. #define CHUNK_SZ (400*1024*1024L)
  140. #define CHUNK_PAGES (CHUNK_SZ / pg_sz)
  141. diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo01.c b/testcases/kernel/syscalls/sysinfo/sysinfo01.c
  142. index 2ea44a2be..a95066bf5 100644
  143. --- a/testcases/kernel/syscalls/sysinfo/sysinfo01.c
  144. +++ b/testcases/kernel/syscalls/sysinfo/sysinfo01.c
  145. @@ -69,9 +69,9 @@
  146. #include <sys/types.h>
  147. #include <sys/stat.h>
  148. #include <sys/signal.h>
  149. -#include <sys/sysinfo.h>
  150. #include "test.h"
  151. +#include "lapi/sysinfo.h"
  152. void setup();
  153. void cleanup();
  154. diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo02.c b/testcases/kernel/syscalls/sysinfo/sysinfo02.c
  155. index 678b8f1d3..5ce65d20e 100644
  156. --- a/testcases/kernel/syscalls/sysinfo/sysinfo02.c
  157. +++ b/testcases/kernel/syscalls/sysinfo/sysinfo02.c
  158. @@ -65,10 +65,10 @@
  159. #include <sys/types.h>
  160. #include <sys/stat.h>
  161. #include <sys/signal.h>
  162. -#include <sys/sysinfo.h>
  163. #include <stdint.h>
  164. #include "test.h"
  165. +#include "lapi/sysinfo.h"
  166. #define INVALID_ADDRESS ((uintptr_t)-1)
  167. diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo03.c b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
  168. index af7cb6421..3b61a05b1 100644
  169. --- a/testcases/kernel/syscalls/sysinfo/sysinfo03.c
  170. +++ b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
  171. @@ -13,9 +13,9 @@
  172. */
  173. -#include <sys/sysinfo.h>
  174. #include "lapi/namespaces_constants.h"
  175. #include "lapi/posix_clocks.h"
  176. +#include "lapi/sysinfo.h"
  177. #include "tst_test.h"
  178. static int offsets[] = {
  179. --
  180. 2.28.0