From patchwork Mon Mar 28 17:21:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12793954 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C719FC433FE for ; Mon, 28 Mar 2022 17:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237418AbiC1RYT (ORCPT ); Mon, 28 Mar 2022 13:24:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232718AbiC1RYT (ORCPT ); Mon, 28 Mar 2022 13:24:19 -0400 Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BF3864BD1; Mon, 28 Mar 2022 10:22:37 -0700 (PDT) Received: from grover.. (133-32-185-133.west.xps.vectant.ne.jp [133.32.185.133]) (authenticated) by conuserg-12.nifty.com with ESMTP id 22SHLdGZ017332; Tue, 29 Mar 2022 02:21:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 22SHLdGZ017332 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1648488100; bh=UH1VDPx6gdMj3puEVBexYhQw2eBB8T7IsyNihS4F0YM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ov2CdN5oQp5TdxkGzLQIabmizxCidhSCe2jkecUC2Jq9B3bLXl3Amuypl11knvFxH zVvOPyiEb2bcuTrKFa0xKgHp5J4TL2xG4JF2p9dpnvwnO/r2Mvx+bISGokVSkRx3tL 3IOSC8xdtSKS1GdN3z+hoV88w0tZZDT511BP51yCVZCcYuPlm6VoWr0tHdynR+qsc3 zGAsqzfk8OQvxw/FSRqLy84uc/Bq/Xk26kOn/GCKJzP94mvRRMmpiVsOgINjJ9UEMp 8qkmwB9JJF/qasA9MuXNQErhk5LtIEBvTSRQgOUEvejeZi92XLgC4HWpg0J8+6W+M6 62MnpZKhFg3/Q== X-Nifty-SrcIP: [133.32.185.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , linux-kernel@vger.kernel.org, Masahiro Yamada , "Dmitry V. Levin" , Elliot Berman , Geert Uytterhoeven , Greg Kroah-Hartman , Nick Desaulniers Subject: [PATCH 2/2] kbuild: forbid exported headers from including , Date: Tue, 29 Mar 2022 02:21:30 +0900 Message-Id: <20220328172130.197319-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220328172130.197319-1-masahiroy@kernel.org> References: <20220328172130.197319-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Some UAPI headers included , like this: #ifndef __KERNEL__ #include #endif As it turned out, they just included it for no good reason. After some fixes, now I can compile-test UAPI headers (CONFIG_UAPI_HEADER_TEST=y) without included. To avoid somebody getting it back again, this commit adds the dummy header, usr/dummy-include/stdlib.h I added $(srctree)/usr/dummy-include to the header search paths. Because it is searched before the system directories, if someone tries to include , they will see the error message. While I am here, I also replaced $(objtree)/usr/include with $(obj), but it is just a small refactoring. If we achieve the situation where none of system headers is included from exported kernel headers (i.e. kernel headers become self-contained), we might be able to add -nostdinc, but that is much far from where we stand now. (see many no-header-test lines in usr/include/Makefile) As a realistic solution, you can forbid header inclusion individually by putting a dummy header into usr/dummy-include/. Currently, no header include . I put it as well before somebody attempts to use it. Signed-off-by: Masahiro Yamada Reviewed-by: Greg Kroah-Hartman --- usr/dummy-include/stdbool.h | 7 +++++++ usr/dummy-include/stdlib.h | 7 +++++++ usr/include/Makefile | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 usr/dummy-include/stdbool.h create mode 100644 usr/dummy-include/stdlib.h diff --git a/usr/dummy-include/stdbool.h b/usr/dummy-include/stdbool.h new file mode 100644 index 000000000000..54ff9e9c90ac --- /dev/null +++ b/usr/dummy-include/stdbool.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _STDBOOL_H +#define _STDBOOL_H + +#error "Please do not include from exported headers" + +#endif /* _STDBOOL_H */ diff --git a/usr/dummy-include/stdlib.h b/usr/dummy-include/stdlib.h new file mode 100644 index 000000000000..e8c21888e371 --- /dev/null +++ b/usr/dummy-include/stdlib.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _STDLIB_H +#define _STDLIB_H + +#error "Please do not include from exported headers" + +#endif /* _STDLIB_H */ diff --git a/usr/include/Makefile b/usr/include/Makefile index fa9819e022b7..7740777b49f8 100644 --- a/usr/include/Makefile +++ b/usr/include/Makefile @@ -15,7 +15,7 @@ UAPI_CFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) # USERCFLAGS might contain sysroot location for CC. UAPI_CFLAGS += $(USERCFLAGS) -override c_flags = $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I$(objtree)/usr/include +override c_flags = $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I $(obj) -I $(srctree)/usr/dummy-include # The following are excluded for now because they fail to build. #