From: David Howells <dhowells@redhat.com>
To: linux-api@vger.kernel.org, linux-kbuild@vger.kernel.org
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
Michal Marek <michal.lkml@markovi.net>,
linux-kernel@vger.kernel.org, dhowells@redhat.com
Subject: [PATCH 11/11] UAPI: Check headers build for C++ [ver #2]
Date: Thu, 06 Sep 2018 10:19:37 +0100 [thread overview]
Message-ID: <153622557736.14298.10350496216090814292.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <153622549721.14298.8116794954073122489.stgit@warthog.procyon.org.uk>
Check that all the headers can be included from one file and built for C++,
thereby catching the use of C++ reserved words and bits of unimplemented
C++ in the UAPI headers.
Note that certain headers are excluded from the build, including:
(1) Any header ending in "_32.h", "_64.h" or "_x32.h" as these are
expected to be multiarch variant headers.
(2) Endianness variant headers.
(3) asm-generic/ headers (they're used conditionally by the asm/ headers
and shouldn't be used directly).
(4) netfilter_ipv*/ip*t_LOG.h headers. They emit a warning indicating
they're going to be removed soon.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Masahiro Yamada <yamada.masahiro@socionext.com>
cc: Michal Marek <michal.lkml@markovi.net>
cc: linux-kbuild@vger.kernel.org
---
Makefile | 1
| 124 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+)
create mode 100755 scripts/headers-c++.sh
diff --git a/Makefile b/Makefile
index 19948e556941..38d655cb4474 100644
--- a/Makefile
+++ b/Makefile
@@ -1186,6 +1186,7 @@ headers_install: __headers
$(error Headers not exportable for the $(SRCARCH) architecture))
$(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include
$(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi $(hdr-dst)
+ $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers-c++.sh check
PHONY += headers_check_all
headers_check_all: headers_install_all
--git a/scripts/headers-c++.sh b/scripts/headers-c++.sh
new file mode 100755
index 000000000000..7e56913629f8
--- /dev/null
+++ b/scripts/headers-c++.sh
@@ -0,0 +1,124 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# Run headers_$1 command for all suitable architectures
+
+# Stop on error
+set -e
+
+if ! $CC -x c++ -c - -o /dev/null </dev/null 2>/dev/null
+then
+ echo " CHECK C++ HEADER COMPILATION [SKIPPED]"
+ exit 0
+fi
+
+echo " CHECK C++ HEADER COMPILATION"
+
+mkdir -p hdr-check
+cd hdr-check
+
+mkdir -p include/sys
+mkdir -p include/arpa
+mkdir -p include/xen/interface
+echo >include/endian.h
+echo >include/limits.h
+echo >include/stdint.h
+echo >include/stdlib.h
+echo >include/stdio.h
+echo >include/string.h
+echo >include/time.h
+echo >include/unistd.h
+echo >include/arpa/inet.h
+echo >include/sys/ioctl.h
+echo >include/sys/types.h
+echo >include/sys/time.h
+echo >include/sys/socket.h
+echo >include/xen/interface/xen.h
+
+cat >test.h <<EOF
+#ifdef __cplusplus
+#define NULL nullptr
+#define _Bool bool
+#else
+#define NULL ((void *)0)
+#define bool _Bool
+#endif
+#include <linux/types.h>
+#include <linux/socket.h>
+#include <linux/time.h>
+
+typedef __s8 int8_t;
+typedef __s16 int16_t;
+typedef __s32 int32_t;
+typedef __s64 int64_t;
+typedef __u8 uint8_t;
+typedef __u16 uint16_t;
+typedef __u32 uint32_t;
+typedef __u64 uint64_t;
+typedef long int intptr_t;
+typedef unsigned long int uintptr_t;
+typedef unsigned short u_short;
+typedef unsigned int u_int;
+typedef unsigned long u_long;
+typedef char *caddr_t;
+
+typedef __kernel_clockid_t clockid_t;
+typedef __kernel_ino_t ino_t;
+typedef __kernel_pid_t pid_t;
+typedef __kernel_sa_family_t sa_family_t;
+typedef __kernel_size_t size_t;
+typedef __kernel_uid_t uid_t;
+
+typedef unsigned long elf_greg_t;
+typedef elf_greg_t elf_gregset_t[1];
+typedef unsigned long long elf_fpregset_t[1];
+typedef unsigned long long elf_fpxregset_t[1];
+
+#define INT_MIN ((int)0x80000000)
+#define INT_MAX ((int)0x7fffffff)
+
+extern size_t strlen(const char *);
+extern void *memset(void *, int, size_t);
+extern void *memcpy(void *, const void *, size_t);
+extern __u16 ntohs(__u16);
+extern __u16 htons(__u16);
+extern __u32 ntohl(__u32);
+extern __u32 htonl(__u32);
+
+typedef uint32_t grant_ref_t;
+typedef uint16_t domid_t;
+typedef unsigned long xen_pfn_t;
+
+#define MSG_FIN 0x200
+
+typedef int SVGA3dMSPattern;
+typedef int SVGA3dMSQualityLevel;
+
+struct sockaddr
+{
+ sa_family_t sa_family;
+ char sa_data[14];
+};
+#define sockaddr_storage __kernel_sockaddr_storage
+
+#define _LINUX_PATCHKEY_H_INDIRECT
+
+EOF
+
+find ../usr/include -name '*.h' |
+ grep -v 'linux/byteorder/big_endian.h' |
+ grep -v 'linux/byteorder/little_endian.h' |
+ grep -v '_\(32\|64\|x32\)[.]h$' |
+ grep -v '/asm-generic/' |
+ # ip*t_LOG.h are deprecated
+ grep -v 'linux/netfilter_ipv4/ipt_LOG[.]h' |
+ grep -v 'linux/netfilter_ipv6/ip6t_LOG[.]h' |
+ sed -e 's!../usr/include/!#include <!' -e 's!$!>!' >>test.h
+
+echo '#include "test.h"' >test.cpp
+
+$CC -x c++ -o /dev/null -c test.cpp \
+ -nostdinc \
+ -isystem ./include \
+ -isystem ../usr/include \
+ -fpermissive \
+ -D PAGE_SIZE='#PAGE_SIZE_IS_NOT_VALID_OUTSIDE_OF_KERNEL'
next prev parent reply other threads:[~2018-09-06 9:19 UTC|newest]
Thread overview: 124+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-06 9:18 [RFC] UAPI: Check headers by compiling all together as C++ David Howells
2018-09-06 9:18 ` David Howells
2018-09-06 9:18 ` David Howells
2018-09-06 9:18 ` David Howells
2018-09-06 9:18 ` David Howells
[not found] ` <153622549721.14298.8116794954073122489.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2018-09-06 9:18 ` [PATCH 01/11] UAPI: drm: Fix use of C++ keywords as structural members [ver #2] David Howells
2018-09-06 9:18 ` David Howells
2018-09-06 9:18 ` [PATCH 02/11] UAPI: keys: " David Howells
2018-09-06 9:18 ` David Howells
2018-09-06 9:18 ` [PATCH 03/11] UAPI: virtio_net: " David Howells
2018-09-06 15:02 ` Michael S. Tsirkin
2018-09-06 15:02 ` Michael S. Tsirkin
2018-09-06 9:18 ` David Howells
2018-09-06 9:18 ` [PATCH 04/11] UAPI: bcache: Fix use of embedded flexible array " David Howells
2018-09-06 9:18 ` [PATCH 05/11] UAPI: coda: Move kernel internals out of public view " David Howells
2018-09-06 9:18 ` David Howells
2018-09-06 9:19 ` [PATCH 06/11] coda: Move internal defs out of include/linux/ " David Howells
2018-09-06 9:19 ` [PATCH 07/11] UAPI: netfilter: Fix symbol collision issues " David Howells
2018-09-10 17:32 ` kbuild test robot
2018-09-10 17:32 ` kbuild test robot
2018-09-10 17:32 ` kbuild test robot
2018-09-28 13:07 ` [netfilter-core] " Pablo Neira Ayuso
2018-10-09 15:35 ` David Howells
2018-09-06 9:19 ` [PATCH 08/11] UAPI: nilfs2: Fix use of undefined byteswapping functions " David Howells
2018-09-06 9:19 ` [PATCH 09/11] UAPI: ndctl: Fix g++-unsupported initialisation in headers " David Howells
2018-09-06 9:19 ` David Howells
2018-09-06 9:19 ` David Howells
2018-09-25 20:22 ` Dan Williams
2018-09-25 20:22 ` Dan Williams
2018-09-25 20:22 ` Dan Williams
2018-09-06 9:19 ` [PATCH 10/11] UAPI: ndctl: Remove use of PAGE_SIZE " David Howells
2018-09-06 9:19 ` David Howells
2018-09-06 9:19 ` David Howells
2018-09-25 20:17 ` Dan Williams
2018-09-25 20:17 ` Dan Williams
2018-09-25 20:17 ` Dan Williams
2018-10-09 15:36 ` David Howells
2018-10-09 15:36 ` David Howells
2018-09-06 9:19 ` David Howells [this message]
2018-09-10 16:26 ` [PATCH 11/11] UAPI: Check headers build for C++ " kbuild test robot
2018-09-10 16:26 ` kbuild test robot
2018-09-10 16:26 ` kbuild test robot
2018-09-10 17:02 ` kbuild test robot
2018-09-10 17:02 ` kbuild test robot
2018-09-10 17:02 ` kbuild test robot
2018-09-14 9:10 ` Arnd Bergmann
-- strict thread matches above, loose matches on Subject: below --
2018-09-05 15:54 [RFC] UAPI: Check headers by compiling all together as C++ David Howells
2018-09-05 15:54 ` David Howells
2018-09-05 15:54 ` David Howells
2018-09-05 15:54 ` David Howells
2018-09-05 15:54 ` David Howells
2018-09-05 15:54 ` [PATCH 01/11] UAPI: drm: Fix use of C++ keywords as structural members David Howells
2018-09-05 15:54 ` David Howells
2018-09-05 15:54 ` [PATCH 02/11] UAPI: keys: " David Howells
2018-09-05 15:54 ` David Howells
2018-09-05 15:54 ` [PATCH 03/11] UAPI: virtio_net: " David Howells
2018-09-05 16:54 ` Greg KH
2018-09-05 16:54 ` Greg KH
2018-09-05 17:15 ` David Howells
2018-09-05 17:15 ` David Howells
2018-09-05 17:35 ` Michael S. Tsirkin
2018-09-05 17:35 ` Michael S. Tsirkin
2018-09-06 7:09 ` David Howells
2018-09-06 7:09 ` David Howells
2018-09-06 14:36 ` Michael S. Tsirkin
2018-09-06 14:36 ` Michael S. Tsirkin
2018-09-05 15:54 ` David Howells
2018-09-05 15:55 ` [PATCH 04/11] UAPI: bcache: Fix use of embedded flexible array David Howells
2018-10-02 14:52 ` Jan Engelhardt
2018-10-09 15:41 ` David Howells
2018-10-09 16:54 ` Jan Engelhardt
2018-09-05 15:55 ` [PATCH 05/11] UAPI: coda: Don't use internal kernel structs in UAPI David Howells
2018-09-05 16:54 ` Jan Harkes
2018-09-05 17:12 ` Yann Droneaud
2018-09-05 17:28 ` Jan Harkes
2018-09-05 17:28 ` Jan Harkes
2018-09-05 17:24 ` David Howells
2018-09-06 7:13 ` David Howells
2018-09-06 11:52 ` Yann Droneaud
2018-09-06 12:16 ` Jan Harkes
2018-09-06 12:16 ` Jan Harkes
2018-09-06 14:53 ` David Howells
2018-09-05 15:55 ` [PATCH 06/11] UAPI: netfilter: Fix symbol collision issues David Howells
2018-09-05 15:55 ` [PATCH 07/11] UAPI: nilfs2: Fix use of undefined byteswapping functions David Howells
2018-09-05 22:20 ` Al Viro
2018-09-05 15:55 ` [PATCH 08/11] UAPI: sound: Fix use of u32 and co. in UAPI headers David Howells
2018-09-05 15:55 ` David Howells
2018-09-06 5:59 ` Takashi Sakamoto
2018-09-06 5:59 ` Takashi Sakamoto
2018-09-06 8:17 ` David Howells
2018-09-05 15:55 ` [PATCH 09/11] UAPI: ndctl: Fix g++-unsupported initialisation in headers David Howells
2018-09-05 15:55 ` David Howells
2018-09-05 15:55 ` David Howells
2018-09-05 15:55 ` [PATCH 10/11] UAPI: ndctl: Remove use of PAGE_SIZE David Howells
2018-09-05 15:55 ` David Howells
2018-09-05 15:55 ` [PATCH 11/11] UAPI: Check headers build for C++ David Howells
2018-09-05 16:55 ` [RFC] UAPI: Check headers by compiling all together as C++ Greg KH
2018-09-05 16:55 ` Greg KH
2018-09-05 16:55 ` Greg KH
2018-09-05 16:55 ` Greg KH
2018-09-05 16:55 ` Greg KH
2018-09-05 17:33 ` Yann Droneaud
2018-09-05 17:33 ` Yann Droneaud
2018-09-05 17:33 ` Yann Droneaud
2018-09-05 17:33 ` Yann Droneaud
2018-09-05 17:42 ` Michael S. Tsirkin
2018-09-05 17:42 ` Michael S. Tsirkin
2018-09-05 17:42 ` Michael S. Tsirkin
2018-09-05 17:42 ` Michael S. Tsirkin
2018-09-05 17:42 ` Michael S. Tsirkin
2018-09-05 17:42 ` Michael S. Tsirkin
2018-09-05 17:42 ` Michael S. Tsirkin
2018-09-06 7:12 ` Yann Droneaud
2018-09-06 7:12 ` Yann Droneaud
2018-09-06 7:12 ` Yann Droneaud
2018-09-06 7:12 ` Yann Droneaud
2018-09-05 19:22 ` Jan Engelhardt
2018-09-05 19:22 ` Jan Engelhardt
2018-09-05 19:22 ` Jan Engelhardt
2018-09-05 19:22 ` Jan Engelhardt
2018-09-05 19:22 ` Jan Engelhardt
2018-09-05 17:50 ` David Howells
2018-09-05 17:50 ` David Howells
2018-09-05 17:50 ` David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=153622557736.14298.10350496216090814292.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.lkml@markovi.net \
--cc=yamada.masahiro@socionext.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.