Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3986396imm; Wed, 5 Sep 2018 08:58:14 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb7g/1LD6i4ZW3PV3fTGZovvWVx43VN9SWB30OPVtWVCE5wzsMCloyW2Ev3wQVlff98OpjX X-Received: by 2002:a63:3642:: with SMTP id d63-v6mr36373774pga.231.1536163094030; Wed, 05 Sep 2018 08:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536163094; cv=none; d=google.com; s=arc-20160816; b=mK+KJ7dTmZkW+nq+ysxC2+QuJGtteXD8lmlFBrYHRnOk2bcDbELtqeauYzWD/ksb+m ySlnqWvJpKbCyotlxw6hGrbunSZC8SLVFr7IP6fULaUYxNJjBtq9gItNa865mZOx5d/Y VAaRLEDC7KfYGxb0O1ArWpDvPuEntYL8sQPS/bHoyTRKwAira0GuB6aucHQGP6Yor8Qf a18Z8z0UwA9nLY1m5rchSzmwynuANBcnEISS4uXGkl0trgTvZnw66STBPzUuGzE+l9os l1xy6CJaHIz9L/H+wp91s28OUy6Ky4JVK8u/Le9i9OHcrJ0BCaHYQ5wrJ6fWI8bYhwXG Graw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=QpQKyzSpLcO7swOcrpr8Ti/HSJJ4NX1hQP1aNLap/m4=; b=bnEN4KxsLqyyrRMRYgP6r8ap+YSJ8Cr0KtzOOErYEXMbmlAaQoPJ4b9UMmGDleDmH8 BsdKxtLBxqCJgGz1bYodIA4BQbeYMuhF3hcLpSonEppEllPdI4ZlOeOWbWJe9nS5NGUK ktiS6Dd9T/HA9HVPP46KAGTQTbrGkCVmzh7Vtv+2DW/bPMpXRQilvT6bKGpimD3gZMpv vS2Xt7nyRx4KxGv2vonmiiNlASuyarkQyWG2PEMGBfA4xcAUsB5/9Ys7uQ6Hou2SG6sU hC6xycq2nbfoEB+XgIeQGnMV/EP14wWYBEq64tB/C4gLc05ZLIC+BNo7JWW9UAnkkZGZ Q25A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g205-v6si2615676pfb.294.2018.09.05.08.57.58; Wed, 05 Sep 2018 08:58:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727957AbeIEU0l (ORCPT + 99 others); Wed, 5 Sep 2018 16:26:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51494 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726189AbeIEU0l (ORCPT ); Wed, 5 Sep 2018 16:26:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2138587927; Wed, 5 Sep 2018 15:55:52 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-123-84.rdu2.redhat.com [10.10.123.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 350332166BA1; Wed, 5 Sep 2018 15:55:51 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 11/11] UAPI: Check headers build for C++ From: David Howells To: linux-api@vger.kernel.org, linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org, dhowells@redhat.com Date: Wed, 05 Sep 2018 16:55:50 +0100 Message-ID: <153616295066.23468.6133013878008690375.stgit@warthog.procyon.org.uk> In-Reply-To: <153616286704.23468.584491117180383924.stgit@warthog.procyon.org.uk> References: <153616286704.23468.584491117180383924.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 05 Sep 2018 15:55:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 05 Sep 2018 15:55:52 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 cc: Masahiro Yamada cc: Michal Marek cc: linux-kbuild@vger.kernel.org --- Makefile | 1 scripts/headers-c++.sh | 124 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100755 scripts/headers-c++.sh diff --git a/Makefile b/Makefile index 2b458801ba74..f3c36c2bb4cf 100644 --- a/Makefile +++ b/Makefile @@ -1183,6 +1183,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 diff --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 +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 < +#include +#include + +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 !' >>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'