Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f716a85c authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull kbuild updates from Michal Marek:

 - GCC plugin support by Emese Revfy from grsecurity, with a fixup from
   Kees Cook.  The plugins are meant to be used for static analysis of
   the kernel code.  Two plugins are provided already.

 - reduction of the gcc commandline by Arnd Bergmann.

 - IS_ENABLED / IS_REACHABLE macro enhancements by Masahiro Yamada

 - bin2c fix by Michael Tautschnig

 - setlocalversion fix by Wolfram Sang

* 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild:
  gcc-plugins: disable under COMPILE_TEST
  kbuild: Abort build on bad stack protector flag
  scripts: Fix size mismatch of kexec_purgatory_size
  kbuild: make samples depend on headers_install
  Kbuild: don't add obj tree in additional includes
  Kbuild: arch: look for generated headers in obtree
  Kbuild: always prefix objtree in LINUXINCLUDE
  Kbuild: avoid duplicate include path
  Kbuild: don't add ../../ to include path
  vmlinux.lds.h: replace config_enabled() with IS_ENABLED()
  kconfig.h: allow to use IS_{ENABLE,REACHABLE} in macro expansion
  kconfig.h: use already defined macros for IS_REACHABLE() define
  export.h: use __is_defined() to check if __KSYM_* is defined
  kconfig.h: use __is_defined() to check if MODULE is defined
  kbuild: setlocalversion: print error to STDERR
  Add sancov plugin
  Add Cyclomatic complexity GCC plugin
  GCC plugin infrastructure
  Shared library support
parents 221bb8a4 a519167e
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ modules.builtin
Module.symvers
Module.symvers
*.dwo
*.dwo
*.su
*.su
*.c.[012]*.*


#
#
# Top-level generic files
# Top-level generic files
+1 −0
Original line number Original line Diff line number Diff line
@@ -3,6 +3,7 @@
*.bc
*.bc
*.bin
*.bin
*.bz2
*.bz2
*.c.[012]*.*
*.cis
*.cis
*.cpio
*.cpio
*.csp
*.csp
+87 −0
Original line number Original line Diff line number Diff line
GCC plugin infrastructure
=========================


1. Introduction
===============

GCC plugins are loadable modules that provide extra features to the
compiler [1]. They are useful for runtime instrumentation and static analysis.
We can analyse, change and add further code during compilation via
callbacks [2], GIMPLE [3], IPA [4] and RTL passes [5].

The GCC plugin infrastructure of the kernel supports all gcc versions from
4.5 to 6.0, building out-of-tree modules, cross-compilation and building in a
separate directory.
Plugin source files have to be compilable by both a C and a C++ compiler as well
because gcc versions 4.5 and 4.6 are compiled by a C compiler,
gcc-4.7 can be compiled by a C or a C++ compiler,
and versions 4.8+ can only be compiled by a C++ compiler.

Currently the GCC plugin infrastructure supports only the x86, arm and arm64
architectures.

This infrastructure was ported from grsecurity [6] and PaX [7].

--
[1] https://gcc.gnu.org/onlinedocs/gccint/Plugins.html
[2] https://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html#Plugin-API
[3] https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html
[4] https://gcc.gnu.org/onlinedocs/gccint/IPA.html
[5] https://gcc.gnu.org/onlinedocs/gccint/RTL.html
[6] https://grsecurity.net/
[7] https://pax.grsecurity.net/


2. Files
========

$(src)/scripts/gcc-plugins
	This is the directory of the GCC plugins.

$(src)/scripts/gcc-plugins/gcc-common.h
	This is a compatibility header for GCC plugins.
	It should be always included instead of individual gcc headers.

$(src)/scripts/gcc-plugin.sh
	This script checks the availability of the included headers in
	gcc-common.h and chooses the proper host compiler to build the plugins
	(gcc-4.7 can be built by either gcc or g++).

