1From bee452dfa2a34ba7df7db677e5673cbdcd23f61e Mon Sep 17 00:00:00 2001 2From: Petr Vorel <petr.vorel@gmail.com> 3Date: Thu, 1 Oct 2020 23:28:39 +0200 4Subject: [PATCH] lapi: Add sysinfo.h to fix build with MUSL libc 5MIME-Version: 1.0 6Content-Type: text/plain; charset=UTF-8 7Content-Transfer-Encoding: 8bit 8 9The reason is to avoid indirect <linux/sysinfo.h> include when using 10some network headers: <linux/netlink.h> or others -> <linux/kernel.h> 11-> <linux/sysinfo.h> 12 13This indirect include causes on MUSL redefinition of struct sysinfo when 14included both <sys/sysinfo.h> and some of UAPI headers: 15 16In file included from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/kernel.h:5, 17 from x86_64-buildroot-linux-musl/sysroot/usr/include/linux/netlink.h:5, 18 from ../include/tst_netlink.h:14, 19 from tst_crypto.c:13: 20x86_64-buildroot-linux-musl/sysroot/usr/include/linux/sysinfo.h:8:8: error: redefinition of ‘struct sysinfo’ 21 struct sysinfo { 22 ^~~~~~~ 23In file included from ../include/tst_safe_macros.h:15, 24 from ../include/tst_test.h:93, 25 from tst_crypto.c:11: 26x86_64-buildroot-linux-musl/sysroot/usr/include/sys/sysinfo.h:10:8: note: originally defined here 27 28Signed-off-by: Petr Vorel <petr.vorel@gmail.com> 29 30[ upstream status: 31https://patchwork.ozlabs.org/project/ltp/patch/20201001231256.6930-1-petr.vorel@gmail.com/, 32rebased for 20210927 ] 33 34But this patch is not going to get upstreamed because it got fixed in Linux kernel: 35a85cbe6159ff "uapi: move constants from <linux/kernel.h> to <linux/const.h>" 36 37This patch was also backported to stable and LTS versions, 38which we use since buildroot 54584d233b "{linux, linux-headers}: bump 395.{4, 10}.x 4.{4, 9, 14, 19} series". 40We just wait for all musl based toolchains to be rebuilt. ] 41 42Signed-off-by: Petr Vorel <petr.vorel@gmail.com> 43--- 44 include/lapi/sysinfo.h | 22 +++++++++++++++++++ 45 include/tst_safe_macros.h | 2 +- 46 lib/safe_macros.c | 2 +- 47 lib/tst_memutils.c | 2 +- 48 testcases/kernel/mem/mtest01/mtest01.c | 2 +- 49 testcases/kernel/syscalls/madvise/madvise06.c | 2 +- 50 testcases/kernel/syscalls/sysinfo/sysinfo01.c | 2 +- 51 testcases/kernel/syscalls/sysinfo/sysinfo02.c | 2 +- 52 testcases/kernel/syscalls/sysinfo/sysinfo03.c | 2 +- 53 .../interfaces/pthread_cond_broadcast/1-2.c | 2 +- 54 10 files changed, 31 insertions(+), 9 deletions(-) 55 create mode 100644 include/lapi/sysinfo.h 56 57diff --git a/include/lapi/sysinfo.h b/include/lapi/sysinfo.h 58new file mode 100644 59index 000000000..d0e0e93d7 60--- /dev/null 61+++ b/include/lapi/sysinfo.h 62@@ -0,0 +1,22 @@ 63+// SPDX-License-Identifier: GPL-2.0-or-later 64+/* 65+ * Copyright (c) 2020 Petr Vorel <petr.vorel@gmail.com> 66+ */ 67+ 68+#ifndef SYSINFO_H__ 69+ 70+/* 71+ * Don't use <sys/sysinfo.h> as it breaks build MUSL toolchain. 72+ * Use <linux/sysinfo.h> instead. 73+ * 74+ * Some kernel UAPI headers do indirect <linux/sysinfo.h> include: 75+ * <linux/netlink.h> or others -> <linux/kernel.h> -> <linux/sysinfo.h> 76+ * 77+ * This indirect include causes on MUSL redefinition of struct sysinfo when 78+ * included both <sys/sysinfo.h> and some of UAPI headers: 79+ */ 80+#include <linux/sysinfo.h> 81+ 82+#define SYSINFO_H__ 83+ 84+#endif /* SYSINFO_H__ */ 85diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h 86index d99441c86..0d26e9d45 100644 87--- a/include/tst_safe_macros.h 88+++ b/include/tst_safe_macros.h 89@@ -12,7 +12,7 @@ 90 #include <sys/resource.h> 91 #include <sys/stat.h> 92 #include <sys/vfs.h> 93-#include <sys/sysinfo.h> 94+#include <linux/sysinfo.h> 95 #include <fcntl.h> 96 #include <libgen.h> 97 #include <signal.h> 98diff --git a/lib/safe_macros.c b/lib/safe_macros.c 99index a5b6bc504..20d01d304 100644 100--- a/lib/safe_macros.c 101+++ b/lib/safe_macros.c 102@@ -11,7 +11,6 @@ 103 #include <sys/wait.h> 104 #include <sys/mount.h> 105 #include <sys/xattr.h> 106-#include <sys/sysinfo.h> 107 #include <errno.h> 108 #include <fcntl.h> 109 #include <libgen.h> 110@@ -23,6 +22,7 @@ 111 #include <malloc.h> 112 #include "test.h" 113 #include "safe_macros.h" 114+#include "lapi/sysinfo.h" 115 116 char *safe_basename(const char *file, const int lineno, 117 void (*cleanup_fn) (void), char *path) 118diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c 119index 69077861f..ae1cad29b 100644 120--- a/lib/tst_memutils.c 121+++ b/lib/tst_memutils.c 122@@ -5,11 +5,11 @@ 123 124 #include <unistd.h> 125 #include <limits.h> 126-#include <sys/sysinfo.h> 127 #include <stdlib.h> 128 129 #define TST_NO_DEFAULT_MAIN 130 #include "tst_test.h" 131+#include "lapi/sysinfo.h" 132 133 #define BLOCKSIZE (16 * 1024 * 1024) 134 135diff --git a/testcases/kernel/mem/mtest01/mtest01.c b/testcases/kernel/mem/mtest01/mtest01.c 136index 9676ea4b5..33b2ac822 100644 137--- a/testcases/kernel/mem/mtest01/mtest01.c 138+++ b/testcases/kernel/mem/mtest01/mtest01.c 139@@ -20,7 +20,6 @@ 140 */ 141 142 #include <sys/types.h> 143-#include <sys/sysinfo.h> 144 #include <sys/wait.h> 145 #include <limits.h> 146 #include <signal.h> 147@@ -29,6 +28,7 @@ 148 #include <unistd.h> 149 150 #include "lapi/abisize.h" 151+#include "lapi/sysinfo.h" 152 #include "tst_test.h" 153 154 #define FIVE_HUNDRED_MB (500ULL*1024*1024) 155diff --git a/testcases/kernel/syscalls/madvise/madvise06.c b/testcases/kernel/syscalls/madvise/madvise06.c 156index 263b8e78b..4fa52e6ea 100644 157--- a/testcases/kernel/syscalls/madvise/madvise06.c 158+++ b/testcases/kernel/syscalls/madvise/madvise06.c 159@@ -46,7 +46,7 @@ 160 #include <errno.h> 161 #include <stdio.h> 162 #include <sys/mount.h> 163-#include <sys/sysinfo.h> 164+#include "lapi/sysinfo.h" 165 #include "tst_test.h" 166 #include "tst_cgroup.h" 167 168diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo01.c b/testcases/kernel/syscalls/sysinfo/sysinfo01.c 169index 2ea44a2be..a237345ef 100644 170--- a/testcases/kernel/syscalls/sysinfo/sysinfo01.c 171+++ b/testcases/kernel/syscalls/sysinfo/sysinfo01.c 172@@ -69,7 +69,7 @@ 173 #include <sys/types.h> 174 #include <sys/stat.h> 175 #include <sys/signal.h> 176-#include <sys/sysinfo.h> 177+#include "lapi/sysinfo.h" 178 179 #include "test.h" 180 181diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo02.c b/testcases/kernel/syscalls/sysinfo/sysinfo02.c 182index 7ad0e8bdc..61fa1ab75 100644 183--- a/testcases/kernel/syscalls/sysinfo/sysinfo02.c 184+++ b/testcases/kernel/syscalls/sysinfo/sysinfo02.c 185@@ -65,7 +65,7 @@ 186 #include <sys/types.h> 187 #include <sys/stat.h> 188 #include <sys/signal.h> 189-#include <sys/sysinfo.h> 190+#include "lapi/sysinfo.h" 191 #include <stdint.h> 192 193 #include "test.h" 194diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo03.c b/testcases/kernel/syscalls/sysinfo/sysinfo03.c 195index af7cb6421..dc5ae65e3 100644 196--- a/testcases/kernel/syscalls/sysinfo/sysinfo03.c 197+++ b/testcases/kernel/syscalls/sysinfo/sysinfo03.c 198@@ -13,7 +13,7 @@ 199 200 */ 201 202-#include <sys/sysinfo.h> 203+#include "lapi/sysinfo.h" 204 #include "lapi/namespaces_constants.h" 205 #include "lapi/posix_clocks.h" 206 #include "tst_test.h" 207diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c 208index 22e7c3638..572701f9f 100644 209--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c 210+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_broadcast/1-2.c 211@@ -43,7 +43,7 @@ 212 #include <sys/wait.h> 213 #include <semaphore.h> 214 #ifdef __linux__ 215-#include <sys/sysinfo.h> 216+#include "lapi/sysinfo.h" 217 #endif 218 219 #include "../testfrmw/testfrmw.h" 220-- 2212.33.0 222 223