From patchwork Wed Apr 13 02:35:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 8817941 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6BD079F54F for ; Wed, 13 Apr 2016 02:35:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 31F8320219 for ; Wed, 13 Apr 2016 02:35:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BA9E201F2 for ; Wed, 13 Apr 2016 02:35:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757612AbcDMCfq (ORCPT ); Tue, 12 Apr 2016 22:35:46 -0400 Received: from conssluserg-03.nifty.com ([210.131.2.82]:62825 "EHLO conssluserg-03.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757605AbcDMCfp (ORCPT ); Tue, 12 Apr 2016 22:35:45 -0400 Received: from mail-yw0-f169.google.com (mail-yw0-f169.google.com [209.85.161.169]) (authenticated) by conssluserg-03.nifty.com with ESMTP id u3D2ZQuU000791; Wed, 13 Apr 2016 11:35:27 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com u3D2ZQuU000791 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1460514927; bh=giEqT1cKddDcp/OGquvhd+d2he2YSMFW0AkKUa4BTFA=; h=In-Reply-To:References:Date:Subject:From:To:Cc:From; b=FKeQFPLX6FYB2UC/9ZV87tbShogZyblx7TdrCKx8bEDXOyjnmUauN1qDDXw//zvFC yhkovkXzcSEkr+NbYYOC8Gdg5Lhe65vDEeUocVCDREJJMGLF0cBElfdtQOWSCpnhJJ D8N2g8sGp9S9bBhlA1kuUR4wYffbR5WpNsffHgqiERzSB2YuTpR6L0PJxWHhHBG5Ix vTD4Hm7SkoYqteOr5wkL++6FZ2RD8/dZWM9YepdsnADsG7taacRZnaS/O627lCIfQY R6hSKSPtD1P1WBO9KxvnFEDrEp8tmHgjf8rafCf+iUT3ty98nvZN29SqOmvIRqqRI5 KFuFi9MYWukMQ== X-Nifty-SrcIP: [209.85.161.169] Received: by mail-yw0-f169.google.com with SMTP id o66so51092176ywc.3; Tue, 12 Apr 2016 19:35:27 -0700 (PDT) X-Gm-Message-State: AOPr4FUh2wb8ex8E0IpViReOr4Uw48RXgcW4mRm6MjlUe559z+SvkHvL4bm/zRfMyu/Uu/4Zhk94k6BN9q4ciQ== MIME-Version: 1.0 X-Received: by 10.13.226.211 with SMTP id l202mr3621164ywe.294.1460514926205; Tue, 12 Apr 2016 19:35:26 -0700 (PDT) Received: by 10.37.118.79 with HTTP; Tue, 12 Apr 2016 19:35:26 -0700 (PDT) In-Reply-To: <20160407231300.d99272db798388cad1d2e22a@gmail.com> References: <20160407231023.5f1307ffc79f0cdd880eedb7@gmail.com> <20160407231300.d99272db798388cad1d2e22a@gmail.com> Date: Wed, 13 Apr 2016 11:35:26 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 2/6] GCC plugin infrastructure From: Masahiro Yamada To: Emese Revfy Cc: Linux Kbuild mailing list , pageexec@freemail.hu, spender@grsecurity.net, kernel-hardening@lists.openwall.com, Michal Marek , Kees Cook , Rasmus Villemoes , fengguang.wu@intel.com, Dmitry Vyukov , Linux Kernel Mailing List , David Brown Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Emese, 2016-04-08 6:13 GMT+09:00 Emese Revfy : > diff --git a/Makefile b/Makefile > index 173437d..3af7b9e 100644 > --- a/Makefile > +++ b/Makefile > @@ -418,6 +418,8 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE > export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL > export KBUILD_ARFLAGS > > +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS > + > # When compiling out-of-tree modules, put MODVERDIR in the module > # tree rather than in the kernel tree. The kernel tree might > # even be read-only. > @@ -548,7 +550,7 @@ ifeq ($(KBUILD_EXTMOD),) > # in parallel > PHONY += scripts > scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \ > - asm-generic > + asm-generic gcc-plugins > $(Q)$(MAKE) $(build)=$(@) > > # Objects we will link into vmlinux / subdirs we need to visit > @@ -623,6 +625,15 @@ endif > # Tell gcc to never replace conditional load with a non-conditional one > KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) > > +PHONY += gcc-plugins > +gcc-plugins: scripts_basic > +ifdef CONFIG_GCC_PLUGINS > + $(Q)$(MAKE) $(build)=scripts/gcc-plugins > +endif > + @: > + > +include scripts/Makefile.gcc-plugins > + > ifdef CONFIG_READABLE_ASM > # Disable optimizations that make assembler listings hard to read. > # reorder blocks reorders the control in the function > @@ -949,6 +960,8 @@ endif > > # The actual objects are generated when descending, > # make sure no implicit rule kicks in > +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) > +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) > $(sort $(vmlinux-deps)): $(vmlinux-dirs) ; I do not get your intention here. It looks like you are trying to omit plugin flags for init/ directory. (Actually this code is not working, though) Then, you add plug the following lines to init/Makefile +ccflags-y := $(GCC_PLUGINS_CFLAGS) +asflags-y := $(GCC_PLUGINS_AFLAGS) > # Handle descending into subdirectories listed in $(vmlinux-dirs) > @@ -1001,10 +1014,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \ > > archprepare: archheaders archscripts prepare1 scripts_basic > > -prepare0: archprepare FORCE > +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) > +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) > +prepare0: archprepare gcc-plugins FORCE > $(Q)$(MAKE) $(build)=. > > # All the preparing.. > +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) > prepare: prepare0 prepare-objtool > > ifdef CONFIG_STACK_VALIDATION > @@ -1137,6 +1153,8 @@ all: modules > # using awk while concatenating to the final file. > > PHONY += modules > +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) > +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) > modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin > $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order > @$(kecho) ' Building modules, stage 2.'; > @@ -1257,7 +1275,7 @@ distclean: mrproper > @find $(srctree) $(RCS_FIND_IGNORE) \ > \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ > -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ > - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \ > + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \ > -type f -print | xargs rm -f > > > @@ -1426,6 +1444,8 @@ PHONY += $(module-dirs) modules > $(module-dirs): crmodverdir $(objtree)/Module.symvers > $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@) > > +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) > +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) > modules: $(module-dirs) > @$(kecho) ' Building modules, stage 2.'; > $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost > @@ -1567,10 +1587,14 @@ else > target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@)) > endif > > +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) > +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) > %.s: %.c prepare scripts FORCE > $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) > %.i: %.c prepare scripts FORCE > $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) > +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) > +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) > %.o: %.c prepare scripts FORCE > $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) > %.lst: %.c prepare scripts FORCE > @@ -1589,10 +1613,14 @@ endif > $(build)=$(build-dir) > # Make sure the latest headers are built for Documentation > Documentation/: headers_install > +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) > +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) > %/: prepare scripts FORCE > $(cmd_crmodverdir) > $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ > $(build)=$(build-dir) > +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) > +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) > %.ko: prepare scripts FORCE > $(cmd_crmodverdir) > $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ Why do you need to sprinkle "KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)" here and there? Unless I am missing something, I think the following should work. diff --git a/Makefile b/Makefile index 5d65f4b..f85420b 100644 --- a/Makefile +++ b/Makefile @@ -962,8 +962,6 @@ endif # The actual objects are generated when descending, # make sure no implicit rule kicks in -$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) -$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) $(sort $(vmlinux-deps)): $(vmlinux-dirs) ; # Handle descending into subdirectories listed in $(vmlinux-dirs) @@ -1016,13 +1014,10 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h archprepare: archheaders archscripts prepare1 scripts_basic -prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) -prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) prepare0: archprepare gcc-plugins FORCE $(Q)$(MAKE) $(build)=. # All the preparing.. -prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) prepare: prepare0 prepare-objtool ifdef CONFIG_STACK_VALIDATION @@ -1155,8 +1150,6 @@ all: modules # using awk while concatenating to the final file. PHONY += modules -modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) -modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtre @$(kecho) ' Building modules, stage 2.'; @@ -1446,8 +1439,6 @@ PHONY += $(module-dirs) modules $(module-dirs): crmodverdir $(objtree)/Module.symvers $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@) -modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) -modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) modules: $(module-dirs) @$(kecho) ' Building modules, stage 2.'; $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost @@ -1589,14 +1580,10 @@ else target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@)) endif -%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) -%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) %.s: %.c prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.i: %.c prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) -%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) -%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) %.o: %.c prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.lst: %.c prepare scripts FORCE @@ -1615,14 +1602,10 @@ endif $(build)=$(build-dir) # Make sure the latest headers are built for Documentation Documentation/: headers_install -%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) -%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) %/: prepare scripts FORCE $(cmd_crmodverdir) $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ $(build)=$(build-dir) -%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) -%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS) %.ko: prepare scripts FORCE $(cmd_crmodverdir) $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index 25a70fb..34d6224 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -26,4 +26,6 @@ ifdef CONFIG_GCC_PLUGINS endif endif + KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) + endif