$(src)/scripts/gcc-plugins/gcc-generate-gimple-pass.h
$(src)/scripts/gcc-plugins/gcc-generate-ipa-pass.h
$(src)/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h
$(src)/scripts/gcc-plugins/gcc-generate-rtl-pass.h
	These headers automatically generate the registration structures for
	GIMPLE, SIMPLE_IPA, IPA and RTL passes. They support all gcc versions
	from 4.5 to 6.0.
	They should be preferred to creating the structures by hand.


3. Usage
========

You must install the gcc plugin headers for your gcc version,
e.g., on Ubuntu for gcc-4.9:

	apt-get install gcc-4.9-plugin-dev

Enable a GCC plugin based feature in the kernel config:

	CONFIG_GCC_PLUGIN_CYC_COMPLEXITY = y

To compile only the plugin(s):

	make gcc-plugins

or just run the kernel make and compile the whole kernel with
the cyclomatic complexity GCC plugin.


4. How to add a new GCC plugin
==============================

The GCC plugins are in $(src)/scripts/gcc-plugins/. You can use a file or a directory
here. It must be added to $(src)/scripts/gcc-plugins/Makefile,
$(src)/scripts/Makefile.gcc-plugins and $(src)/arch/Kconfig.
See the cyc_complexity_plugin.c (CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) GCC plugin.
+9 −0
Original line number Original line Diff line number Diff line
@@ -5094,6 +5094,15 @@ L: linux-scsi@vger.kernel.org
S:	Odd Fixes (e.g., new signatures)
S:	Odd Fixes (e.g., new signatures)
F:	drivers/scsi/fdomain.*
F:	drivers/scsi/fdomain.*


GCC PLUGINS
M:	Kees Cook <keescook@chromium.org>
R:	Emese Revfy <re.emese@gmail.com>
L:	kernel-hardening@lists.openwall.com
S:	Maintained
F:	scripts/gcc-plugins/
F:	scripts/gcc-plugin.sh
F:	Documentation/gcc-plugins.txt

GCOV BASED KERNEL PROFILING
GCOV BASED KERNEL PROFILING
M:	Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
M:	Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
S:	Maintained
S:	Maintained
+23 −22
Original line number Original line Diff line number Diff line
@@ -371,26 +371,27 @@ CFLAGS_KERNEL =
AFLAGS_KERNEL	=
AFLAGS_KERNEL	=
LDFLAGS_vmlinux =
LDFLAGS_vmlinux =
CFLAGS_GCOV	= -fprofile-arcs -ftest-coverage -fno-tree-loop-im
CFLAGS_GCOV	= -fprofile-arcs -ftest-coverage -fno-tree-loop-im
CFLAGS_KCOV	= -fsanitize-coverage=trace-pc
CFLAGS_KCOV	:= $(call cc-option,-fsanitize-coverage=trace-pc,)




# Use USERINCLUDE when you must reference the UAPI directories only.
# Use USERINCLUDE when you must reference the UAPI directories only.
USERINCLUDE    := \
USERINCLUDE    := \
		-I$(srctree)/arch/$(hdr-arch)/include/uapi \
		-I$(srctree)/arch/$(hdr-arch)/include/uapi \
		-Iarch/$(hdr-arch)/include/generated/uapi \
		-I$(objtree)/arch/$(hdr-arch)/include/generated/uapi \
		-I$(srctree)/include/uapi \
		-I$(srctree)/include/uapi \
		-Iinclude/generated/uapi \
		-I$(objtree)/include/generated/uapi \
                -include $(srctree)/include/linux/kconfig.h
                -include $(srctree)/include/linux/kconfig.h


# Use LINUXINCLUDE when you must reference the include/ directory.
# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
# Needed to be compatible with the O= option
LINUXINCLUDE    := \
LINUXINCLUDE    := \
		-I$(srctree)/arch/$(hdr-arch)/include \
		-I$(srctree)/arch/$(hdr-arch)/include \
		-Iarch/$(hdr-arch)/include/generated/uapi \
		-I$(objtree)/arch/$(hdr-arch)/include/generated/uapi \
		-Iarch/$(hdr-arch)/include/generated \
		-I$(objtree)/arch/$(hdr-arch)/include/generated \
		$(if $(KBUILD_SRC), -I$(srctree)/include) \
		$(if $(KBUILD_SRC), -I$(srctree)/include) \
		-Iinclude \
		-I$(objtree)/include
		$(USERINCLUDE)

LINUXINCLUDE	+= $(filter-out $(LINUXINCLUDE),$(USERINCLUDE))


KBUILD_CPPFLAGS := -D__KERNEL__
KBUILD_CPPFLAGS := -D__KERNEL__


@@ -554,7 +555,7 @@ ifeq ($(KBUILD_EXTMOD),)
# in parallel
# in parallel
PHONY += scripts
PHONY += scripts
scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \
scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \
	 asm-generic
	 asm-generic gcc-plugins
	$(Q)$(MAKE) $(build)=$(@)
	$(Q)$(MAKE) $(build)=$(@)


# Objects we will link into vmlinux / subdirs we need to visit
# Objects we will link into vmlinux / subdirs we need to visit
@@ -635,6 +636,15 @@ endif
# Tell gcc to never replace conditional load with a non-conditional one
# Tell gcc to never replace conditional load with a non-conditional one
KBUILD_CFLAGS	+= $(call cc-option,--param=allow-store-data-races=0)
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
ifdef CONFIG_READABLE_ASM
# Disable optimizations that make assembler listings hard to read.
# Disable optimizations that make assembler listings hard to read.
# reorder blocks reorders the control in the function
# reorder blocks reorders the control in the function
@@ -666,21 +676,11 @@ endif
endif
endif
# Find arch-specific stack protector compiler sanity-checking script.
# Find arch-specific stack protector compiler sanity-checking script.
ifdef CONFIG_CC_STACKPROTECTOR
ifdef CONFIG_CC_STACKPROTECTOR
  stackp-path := $(srctree)/scripts/gcc-$(ARCH)_$(BITS)-has-stack-protector.sh
  stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh
  ifneq ($(wildcard $(stackp-path)),)
  stackp-check := $(wildcard $(stackp-path))
    stackp-check := $(stackp-path)
  endif
endif
endif
KBUILD_CFLAGS += $(stackp-flag)
KBUILD_CFLAGS += $(stackp-flag)


ifdef CONFIG_KCOV
  ifeq ($(call cc-option, $(CFLAGS_KCOV)),)
    $(warning Cannot use CONFIG_KCOV: \
             -fsanitize-coverage=trace-pc is not supported by compiler)
    CFLAGS_KCOV =
  endif
endif

ifeq ($(cc-name),clang)
ifeq ($(cc-name),clang)
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)
KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)
@@ -1019,7 +1019,7 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \


archprepare: archheaders archscripts prepare1 scripts_basic
archprepare: archheaders archscripts prepare1 scripts_basic


prepare0: archprepare
prepare0: archprepare gcc-plugins
	$(Q)$(MAKE) $(build)=.
	$(Q)$(MAKE) $(build)=.


# All the preparing..
# All the preparing..
@@ -1531,6 +1531,7 @@ clean: $(clean-dirs)
		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
		-o -name '*.symtypes' -o -name 'modules.order' \
		-o -name '*.symtypes' -o -name 'modules.order' \
		-o -name modules.builtin -o -name '.tmp_*.o.*' \
		-o -name modules.builtin -o -name '.tmp_*.o.*' \
		-o -name '*.c.[012]*.*' \
		-o -name '*.gcno' \) -type f -print | xargs rm -f
		-o -name '*.gcno' \) -type f -print | xargs rm -f


# Generate tags for editors
# Generate tags for editors
@@ -1641,7 +1642,7 @@ endif
	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
	$(build)=$(build-dir)
	$(build)=$(build-dir)
# Make sure the latest headers are built for Documentation
# Make sure the latest headers are built for Documentation
Documentation/: headers_install
Documentation/ samples/: headers_install
%/: prepare scripts FORCE
%/: prepare scripts FORCE
	$(cmd_crmodverdir)
	$(cmd_crmodverdir)
	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
Loading