aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Documentation/dontdiff1
-rw-r--r--Documentation/gcc-plugins.txt87
-rw-r--r--MAINTAINERS9
-rw-r--r--Makefile45
-rw-r--r--arch/Kconfig37
-rw-r--r--arch/alpha/boot/Makefile2
-rw-r--r--arch/arm/Kconfig1
-rw-r--r--arch/arm64/Kconfig1
-rw-r--r--arch/powerpc/boot/Makefile2
-rw-r--r--arch/powerpc/kvm/Makefile2
-rw-r--r--arch/s390/boot/compressed/Makefile4
-rw-r--r--arch/um/Kconfig.common1
-rw-r--r--arch/um/Makefile4
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/boot/Makefile2
-rw-r--r--arch/x86/entry/vdso/Makefile3
-rw-r--r--arch/x86/purgatory/Makefile2
-rw-r--r--arch/x86/realmode/rm/Makefile2
-rw-r--r--include/asm-generic/vmlinux.lds.h2
-rw-r--r--include/linux/export.h2
-rw-r--r--include/linux/kconfig.h31
-rw-r--r--lib/Kconfig.debug2
-rw-r--r--scripts/Kbuild.include2
-rw-r--r--scripts/Makefile2
-rw-r--r--scripts/Makefile.build2
-rw-r--r--scripts/Makefile.clean4
-rw-r--r--scripts/Makefile.gcc-plugins43
-rw-r--r--scripts/Makefile.host55
-rw-r--r--scripts/Makefile.lib7
-rw-r--r--scripts/basic/bin2c.c3
-rwxr-xr-xscripts/gcc-plugin.sh51
-rw-r--r--scripts/gcc-plugins/Makefile27
-rw-r--r--scripts/gcc-plugins/cyc_complexity_plugin.c73
-rw-r--r--scripts/gcc-plugins/gcc-common.h830
-rw-r--r--scripts/gcc-plugins/gcc-generate-gimple-pass.h175
-rw-r--r--scripts/gcc-plugins/gcc-generate-ipa-pass.h289
-rw-r--r--scripts/gcc-plugins/gcc-generate-rtl-pass.h175
-rw-r--r--scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h175
-rw-r--r--scripts/gcc-plugins/sancov_plugin.c144
-rwxr-xr-xscripts/link-vmlinux.sh2
-rwxr-xr-xscripts/package/builddeb1
-rwxr-xr-xscripts/setlocalversion2
43 files changed, 2252 insertions, 54 deletions
diff --git a/.gitignore b/.gitignore
index 0c320bf02586..2be25f771bd8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,6 +37,7 @@ modules.builtin
37Module.symvers 37Module.symvers
38*.dwo 38*.dwo
39*.su 39*.su
40*.c.[012]*.*
40 41
41# 42#
42# Top-level generic files 43# Top-level generic files
diff --git a/Documentation/dontdiff b/Documentation/dontdiff
index 8ea834f6b289..5385cba941d2 100644
--- a/Documentation/dontdiff
+++ b/Documentation/dontdiff
@@ -3,6 +3,7 @@
3*.bc 3*.bc
4*.bin 4*.bin
5*.bz2 5*.bz2
6*.c.[012]*.*
6*.cis 7*.cis
7*.cpio 8*.cpio
8*.csp 9*.csp
diff --git a/Documentation/gcc-plugins.txt b/Documentation/gcc-plugins.txt
new file mode 100644
index 000000000000..891c69464434
--- /dev/null
+++ b/Documentation/gcc-plugins.txt
@@ -0,0 +1,87 @@
1GCC plugin infrastructure
2=========================
3
4
51. Introduction
6===============
7
8GCC plugins are loadable modules that provide extra features to the
9compiler [1]. They are useful for runtime instrumentation and static analysis.
10We can analyse, change and add further code during compilation via
11callbacks [2], GIMPLE [3], IPA [4] and RTL passes [5].
12
13The GCC plugin infrastructure of the kernel supports all gcc versions from
144.5 to 6.0, building out-of-tree modules, cross-compilation and building in a
15separate directory.
16Plugin source files have to be compilable by both a C and a C++ compiler as well
17because gcc versions 4.5 and 4.6 are compiled by a C compiler,
18gcc-4.7 can be compiled by a C or a C++ compiler,
19and versions 4.8+ can only be compiled by a C++ compiler.
20
21Currently the GCC plugin infrastructure supports only the x86, arm and arm64
22architectures.
23
24This infrastructure was ported from grsecurity [6] and PaX [7].
25
26--
27[1] https://gcc.gnu.org/onlinedocs/gccint/Plugins.html
28[2] https://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html#Plugin-API
29[3] https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html
30[4] https://gcc.gnu.org/onlinedocs/gccint/IPA.html
31[5] https://gcc.gnu.org/onlinedocs/gccint/RTL.html
32[6] https://grsecurity.net/
33[7] https://pax.grsecurity.net/
34
35
362. Files
37========
38
39$(src)/scripts/gcc-plugins
40 This is the directory of the GCC plugins.
41
42$(src)/scripts/gcc-plugins/gcc-common.h
43 This is a compatibility header for GCC plugins.
44 It should be always included instead of individual gcc headers.
45
46$(src)/scripts/gcc-plugin.sh
47 This script checks the availability of the included headers in
48 gcc-common.h and chooses the proper host compiler to build the plugins
49 (gcc-4.7 can be built by either gcc or g++).
50
51$(src)/scripts/gcc-plugins/gcc-generate-gimple-pass.h
52$(src)/scripts/gcc-plugins/gcc-generate-ipa-pass.h
53$(src)/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h
54$(src)/scripts/gcc-plugins/gcc-generate-rtl-pass.h
55 These headers automatically generate the registration structures for
56 GIMPLE, SIMPLE_IPA, IPA and RTL passes. They support all gcc versions
57 from 4.5 to 6.0.
58 They should be preferred to creating the structures by hand.
59
60
613. Usage
62========
63
64You must install the gcc plugin headers for your gcc version,
65e.g., on Ubuntu for gcc-4.9:
66
67 apt-get install gcc-4.9-plugin-dev
68
69Enable a GCC plugin based feature in the kernel config:
70
71 CONFIG_GCC_PLUGIN_CYC_COMPLEXITY = y
72
73To compile only the plugin(s):
74
75 make gcc-plugins
76
77or just run the kernel make and compile the whole kernel with
78the cyclomatic complexity GCC plugin.
79
80
814. How to add a new GCC plugin
82==============================
83
84The GCC plugins are in $(src)/scripts/gcc-plugins/. You can use a file or a directory
85here. It must be added to $(src)/scripts/gcc-plugins/Makefile,
86$(src)/scripts/Makefile.gcc-plugins and $(src)/arch/Kconfig.
87See the cyc_complexity_plugin.c (CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) GCC plugin.
diff --git a/MAINTAINERS b/MAINTAINERS
index 25f43204014d..8f950e2752de 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5094,6 +5094,15 @@ L: linux-scsi@vger.kernel.org
5094S: Odd Fixes (e.g., new signatures) 5094S: Odd Fixes (e.g., new signatures)
5095F: drivers/scsi/fdomain.* 5095F: drivers/scsi/fdomain.*
5096 5096
5097GCC PLUGINS
5098M: Kees Cook <keescook@chromium.org>
5099R: Emese Revfy <re.emese@gmail.com>
5100L: kernel-hardening@lists.openwall.com
5101S: Maintained
5102F: scripts/gcc-plugins/
5103F: scripts/gcc-plugin.sh
5104F: Documentation/gcc-plugins.txt
5105
5097GCOV BASED KERNEL PROFILING 5106GCOV BASED KERNEL PROFILING
5098M: Peter Oberparleiter <oberpar@linux.vnet.ibm.com> 5107M: Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
5099S: Maintained 5108S: Maintained
diff --git a/Makefile b/Makefile
index 393b6159ae92..d6d401bf9d95 100644
--- a/Makefile
+++ b/Makefile
@@ -371,26 +371,27 @@ CFLAGS_KERNEL =
371AFLAGS_KERNEL = 371AFLAGS_KERNEL =
372LDFLAGS_vmlinux = 372LDFLAGS_vmlinux =
373CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im 373CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im
374CFLAGS_KCOV = -fsanitize-coverage=trace-pc 374CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,)
375 375
376 376
377# Use USERINCLUDE when you must reference the UAPI directories only. 377# Use USERINCLUDE when you must reference the UAPI directories only.
378USERINCLUDE := \ 378USERINCLUDE := \
379 -I$(srctree)/arch/$(hdr-arch)/include/uapi \ 379 -I$(srctree)/arch/$(hdr-arch)/include/uapi \
380 -Iarch/$(hdr-arch)/include/generated/uapi \ 380 -I$(objtree)/arch/$(hdr-arch)/include/generated/uapi \
381 -I$(srctree)/include/uapi \ 381 -I$(srctree)/include/uapi \
382 -Iinclude/generated/uapi \ 382 -I$(objtree)/include/generated/uapi \
383 -include $(srctree)/include/linux/kconfig.h 383 -include $(srctree)/include/linux/kconfig.h
384 384
385# Use LINUXINCLUDE when you must reference the include/ directory. 385# Use LINUXINCLUDE when you must reference the include/ directory.
386# Needed to be compatible with the O= option 386# Needed to be compatible with the O= option
387LINUXINCLUDE := \ 387LINUXINCLUDE := \
388 -I$(srctree)/arch/$(hdr-arch)/include \ 388 -I$(srctree)/arch/$(hdr-arch)/include \
389 -Iarch/$(hdr-arch)/include/generated/uapi \ 389 -I$(objtree)/arch/$(hdr-arch)/include/generated/uapi \
390 -Iarch/$(hdr-arch)/include/generated \ 390 -I$(objtree)/arch/$(hdr-arch)/include/generated \
391 $(if $(KBUILD_SRC), -I$(srctree)/include) \ 391 $(if $(KBUILD_SRC), -I$(srctree)/include) \
392 -Iinclude \ 392 -I$(objtree)/include
393 $(USERINCLUDE) 393
394LINUXINCLUDE += $(filter-out $(LINUXINCLUDE),$(USERINCLUDE))
394 395
395KBUILD_CPPFLAGS := -D__KERNEL__ 396KBUILD_CPPFLAGS := -D__KERNEL__
396 397
@@ -554,7 +555,7 @@ ifeq ($(KBUILD_EXTMOD),)
554# in parallel 555# in parallel
555PHONY += scripts 556PHONY += scripts
556scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \ 557scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \
557 asm-generic 558 asm-generic gcc-plugins
558 $(Q)$(MAKE) $(build)=$(@) 559 $(Q)$(MAKE) $(build)=$(@)
559 560
560# Objects we will link into vmlinux / subdirs we need to visit 561# Objects we will link into vmlinux / subdirs we need to visit
@@ -635,6 +636,15 @@ endif
635# Tell gcc to never replace conditional load with a non-conditional one 636# Tell gcc to never replace conditional load with a non-conditional one
636KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) 637KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
637 638
639PHONY += gcc-plugins
640gcc-plugins: scripts_basic
641ifdef CONFIG_GCC_PLUGINS
642 $(Q)$(MAKE) $(build)=scripts/gcc-plugins
643endif
644 @:
645
646include scripts/Makefile.gcc-plugins
647
638ifdef CONFIG_READABLE_ASM 648ifdef CONFIG_READABLE_ASM
639# Disable optimizations that make assembler listings hard to read. 649# Disable optimizations that make assembler listings hard to read.
640# reorder blocks reorders the control in the function 650# reorder blocks reorders the control in the function
@@ -666,21 +676,11 @@ endif
666endif 676endif
667# Find arch-specific stack protector compiler sanity-checking script. 677# Find arch-specific stack protector compiler sanity-checking script.
668ifdef CONFIG_CC_STACKPROTECTOR 678ifdef CONFIG_CC_STACKPROTECTOR
669 stackp-path := $(srctree)/scripts/gcc-$(ARCH)_$(BITS)-has-stack-protector.sh 679 stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh
670 ifneq ($(wildcard $(stackp-path)),) 680 stackp-check := $(wildcard $(stackp-path))
671 stackp-check := $(stackp-path)
672 endif
673endif 681endif
674KBUILD_CFLAGS += $(stackp-flag) 682KBUILD_CFLAGS += $(stackp-flag)
675 683
676ifdef CONFIG_KCOV
677 ifeq ($(call cc-option, $(CFLAGS_KCOV)),)
678 $(warning Cannot use CONFIG_KCOV: \
679 -fsanitize-coverage=trace-pc is not supported by compiler)
680 CFLAGS_KCOV =
681 endif
682endif
683
684ifeq ($(cc-name),clang) 684ifeq ($(cc-name),clang)
685KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) 685KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
686KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,) 686KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)
@@ -1019,7 +1019,7 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
1019 1019
1020archprepare: archheaders archscripts prepare1 scripts_basic 1020archprepare: archheaders archscripts prepare1 scripts_basic
1021 1021
1022prepare0: archprepare 1022prepare0: archprepare gcc-plugins
1023 $(Q)$(MAKE) $(build)=. 1023 $(Q)$(MAKE) $(build)=.
1024 1024
1025# All the preparing.. 1025# All the preparing..
@@ -1531,6 +1531,7 @@ clean: $(clean-dirs)
1531 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 1531 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1532 -o -name '*.symtypes' -o -name 'modules.order' \ 1532 -o -name '*.symtypes' -o -name 'modules.order' \
1533 -o -name modules.builtin -o -name '.tmp_*.o.*' \ 1533 -o -name modules.builtin -o -name '.tmp_*.o.*' \
1534 -o -name '*.c.[012]*.*' \
1534 -o -name '*.gcno' \) -type f -print | xargs rm -f 1535 -o -name '*.gcno' \) -type f -print | xargs rm -f
1535 1536
1536# Generate tags for editors 1537# Generate tags for editors
@@ -1641,7 +1642,7 @@ endif
1641 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ 1642 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1642 $(build)=$(build-dir) 1643 $(build)=$(build-dir)
1643# Make sure the latest headers are built for Documentation 1644# Make sure the latest headers are built for Documentation
1644Documentation/: headers_install 1645Documentation/ samples/: headers_install
1645%/: prepare scripts FORCE 1646%/: prepare scripts FORCE
1646 $(cmd_crmodverdir) 1647 $(cmd_crmodverdir)
1647 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ 1648 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
diff --git a/arch/Kconfig b/arch/Kconfig
index 15996290fed4..bd8056b5b246 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -357,6 +357,43 @@ config SECCOMP_FILTER
357 357
358 See Documentation/prctl/seccomp_filter.txt for details. 358 See Documentation/prctl/seccomp_filter.txt for details.
359 359
360config HAVE_GCC_PLUGINS
361 bool
362 help
363 An arch should select this symbol if it supports building with
364 GCC plugins.
365
366menuconfig GCC_PLUGINS
367 bool "GCC plugins"
368 depends on HAVE_GCC_PLUGINS
369 depends on !COMPILE_TEST
370 help
371 GCC plugins are loadable modules that provide extra features to the
372 compiler. They are useful for runtime instrumentation and static analysis.
373
374 See Documentation/gcc-plugins.txt for details.
375
376config GCC_PLUGIN_CYC_COMPLEXITY
377 bool "Compute the cyclomatic complexity of a function"
378 depends on GCC_PLUGINS
379 help
380 The complexity M of a function's control flow graph is defined as:
381 M = E - N + 2P
382 where
383
384 E = the number of edges
385 N = the number of nodes
386 P = the number of connected components (exit nodes).
387
388config GCC_PLUGIN_SANCOV
389 bool
390 depends on GCC_PLUGINS
391 help
392 This plugin inserts a __sanitizer_cov_trace_pc() call at the start of
393 basic blocks. It supports all gcc versions with plugin support (from
394 gcc-4.5 on). It is based on the commit "Add fuzzing coverage support"
395 by Dmitry Vyukov <dvyukov@google.com>.
396
360config HAVE_CC_STACKPROTECTOR 397config HAVE_CC_STACKPROTECTOR
361 bool 398 bool
362 help 399 help
diff --git a/arch/alpha/boot/Makefile b/arch/alpha/boot/Makefile
index 8399bd0e68e8..0cbe4c59d3ce 100644
--- a/arch/alpha/boot/Makefile
+++ b/arch/alpha/boot/Makefile
@@ -15,7 +15,7 @@ targets := vmlinux.gz vmlinux \
15OBJSTRIP := $(obj)/tools/objstrip 15OBJSTRIP := $(obj)/tools/objstrip
16 16
17HOSTCFLAGS := -Wall -I$(objtree)/usr/include 17HOSTCFLAGS := -Wall -I$(objtree)/usr/include
18BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) 18BOOTCFLAGS += -I$(objtree)/$(obj) -I$(srctree)/$(obj)
19 19
20# SRM bootable image. Copy to offset 512 of a partition. 20# SRM bootable image. Copy to offset 512 of a partition.
21$(obj)/bootimage: $(addprefix $(obj)/tools/,mkbb lxboot bootlx) $(obj)/vmlinux.nh 21$(obj)/bootimage: $(addprefix $(obj)/tools/,mkbb lxboot bootlx) $(obj)/vmlinux.nh
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 14b4cf75ceec..fc3dc0b90be2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -54,6 +54,7 @@ config ARM
54 select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) 54 select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
55 select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL) 55 select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL)
56 select HAVE_FUNCTION_TRACER if (!XIP_KERNEL) 56 select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
57 select HAVE_GCC_PLUGINS
57 select HAVE_GENERIC_DMA_COHERENT 58 select HAVE_GENERIC_DMA_COHERENT
58 select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7)) 59 select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7))
59 select HAVE_IDE if PCI || ISA || PCMCIA 60 select HAVE_IDE if PCI || ISA || PCMCIA
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9f8b99e20557..1b06db571fff 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -78,6 +78,7 @@ config ARM64
78 select HAVE_FTRACE_MCOUNT_RECORD 78 select HAVE_FTRACE_MCOUNT_RECORD
79 select HAVE_FUNCTION_TRACER 79 select HAVE_FUNCTION_TRACER
80 select HAVE_FUNCTION_GRAPH_TRACER 80 select HAVE_FUNCTION_GRAPH_TRACER
81 select HAVE_GCC_PLUGINS
81 select HAVE_GENERIC_DMA_COHERENT 82 select HAVE_GENERIC_DMA_COHERENT
82 select HAVE_HW_BREAKPOINT if PERF_EVENTS 83 select HAVE_HW_BREAKPOINT if PERF_EVENTS
83 select HAVE_IRQ_TIME_ACCOUNTING 84 select HAVE_IRQ_TIME_ACCOUNTING
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 4cd612a6e272..1a2a6e8dc40d 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -43,7 +43,7 @@ ifeq ($(call cc-option-yn, -fstack-protector),y)
43BOOTCFLAGS += -fno-stack-protector 43BOOTCFLAGS += -fno-stack-protector
44endif 44endif
45 45
46BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) 46BOOTCFLAGS += -I$(objtree)/$(obj) -I$(srctree)/$(obj)
47 47
48DTC_FLAGS ?= -p 1024 48DTC_FLAGS ?= -p 1024
49 49
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index eba0bea6e032..1f9e5529e692 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -20,7 +20,7 @@ common-objs-y += powerpc.o emulate.o emulate_loadstore.o
20obj-$(CONFIG_KVM_EXIT_TIMING) += timing.o 20obj-$(CONFIG_KVM_EXIT_TIMING) += timing.o
21obj-$(CONFIG_KVM_BOOK3S_HANDLER) += book3s_exports.o 21obj-$(CONFIG_KVM_BOOK3S_HANDLER) += book3s_exports.o
22 22
23AFLAGS_booke_interrupts.o := -I$(obj) 23AFLAGS_booke_interrupts.o := -I$(objtree)/$(obj)
24 24
25kvm-e500-objs := \ 25kvm-e500-objs := \
26 $(common-objs-y) \ 26 $(common-objs-y) \
diff --git a/arch/s390/boot/compressed/Makefile b/arch/s390/boot/compressed/Makefile
index 13723c39e58e..33ba697c782d 100644
--- a/arch/s390/boot/compressed/Makefile
+++ b/arch/s390/boot/compressed/Makefile
@@ -33,10 +33,10 @@ quiet_cmd_sizes = GEN $@
33$(obj)/sizes.h: vmlinux 33$(obj)/sizes.h: vmlinux
34 $(call if_changed,sizes) 34 $(call if_changed,sizes)
35 35
36AFLAGS_head.o += -I$(obj) 36AFLAGS_head.o += -I$(objtree)/$(obj)
37$(obj)/head.o: $(obj)/sizes.h 37$(obj)/head.o: $(obj)/sizes.h
38 38
39CFLAGS_misc.o += -I$(obj) 39CFLAGS_misc.o += -I$(objtree)/$(obj)
40$(obj)/misc.o: $(obj)/sizes.h 40$(obj)/misc.o: $(obj)/sizes.h
41 41
42OBJCOPYFLAGS_vmlinux.bin := -R .comment -S 42OBJCOPYFLAGS_vmlinux.bin := -R .comment -S
diff --git a/arch/um/Kconfig.common b/arch/um/Kconfig.common
index cc0013475444..58650d098fb4 100644
--- a/arch/um/Kconfig.common
+++ b/arch/um/Kconfig.common
@@ -9,6 +9,7 @@ config UML
9 select GENERIC_CPU_DEVICES 9 select GENERIC_CPU_DEVICES
10 select GENERIC_IO 10 select GENERIC_IO
11 select GENERIC_CLOCKEVENTS 11 select GENERIC_CLOCKEVENTS
12 select HAVE_GCC_PLUGINS
12 select TTY # Needed for line.c 13 select TTY # Needed for line.c
13 14
14config MMU 15config MMU
diff --git a/arch/um/Makefile b/arch/um/Makefile
index e3abe6f3156d..0ca46ededfc7 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -78,8 +78,8 @@ include $(ARCH_DIR)/Makefile-os-$(OS)
78 78
79KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \ 79KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \
80 -I$(srctree)/$(HOST_DIR)/include/uapi \ 80 -I$(srctree)/$(HOST_DIR)/include/uapi \
81 -I$(HOST_DIR)/include/generated \ 81 -I$(objtree)/$(HOST_DIR)/include/generated \
82 -I$(HOST_DIR)/include/generated/uapi 82 -I$(objtree)/$(HOST_DIR)/include/generated/uapi
83 83
84# -Derrno=kernel_errno - This turns all kernel references to errno into 84# -Derrno=kernel_errno - This turns all kernel references to errno into
85# kernel_errno to separate them from the libc errno. This allows -fno-common 85# kernel_errno to separate them from the libc errno. This allows -fno-common
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 2fa55851d2a9..3a9add58d794 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -111,6 +111,7 @@ config X86
111 select HAVE_FUNCTION_GRAPH_FP_TEST 111 select HAVE_FUNCTION_GRAPH_FP_TEST
112 select HAVE_FUNCTION_GRAPH_TRACER 112 select HAVE_FUNCTION_GRAPH_TRACER
113 select HAVE_FUNCTION_TRACER 113 select HAVE_FUNCTION_TRACER
114 select HAVE_GCC_PLUGINS
114 select HAVE_GENERIC_DMA_COHERENT if X86_32 115 select HAVE_GENERIC_DMA_COHERENT if X86_32
115 select HAVE_HW_BREAKPOINT 116 select HAVE_HW_BREAKPOINT
116 select HAVE_IDE 117 select HAVE_IDE
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index be8e688fa0d4..12ea8f8384f4 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -96,7 +96,7 @@ $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE
96 $(call if_changed,zoffset) 96 $(call if_changed,zoffset)
97 97
98 98
99AFLAGS_header.o += -I$(obj) 99AFLAGS_header.o += -I$(objtree)/$(obj)
100$(obj)/header.o: $(obj)/zoffset.h 100$(obj)/header.o: $(obj)/zoffset.h
101 101
102LDFLAGS_setup.elf := -T 102LDFLAGS_setup.elf := -T
diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index 6ba89a1ab0e5..d5409660f5de 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -75,7 +75,7 @@ CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
75 -fno-omit-frame-pointer -foptimize-sibling-calls \ 75 -fno-omit-frame-pointer -foptimize-sibling-calls \
76 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO 76 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
77 77
78$(vobjs): KBUILD_CFLAGS += $(CFL) 78$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
79 79
80# 80#
81# vDSO code runs in userspace and -pg doesn't help with profiling anyway. 81# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
@@ -145,6 +145,7 @@ KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
145KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) 145KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
146KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) 146KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
147KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) 147KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
148KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
148KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic 149KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
149KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) 150KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
150KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) 151KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 12734a96df47..ac58c1616408 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -8,6 +8,8 @@ PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
8LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib 8LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib
9targets += purgatory.ro 9targets += purgatory.ro
10 10
11KCOV_INSTRUMENT := n
12
11# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That 13# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
12# in turn leaves some undefined symbols like __fentry__ in purgatory and not 14# in turn leaves some undefined symbols like __fentry__ in purgatory and not
13# sure how to relocate those. Like kexec-tools, use custom flags. 15# sure how to relocate those. Like kexec-tools, use custom flags.
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index c556c5ae8de5..25012abc3409 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -48,7 +48,7 @@ targets += realmode.lds
48$(obj)/realmode.lds: $(obj)/pasyms.h 48$(obj)/realmode.lds: $(obj)/pasyms.h
49 49
50LDFLAGS_realmode.elf := --emit-relocs -T 50LDFLAGS_realmode.elf := --emit-relocs -T
51CPPFLAGS_realmode.lds += -P -C -I$(obj) 51CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj)
52 52
53targets += realmode.elf 53targets += realmode.elf
54$(obj)/realmode.elf: $(obj)/realmode.lds $(REALMODE_OBJS) FORCE 54$(obj)/realmode.elf: $(obj)/realmode.lds $(REALMODE_OBJS) FORCE
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 54643d1f5af4..24563970ff7b 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -164,7 +164,7 @@
164 164
165#define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name) 165#define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name)
166#define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name) 166#define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name)
167#define OF_TABLE(cfg, name) __OF_TABLE(config_enabled(cfg), name) 167#define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name)
168#define _OF_TABLE_0(name) 168#define _OF_TABLE_0(name)
169#define _OF_TABLE_1(name) \ 169#define _OF_TABLE_1(name) \
170 . = ALIGN(8); \ 170 . = ALIGN(8); \
diff --git a/include/linux/export.h b/include/linux/export.h
index 2f9ccbe6a639..c565f87f005e 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -82,7 +82,7 @@ extern struct module __this_module;
82#include <generated/autoksyms.h> 82#include <generated/autoksyms.h>
83 83
84#define __EXPORT_SYMBOL(sym, sec) \ 84#define __EXPORT_SYMBOL(sym, sec) \
85 __cond_export_sym(sym, sec, config_enabled(__KSYM_##sym)) 85 __cond_export_sym(sym, sec, __is_defined(__KSYM_##sym))
86#define __cond_export_sym(sym, sec, conf) \ 86#define __cond_export_sym(sym, sec, conf) \
87 ___cond_export_sym(sym, sec, conf) 87 ___cond_export_sym(sym, sec, conf)
88#define ___cond_export_sym(sym, sec, enabled) \ 88#define ___cond_export_sym(sym, sec, enabled) \
diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index b33c7797eb57..15ec117ec537 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -3,6 +3,21 @@
3 3
4#include <generated/autoconf.h> 4#include <generated/autoconf.h>
5 5
6#define __ARG_PLACEHOLDER_1 0,
7#define __take_second_arg(__ignored, val, ...) val
8
9/*
10 * The use of "&&" / "||" is limited in certain expressions.
11 * The followings enable to calculate "and" / "or" with macro expansion only.
12 */
13#define __and(x, y) ___and(x, y)
14#define ___and(x, y) ____and(__ARG_PLACEHOLDER_##x, y)
15#define ____and(arg1_or_junk, y) __take_second_arg(arg1_or_junk y, 0)
16
17#define __or(x, y) ___or(x, y)
18#define ___or(x, y) ____or(__ARG_PLACEHOLDER_##x, y)
19#define ____or(arg1_or_junk, y) __take_second_arg(arg1_or_junk 1, y)
20
6/* 21/*
7 * Helper macros to use CONFIG_ options in C/CPP expressions. Note that 22 * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
8 * these only work with boolean and tristate options. 23 * these only work with boolean and tristate options.
@@ -16,11 +31,10 @@
16 * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when 31 * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
17 * the last step cherry picks the 2nd arg, we get a zero. 32 * the last step cherry picks the 2nd arg, we get a zero.
18 */ 33 */
19#define __ARG_PLACEHOLDER_1 0, 34#define config_enabled(cfg) ___is_defined(cfg)
20#define config_enabled(cfg) _config_enabled(cfg) 35#define __is_defined(x) ___is_defined(x)
21#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) 36#define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val)
22#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) 37#define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0)
23#define ___config_enabled(__ignored, val, ...) val
24 38
25/* 39/*
26 * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0 40 * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
@@ -41,14 +55,13 @@
41 * This is similar to IS_ENABLED(), but returns false when invoked from 55 * This is similar to IS_ENABLED(), but returns false when invoked from
42 * built-in code when CONFIG_FOO is set to 'm'. 56 * built-in code when CONFIG_FOO is set to 'm'.
43 */ 57 */
44#define IS_REACHABLE(option) (config_enabled(option) || \ 58#define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
45 (config_enabled(option##_MODULE) && config_enabled(MODULE))) 59 __and(IS_MODULE(option), __is_defined(MODULE)))
46 60
47/* 61/*
48 * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm', 62 * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
49 * 0 otherwise. 63 * 0 otherwise.
50 */ 64 */
51#define IS_ENABLED(option) \ 65#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
52 (IS_BUILTIN(option) || IS_MODULE(option))
53 66
54#endif /* __LINUX_KCONFIG_H */ 67#endif /* __LINUX_KCONFIG_H */
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index f07842e2d69f..eb8917a71489 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -709,6 +709,8 @@ config KCOV
709 bool "Code coverage for fuzzing" 709 bool "Code coverage for fuzzing"
710 depends on ARCH_HAS_KCOV 710 depends on ARCH_HAS_KCOV
711 select DEBUG_FS 711 select DEBUG_FS
712 select GCC_PLUGINS if !COMPILE_TEST
713 select GCC_PLUGIN_SANCOV if !COMPILE_TEST
712 help 714 help
713 KCOV exposes kernel code coverage information in a form suitable 715 KCOV exposes kernel code coverage information in a form suitable
714 for coverage-guided fuzzing (randomized testing). 716 for coverage-guided fuzzing (randomized testing).
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 0f82314621f2..15b196fc2f49 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -202,7 +202,7 @@ hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
202# Prefix -I with $(srctree) if it is not an absolute path. 202# Prefix -I with $(srctree) if it is not an absolute path.
203# skip if -I has no parameter 203# skip if -I has no parameter
204addtree = $(if $(patsubst -I%,%,$(1)), \ 204addtree = $(if $(patsubst -I%,%,$(1)), \
205$(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1)) 205$(if $(filter-out -I/% -I./% -I../%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1)),$(1)))
206 206
207# Find all -I options and call addtree 207# Find all -I options and call addtree
208flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) 208flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o)))
diff --git a/scripts/Makefile b/scripts/Makefile
index 822ab4a6a4aa..1d80897a9644 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -47,4 +47,4 @@ subdir-$(CONFIG_DTC) += dtc
47subdir-$(CONFIG_GDB_SCRIPTS) += gdb 47subdir-$(CONFIG_GDB_SCRIPTS) += gdb
48 48
49# Let clean descend into subdirs 49# Let clean descend into subdirs
50subdir- += basic kconfig package 50subdir- += basic kconfig package gcc-plugins
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 0d1ca5bf42fb..11602e5efb3b 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -60,7 +60,7 @@ endif
60endif 60endif
61 61
62# Do not include host rules unless needed 62# Do not include host rules unless needed
63ifneq ($(hostprogs-y)$(hostprogs-m),) 63ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
64include scripts/Makefile.host 64include scripts/Makefile.host
65endif 65endif
66 66
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 55c96cb8070f..50616ea25131 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -38,7 +38,9 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
38__clean-files := $(extra-y) $(extra-m) $(extra-) \ 38__clean-files := $(extra-y) $(extra-m) $(extra-) \
39 $(always) $(targets) $(clean-files) \ 39 $(always) $(targets) $(clean-files) \
40 $(host-progs) \ 40 $(host-progs) \
41 $(hostprogs-y) $(hostprogs-m) $(hostprogs-) 41 $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
42 $(hostlibs-y) $(hostlibs-m) $(hostlibs-) \
43 $(hostcxxlibs-y) $(hostcxxlibs-m)
42 44
43__clean-files := $(filter-out $(no-clean-files), $(__clean-files)) 45__clean-files := $(filter-out $(no-clean-files), $(__clean-files))
44 46
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
new file mode 100644
index 000000000000..5e22b60589c1
--- /dev/null
+++ b/scripts/Makefile.gcc-plugins
@@ -0,0 +1,43 @@
1ifdef CONFIG_GCC_PLUGINS
2 __PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC))
3 PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)")
4
5 SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
6
7 gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so
8
9 ifdef CONFIG_GCC_PLUGIN_SANCOV
10 ifeq ($(CFLAGS_KCOV),)
11 # It is needed because of the gcc-plugin.sh and gcc version checks.
12 gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so
13
14 ifneq ($(PLUGINCC),)
15 CFLAGS_KCOV := $(SANCOV_PLUGIN)
16 else
17 $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler)
18 endif
19 endif
20 endif
21
22 GCC_PLUGINS_CFLAGS := $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y))
23
24 export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN SANCOV_PLUGIN
25
26 ifeq ($(PLUGINCC),)
27 ifneq ($(GCC_PLUGINS_CFLAGS),)
28 ifeq ($(call cc-ifversion, -ge, 0405, y), y)
29 PLUGINCC := $(shell $(CONFIG_SHELL) -x $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)")
30 $(warning warning: your gcc installation does not support plugins, perhaps the necessary headers are missing?)
31 else
32 $(warning warning: your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least)
33 endif
34 endif
35 else
36 # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication.
37 GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS))
38 endif
39
40 KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
41 GCC_PLUGIN := $(gcc-plugin-y)
42
43endif
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index 133edfae5b8a..45b5b1aaedbd 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -20,7 +20,15 @@
20# Will compile qconf as a C++ program, and menu as a C program. 20# Will compile qconf as a C++ program, and menu as a C program.
21# They are linked as C++ code to the executable qconf 21# They are linked as C++ code to the executable qconf
22 22
23# hostcc-option
24# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
25
26hostcc-option = $(call try-run,\
27 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
28
23__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) 29__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
30host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m))
31host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
24 32
25# C code 33# C code
26# Executables compiled from a single .c file 34# Executables compiled from a single .c file
@@ -42,6 +50,10 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
42# C++ Object (.o) files compiled from .cc files 50# C++ Object (.o) files compiled from .cc files
43host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) 51host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
44 52
53# Object (.o) files used by the shared libaries
54host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
55host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
56
45# output directory for programs/.o files 57# output directory for programs/.o files
46# hostprogs-y := tools/build may have been specified. 58# hostprogs-y := tools/build may have been specified.
47# Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation 59# Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
@@ -56,6 +68,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
56host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) 68host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
57host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) 69host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
58host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs)) 70host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
71host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
72host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
73host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
74host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
59host-objdirs := $(addprefix $(obj)/,$(host-objdirs)) 75host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
60 76
61obj-dirs += $(host-objdirs) 77obj-dirs += $(host-objdirs)
@@ -124,5 +140,42 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
124$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE 140$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
125 $(call if_changed_dep,host-cxxobjs) 141 $(call if_changed_dep,host-cxxobjs)
126 142
143# Compile .c file, create position independent .o file
144# host-cshobjs -> .o
145quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
146 cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
147$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
148 $(call if_changed_dep,host-cshobjs)
149
150# Compile .c file, create position independent .o file
151# Note that plugin capable gcc versions can be either C or C++ based
152# therefore plugin source files have to be compilable in both C and C++ mode.
153# This is why a C++ compiler is invoked on a .c file.
154# host-cxxshobjs -> .o
155quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
156 cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
157$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
158 $(call if_changed_dep,host-cxxshobjs)
159
160# Link a shared library, based on position independent .o files
161# *.o -> .so shared library (host-cshlib)
162quiet_cmd_host-cshlib = HOSTLLD -shared $@
163 cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
164 $(addprefix $(obj)/,$($(@F:.so=-objs))) \
165 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
166$(host-cshlib): FORCE
167 $(call if_changed,host-cshlib)
168$(call multi_depend, $(host-cshlib), .so, -objs)
169
170# Link a shared library, based on position independent .o files
171# *.o -> .so shared library (host-cxxshlib)
172quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
173 cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
174 $(addprefix $(obj)/,$($(@F:.so=-objs))) \
175 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
176$(host-cxxshlib): FORCE
177 $(call if_changed,host-cxxshlib)
178$(call multi_depend, $(host-cxxshlib), .so, -objs)
179
127targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ 180targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
128 $(host-cxxmulti) $(host-cxxobjs) 181 $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index e7df0f5db7ec..e89c214745eb 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -155,9 +155,10 @@ else
155# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files 155# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
156# and locates generated .h files 156# and locates generated .h files
157# FIXME: Replace both with specific CFLAGS* statements in the makefiles 157# FIXME: Replace both with specific CFLAGS* statements in the makefiles
158__c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) 158__c_flags = $(if $(obj),-I$(srctree)/$(src) -I$(obj)) \
159__a_flags = $(call flags,_a_flags) 159 $(call flags,_c_flags)
160__cpp_flags = $(call flags,_cpp_flags) 160__a_flags = $(call flags,_a_flags)
161__cpp_flags = $(call flags,_cpp_flags)
161endif 162endif
162 163
163c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 164c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
diff --git a/scripts/basic/bin2c.c b/scripts/basic/bin2c.c
index af187e695345..c3d7eef3ad06 100644
--- a/scripts/basic/bin2c.c
+++ b/scripts/basic/bin2c.c
@@ -29,7 +29,8 @@ int main(int argc, char *argv[])
29 } while (ch != EOF); 29 } while (ch != EOF);
30 30
31 if (argc > 1) 31 if (argc > 1)
32 printf("\t;\n\nconst int %s_size = %d;\n", argv[1], total); 32 printf("\t;\n\n#include <linux/types.h>\n\nconst size_t %s_size = %d;\n",
33 argv[1], total);
33 34
34 return 0; 35 return 0;
35} 36}
diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
new file mode 100755
index 000000000000..fb9207565471
--- /dev/null
+++ b/scripts/gcc-plugin.sh
@@ -0,0 +1,51 @@
1#!/bin/sh
2srctree=$(dirname "$0")
3gccplugins_dir=$($3 -print-file-name=plugin)
4plugincc=$($1 -E -x c++ - -o /dev/null -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <<EOF
5#include "gcc-common.h"
6#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
7#warning $2 CXX
8#else
9#warning $1 CC
10#endif
11EOF
12)
13
14if [ $? -ne 0 ]
15then
16 exit 1
17fi
18
19case "$plugincc" in
20 *"$1 CC"*)
21 echo "$1"
22 exit 0
23 ;;
24
25 *"$2 CXX"*)
26 # the c++ compiler needs another test, see below
27 ;;
28
29 *)
30 exit 1
31 ;;
32esac
33
34# we need a c++ compiler that supports the designated initializer GNU extension
35plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <<EOF
36#include "gcc-common.h"
37class test {
38public:
39 int test;
40} test = {
41 .test = 1
42};
43EOF
44)
45
46if [ $? -eq 0 ]
47then
48 echo "$2"
49 exit 0
50fi
51exit 1
diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile
new file mode 100644
index 000000000000..88c8ec47232b
--- /dev/null
+++ b/scripts/gcc-plugins/Makefile
@@ -0,0 +1,27 @@
1GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
2
3ifeq ($(PLUGINCC),$(HOSTCC))
4 HOSTLIBS := hostlibs
5 HOST_EXTRACFLAGS += -I$(GCC_PLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
6 export HOST_EXTRACFLAGS
7else
8 HOSTLIBS := hostcxxlibs
9 HOST_EXTRACXXFLAGS += -I$(GCC_PLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti
10 HOST_EXTRACXXFLAGS += -fno-exceptions -fasynchronous-unwind-tables -ggdb
11 HOST_EXTRACXXFLAGS += -Wno-narrowing -Wno-unused-variable
12 export HOST_EXTRACXXFLAGS
13endif
14
15export GCCPLUGINS_DIR HOSTLIBS
16
17ifneq ($(CFLAGS_KCOV), $(SANCOV_PLUGIN))
18 GCC_PLUGIN := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGIN))
19endif
20
21$(HOSTLIBS)-y := $(GCC_PLUGIN)
22always := $($(HOSTLIBS)-y)
23
24cyc_complexity_plugin-objs := cyc_complexity_plugin.o
25sancov_plugin-objs := sancov_plugin.o
26
27clean-files += *.so
diff --git a/scripts/gcc-plugins/cyc_complexity_plugin.c b/scripts/gcc-plugins/cyc_complexity_plugin.c
new file mode 100644
index 000000000000..34df974c6ba3
--- /dev/null
+++ b/scripts/gcc-plugins/cyc_complexity_plugin.c
@@ -0,0 +1,73 @@
1/*
2 * Copyright 2011-2016 by Emese Revfy <re.emese@gmail.com>
3 * Licensed under the GPL v2, or (at your option) v3
4 *
5 * Homepage:
6 * https://github.com/ephox-gcc-plugins/cyclomatic_complexity
7 *
8 * http://en.wikipedia.org/wiki/Cyclomatic_complexity
9 * The complexity M is then defined as:
10 * M = E - N + 2P
11 * where
12 *
13 * E = the number of edges of the graph
14 * N = the number of nodes of the graph
15 * P = the number of connected components (exit nodes).
16 *
17 * Usage (4.5 - 5):
18 * $ make clean; make run
19 */
20
21#include "gcc-common.h"
22
23int plugin_is_GPL_compatible;
24
25static struct plugin_info cyc_complexity_plugin_info = {
26 .version = "20160225",
27 .help = "Cyclomatic Complexity\n",
28};
29
30static unsigned int cyc_complexity_execute(void)
31{
32 int complexity;
33 expanded_location xloc;
34
35 /* M = E - N + 2P */
36 complexity = n_edges_for_fn(cfun) - n_basic_blocks_for_fn(cfun) + 2;
37
38 xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
39 fprintf(stderr, "Cyclomatic Complexity %d %s:%s\n", complexity,
40 xloc.file, DECL_NAME_POINTER(current_function_decl));
41
42 return 0;
43}
44
45#define PASS_NAME cyc_complexity
46
47#define NO_GATE
48#define TODO_FLAGS_FINISH TODO_dump_func
49
50#include "gcc-generate-gimple-pass.h"
51
52int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
53{
54 const char * const plugin_name = plugin_info->base_name;
55 struct register_pass_info cyc_complexity_pass_info;
56
57 cyc_complexity_pass_info.pass = make_cyc_complexity_pass();
58 cyc_complexity_pass_info.reference_pass_name = "ssa";
59 cyc_complexity_pass_info.ref_pass_instance_number = 1;
60 cyc_complexity_pass_info.pos_op = PASS_POS_INSERT_AFTER;
61
62 if (!plugin_default_version_check(version, &gcc_version)) {
63 error(G_("incompatible gcc/plugin versions"));
64 return 1;
65 }
66
67 register_callback(plugin_name, PLUGIN_INFO, NULL,
68 &cyc_complexity_plugin_info);
69 register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
70 &cyc_complexity_pass_info);
71
72 return 0;
73}
diff --git a/scripts/gcc-plugins/gcc-common.h b/scripts/gcc-plugins/gcc-common.h
new file mode 100644
index 000000000000..172850bcd0d9
--- /dev/null
+++ b/scripts/gcc-plugins/gcc-common.h
@@ -0,0 +1,830 @@
1#ifndef GCC_COMMON_H_INCLUDED
2#define GCC_COMMON_H_INCLUDED
3
4#include "bversion.h"
5#if BUILDING_GCC_VERSION >= 6000
6#include "gcc-plugin.h"
7#else
8#include "plugin.h"
9#endif
10#include "plugin-version.h"
11#include "config.h"
12#include "system.h"
13#include "coretypes.h"
14#include "tm.h"
15#include "line-map.h"
16#include "input.h"
17#include "tree.h"
18
19#include "tree-inline.h"
20#include "version.h"
21#include "rtl.h"
22#include "tm_p.h"
23#include "flags.h"
24#include "hard-reg-set.h"
25#include "output.h"
26#include "except.h"
27#include "function.h"
28#include "toplev.h"
29#include "basic-block.h"
30#include "intl.h"
31#include "ggc.h"
32#include "timevar.h"
33
34#include "params.h"
35
36#if BUILDING_GCC_VERSION <= 4009
37#include "pointer-set.h"
38#else
39#include "hash-map.h"
40#endif
41
42#include "emit-rtl.h"
43#include "debug.h"
44#include "target.h"
45#include "langhooks.h"
46#include "cfgloop.h"
47#include "cgraph.h"
48#include "opts.h"
49
50#if BUILDING_GCC_VERSION == 4005
51#include <sys/mman.h>
52#endif
53
54#if BUILDING_GCC_VERSION >= 4007
55#include "tree-pretty-print.h"
56#include "gimple-pretty-print.h"
57#endif
58
59#if BUILDING_GCC_VERSION >= 4006
60#include "c-family/c-common.h"
61#else
62#include "c-common.h"
63#endif
64
65#if BUILDING_GCC_VERSION <= 4008
66#include "tree-flow.h"
67#else
68#include "tree-cfgcleanup.h"
69#include "tree-ssa-operands.h"
70#include "tree-into-ssa.h"
71#endif
72
73#if BUILDING_GCC_VERSION >= 4008
74#include "is-a.h"
75#endif
76
77#include "diagnostic.h"
78#include "tree-dump.h"
79#include "tree-pass.h"
80#include "predict.h"
81#include "ipa-utils.h"
82
83#if BUILDING_GCC_VERSION >= 4009
84#include "attribs.h"
85#include "varasm.h"
86#include "stor-layout.h"
87#include "internal-fn.h"
88#include "gimple-expr.h"
89#include "gimple-fold.h"
90#include "context.h"
91#include "tree-ssa-alias.h"
92#include "tree-ssa.h"
93#include "stringpool.h"
94#include "tree-ssanames.h"
95#include "print-tree.h"
96#include "tree-eh.h"
97#include "stmt.h"
98#include "gimplify.h"
99#endif
100
101#include "gimple.h"
102
103#if BUILDING_GCC_VERSION >= 4009
104#include "tree-ssa-operands.h"
105#include "tree-phinodes.h"
106#include "tree-cfg.h"
107#include "gimple-iterator.h"
108#include "gimple-ssa.h"
109#include "ssa-iterators.h"
110#endif
111
112#if BUILDING_GCC_VERSION >= 5000
113#include "builtins.h"
114#endif
115
116/* #include "expr.h" where are you... */
117extern rtx emit_move_insn(rtx x, rtx y);
118
119/* missing from basic_block.h... */
120extern void debug_dominance_info(enum cdi_direction dir);
121extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
122
123#if BUILDING_GCC_VERSION == 4006
124extern void debug_gimple_stmt(gimple);
125extern void debug_gimple_seq(gimple_seq);
126extern void print_gimple_seq(FILE *, gimple_seq, int, int);
127extern void print_gimple_stmt(FILE *, gimple, int, int);
128extern void print_gimple_expr(FILE *, gimple, int, int);
129extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
130#endif
131
132#define __unused __attribute__((__unused__))
133
134#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
135#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
136#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
137#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
138
139/* should come from c-tree.h if only it were installed for gcc 4.5... */
140#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
141
142#if BUILDING_GCC_VERSION == 4005
143#define FOR_EACH_LOCAL_DECL(FUN, I, D) \
144 for (tree vars = (FUN)->local_decls, (I) = 0; \
145 vars && ((D) = TREE_VALUE(vars)); \
146 vars = TREE_CHAIN(vars), (I)++)
147#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
148#define FOR_EACH_VEC_ELT(T, V, I, P) \
149 for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
150#define TODO_rebuild_cgraph_edges 0
151#define SCOPE_FILE_SCOPE_P(EXP) (!(EXP))
152
153#ifndef O_BINARY
154#define O_BINARY 0
155#endif
156
157typedef struct varpool_node *varpool_node_ptr;
158
159static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
160{
161 tree fndecl;
162
163 if (!is_gimple_call(stmt))
164 return false;
165 fndecl = gimple_call_fndecl(stmt);
166 if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
167 return false;
168 return DECL_FUNCTION_CODE(fndecl) == code;
169}
170
171static inline bool is_simple_builtin(tree decl)
172{
173 if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
174 return false;
175
176 switch (DECL_FUNCTION_CODE(decl)) {
177 /* Builtins that expand to constants. */
178 case BUILT_IN_CONSTANT_P:
179 case BUILT_IN_EXPECT:
180 case BUILT_IN_OBJECT_SIZE:
181 case BUILT_IN_UNREACHABLE:
182 /* Simple register moves or loads from stack. */
183 case BUILT_IN_RETURN_ADDRESS:
184 case BUILT_IN_EXTRACT_RETURN_ADDR:
185 case BUILT_IN_FROB_RETURN_ADDR:
186 case BUILT_IN_RETURN:
187 case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
188 case BUILT_IN_FRAME_ADDRESS:
189 case BUILT_IN_VA_END:
190 case BUILT_IN_STACK_SAVE:
191 case BUILT_IN_STACK_RESTORE:
192 /* Exception state returns or moves registers around. */
193 case BUILT_IN_EH_FILTER:
194 case BUILT_IN_EH_POINTER:
195 case BUILT_IN_EH_COPY_VALUES:
196 return true;
197
198 default:
199 return false;
200 }
201}
202
203static inline void add_local_decl(struct function *fun, tree d)
204{
205 gcc_assert(TREE_CODE(d) == VAR_DECL);
206 fun->local_decls = tree_cons(NULL_TREE, d, fun->local_decls);
207}
208#endif
209
210#if BUILDING_GCC_VERSION <= 4006
211#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
212#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
213#define EDGE_PRESERVE 0ULL
214#define HOST_WIDE_INT_PRINT_HEX_PURE "%" HOST_WIDE_INT_PRINT "x"
215#define flag_fat_lto_objects true
216
217#define get_random_seed(noinit) ({ \
218 unsigned HOST_WIDE_INT seed; \
219 sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
220 seed * seed; })
221
222#define int_const_binop(code, arg1, arg2) \
223 int_const_binop((code), (arg1), (arg2), 0)
224
225static inline bool gimple_clobber_p(gimple s __unused)
226{
227 return false;
228}
229
230static inline bool gimple_asm_clobbers_memory_p(const_gimple stmt)
231{
232 unsigned i;
233
234 for (i = 0; i < gimple_asm_nclobbers(stmt); i++) {
235 tree op = gimple_asm_clobber_op(stmt, i);
236
237 if (!strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "memory"))
238 return true;
239 }
240
241 return false;
242}
243
244static inline tree builtin_decl_implicit(enum built_in_function fncode)
245{
246 return implicit_built_in_decls[fncode];
247}
248
249static inline int ipa_reverse_postorder(struct cgraph_node **order)
250{
251 return cgraph_postorder(order);
252}
253
254static inline struct cgraph_node *cgraph_create_node(tree decl)
255{
256 return cgraph_node(decl);
257}
258
259static inline struct cgraph_node *cgraph_get_create_node(tree decl)
260{
261 struct cgraph_node *node = cgraph_get_node(decl);
262
263 return node ? node : cgraph_node(decl);
264}
265
266static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
267{
268 return node->analyzed && !node->thunk.thunk_p && !node->alias;
269}
270
271static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
272{
273 struct cgraph_node *node;
274
275 for (node = cgraph_nodes; node; node = node->next)
276 if (cgraph_function_with_gimple_body_p(node))
277 return node;
278 return NULL;
279}
280
281static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
282{
283 for (node = node->next; node; node = node->next)
284 if (cgraph_function_with_gimple_body_p(node))
285 return node;
286 return NULL;
287}
288
289#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
290 for ((node) = cgraph_first_function_with_gimple_body(); (node); \
291 (node) = cgraph_next_function_with_gimple_body(node))
292
293static inline void varpool_add_new_variable(tree decl)
294{
295 varpool_finalize_decl(decl);
296}
297#endif
298
299#if BUILDING_GCC_VERSION <= 4007
300#define FOR_EACH_FUNCTION(node) \
301 for (node = cgraph_nodes; node; node = node->next)
302#define FOR_EACH_VARIABLE(node) \
303 for (node = varpool_nodes; node; node = node->next)
304#define PROP_loops 0
305#define NODE_SYMBOL(node) (node)
306#define NODE_DECL(node) (node)->decl
307#define INSN_LOCATION(INSN) RTL_LOCATION(INSN)
308#define vNULL NULL
309
310static inline int bb_loop_depth(const_basic_block bb)
311{
312 return bb->loop_father ? loop_depth(bb->loop_father) : 0;
313}
314
315static inline bool gimple_store_p(gimple gs)
316{
317 tree lhs = gimple_get_lhs(gs);
318
319 return lhs && !is_gimple_reg(lhs);
320}
321
322static inline void gimple_init_singleton(gimple g __unused)
323{
324}
325#endif
326
327#if BUILDING_GCC_VERSION == 4007 || BUILDING_GCC_VERSION == 4008
328static inline struct cgraph_node *cgraph_alias_target(struct cgraph_node *n)
329{
330 return cgraph_alias_aliased_node(n);
331}
332#endif
333
334#if BUILDING_GCC_VERSION >= 4007 && BUILDING_GCC_VERSION <= 4009
335#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
336 cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
337#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
338 cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
339#endif
340
341#if BUILDING_GCC_VERSION <= 4008
342#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
343#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
344#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
345#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
346#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
347#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
348#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
349#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
350#define BASIC_BLOCK_FOR_FN(FN, N) BASIC_BLOCK_FOR_FUNCTION((FN), (N))
351#define NODE_IMPLICIT_ALIAS(node) (node)->same_body_alias
352#define VAR_P(NODE) (TREE_CODE(NODE) == VAR_DECL)
353
354static inline bool tree_fits_shwi_p(const_tree t)
355{
356 if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST)
357 return false;
358
359 if (TREE_INT_CST_HIGH(t) == 0 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) >= 0)
360 return true;
361
362 if (TREE_INT_CST_HIGH(t) == -1 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) < 0 && !TYPE_UNSIGNED(TREE_TYPE(t)))
363 return true;
364
365 return false;
366}
367
368static inline bool tree_fits_uhwi_p(const_tree t)
369{
370 if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST)
371 return false;
372
373 return TREE_INT_CST_HIGH(t) == 0;
374}
375
376static inline HOST_WIDE_INT tree_to_shwi(const_tree t)
377{
378 gcc_assert(tree_fits_shwi_p(t));
379 return TREE_INT_CST_LOW(t);
380}
381
382static inline unsigned HOST_WIDE_INT tree_to_uhwi(const_tree t)
383{
384 gcc_assert(tree_fits_uhwi_p(t));
385 return TREE_INT_CST_LOW(t);
386}
387
388static inline const char *get_tree_code_name(enum tree_code code)
389{
390 gcc_assert(code < MAX_TREE_CODES);
391 return tree_code_name[code];
392}
393
394#define ipa_remove_stmt_references(cnode, stmt)
395
396typedef union gimple_statement_d gasm;
397typedef union gimple_statement_d gassign;
398typedef union gimple_statement_d gcall;
399typedef union gimple_statement_d gcond;
400typedef union gimple_statement_d gdebug;
401typedef union gimple_statement_d gphi;
402typedef union gimple_statement_d greturn;
403
404static inline gasm *as_a_gasm(gimple stmt)
405{
406 return stmt;
407}
408
409static inline const gasm *as_a_const_gasm(const_gimple stmt)
410{
411 return stmt;
412}
413
414static inline gassign *as_a_gassign(gimple stmt)
415{
416 return stmt;
417}
418
419static inline const gassign *as_a_const_gassign(const_gimple stmt)
420{
421 return stmt;
422}
423
424static inline gcall *as_a_gcall(gimple stmt)
425{
426 return stmt;
427}
428
429static inline const gcall *as_a_const_gcall(const_gimple stmt)
430{
431 return stmt;
432}
433
434static inline gcond *as_a_gcond(gimple stmt)
435{
436 return stmt;
437}
438
439static inline const gcond *as_a_const_gcond(const_gimple stmt)
440{
441 return stmt;
442}
443
444static inline gdebug *as_a_gdebug(gimple stmt)
445{
446 return stmt;
447}
448
449static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
450{
451 return stmt;
452}
453
454static inline gphi *as_a_gphi(gimple stmt)
455{
456 return stmt;
457}
458
459static inline const gphi *as_a_const_gphi(const_gimple stmt)
460{
461 return stmt;
462}
463
464static inline greturn *as_a_greturn(gimple stmt)
465{
466 return stmt;
467}
468
469static inline const greturn *as_a_const_greturn(const_gimple stmt)
470{
471 return stmt;
472}
473#endif
474
475#if BUILDING_GCC_VERSION == 4008
476#define NODE_SYMBOL(node) (&(node)->symbol)
477#define NODE_DECL(node) (node)->symbol.decl
478#endif
479
480#if BUILDING_GCC_VERSION >= 4008
481#define add_referenced_var(var)
482#define mark_sym_for_renaming(var)
483#define varpool_mark_needed_node(node)
484#define create_var_ann(var)
485#define TODO_dump_func 0
486#define TODO_dump_cgraph 0
487#endif
488
489#if BUILDING_GCC_VERSION <= 4009
490#define TODO_verify_il 0
491#define AVAIL_INTERPOSABLE AVAIL_OVERWRITABLE
492
493#define section_name_prefix LTO_SECTION_NAME_PREFIX
494#define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__)
495
496typedef struct rtx_def rtx_insn;
497
498static inline void set_decl_section_name(tree node, const char *value)
499{
500 if (value)
501 DECL_SECTION_NAME(node) = build_string(strlen(value) + 1, value);
502 else
503 DECL_SECTION_NAME(node) = NULL;
504}
505#endif
506
507#if BUILDING_GCC_VERSION == 4009
508typedef struct gimple_statement_asm gasm;
509typedef struct gimple_statement_base gassign;
510typedef struct gimple_statement_call gcall;
511typedef struct gimple_statement_base gcond;
512typedef struct gimple_statement_base gdebug;
513typedef struct gimple_statement_phi gphi;
514typedef struct gimple_statement_base greturn;
515
516static inline gasm *as_a_gasm(gimple stmt)
517{
518 return as_a<gasm>(stmt);
519}
520
521static inline const gasm *as_a_const_gasm(const_gimple stmt)
522{
523 return as_a<const gasm>(stmt);
524}
525
526static inline gassign *as_a_gassign(gimple stmt)
527{
528 return stmt;
529}
530
531static inline const gassign *as_a_const_gassign(const_gimple stmt)
532{
533 return stmt;
534}
535
536static inline gcall *as_a_gcall(gimple stmt)
537{
538 return as_a<gcall>(stmt);
539}
540
541static inline const gcall *as_a_const_gcall(const_gimple stmt)
542{
543 return as_a<const gcall>(stmt);
544}
545
546static inline gcond *as_a_gcond(gimple stmt)
547{
548 return stmt;
549}
550
551static inline const gcond *as_a_const_gcond(const_gimple stmt)
552{
553 return stmt;
554}
555
556static inline gdebug *as_a_gdebug(gimple stmt)
557{
558 return stmt;
559}
560
561static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
562{
563 return stmt;
564}
565
566static inline gphi *as_a_gphi(gimple stmt)
567{
568 return as_a<gphi>(stmt);
569}
570
571static inline const gphi *as_a_const_gphi(const_gimple stmt)
572{
573 return as_a<const gphi>(stmt);
574}
575
576static inline greturn *as_a_greturn(gimple stmt)
577{
578 return stmt;
579}
580
581static inline const greturn *as_a_const_greturn(const_gimple stmt)
582{
583 return stmt;
584}
585#endif
586
587#if BUILDING_GCC_VERSION >= 4009
588#define TODO_ggc_collect 0
589#define NODE_SYMBOL(node) (node)
590#define NODE_DECL(node) (node)->decl
591#define cgraph_node_name(node) (node)->name()
592#define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
593#endif
594
595#if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000
596/* gimple related */
597template <>
598template <>
599inline bool is_a_helper<const gassign *>::test(const_gimple gs)
600{
601 return gs->code == GIMPLE_ASSIGN;
602}
603#endif
604
605#if BUILDING_GCC_VERSION >= 5000
606#define TODO_verify_ssa TODO_verify_il
607#define TODO_verify_flow TODO_verify_il
608#define TODO_verify_stmts TODO_verify_il
609#define TODO_verify_rtl_sharing TODO_verify_il
610
611#define INSN_DELETED_P(insn) (insn)->deleted()
612
613/* symtab/cgraph related */
614#define debug_cgraph_node(node) (node)->debug()
615#define cgraph_get_node(decl) cgraph_node::get(decl)
616#define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
617#define cgraph_create_node(decl) cgraph_node::create(decl)
618#define cgraph_n_nodes symtab->cgraph_count
619#define cgraph_max_uid symtab->cgraph_max_uid
620#define varpool_get_node(decl) varpool_node::get(decl)
621
622#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
623 (caller)->create_edge((callee), (call_stmt), (count), (freq))
624#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
625 (caller)->create_edge_including_clones((callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
626
627typedef struct cgraph_node *cgraph_node_ptr;
628typedef struct cgraph_edge *cgraph_edge_p;
629typedef struct varpool_node *varpool_node_ptr;
630
631static inline void change_decl_assembler_name(tree decl, tree name)
632{
633 symtab->change_decl_assembler_name(decl, name);
634}
635
636static inline void varpool_finalize_decl(tree decl)
637{
638 varpool_node::finalize_decl(decl);
639}
640
641static inline void varpool_add_new_variable(tree decl)
642{
643 varpool_node::add(decl);
644}
645
646static inline unsigned int rebuild_cgraph_edges(void)
647{
648 return cgraph_edge::rebuild_edges();
649}
650
651static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
652{
653 return node->function_symbol(availability);
654}
655
656static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
657{
658 return node->ultimate_alias_target(availability);
659}
660
661static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
662{
663 return node->only_called_directly_p();
664}
665
666static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
667{
668 return node->get_availability();
669}
670
671static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
672{
673 return node->get_alias_target();
674}
675
676static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
677{
678 return symtab->add_cgraph_insertion_hook(hook, data);
679}
680
681static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
682{
683 symtab->remove_cgraph_insertion_hook(entry);
684}
685
686static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
687{
688 return symtab->add_cgraph_removal_hook(hook, data);
689}
690
691static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
692{
693 symtab->remove_cgraph_removal_hook(entry);
694}
695
696static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
697{
698 return symtab->add_cgraph_duplication_hook(hook, data);
699}
700
701static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
702{
703 symtab->remove_cgraph_duplication_hook(entry);
704}
705
706static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
707{
708 symtab->call_cgraph_duplication_hooks(node, node2);
709}
710
711static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
712{
713 symtab->call_edge_duplication_hooks(cs1, cs2);
714}
715
716#if BUILDING_GCC_VERSION >= 6000
717typedef gimple *gimple_ptr;
718typedef const gimple *const_gimple_ptr;
719#define gimple gimple_ptr
720#define const_gimple const_gimple_ptr
721#undef CONST_CAST_GIMPLE
722#define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
723#endif
724
725/* gimple related */
726static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
727{
728 return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
729}
730
731template <>
732template <>
733inline bool is_a_helper<const greturn *>::test(const_gimple gs)
734{
735 return gs->code == GIMPLE_RETURN;
736}
737
738static inline gasm *as_a_gasm(gimple stmt)
739{
740 return as_a<gasm *>(stmt);
741}
742
743static inline const gasm *as_a_const_gasm(const_gimple stmt)
744{
745 return as_a<const gasm *>(stmt);
746}
747
748static inline gassign *as_a_gassign(gimple stmt)
749{
750 return as_a<gassign *>(stmt);
751}
752
753static inline const gassign *as_a_const_gassign(const_gimple stmt)
754{
755 return as_a<const gassign *>(stmt);
756}
757
758static inline gcall *as_a_gcall(gimple stmt)
759{
760 return as_a<gcall *>(stmt);
761}
762
763static inline const gcall *as_a_const_gcall(const_gimple stmt)
764{
765 return as_a<const gcall *>(stmt);
766}
767
768static inline gphi *as_a_gphi(gimple stmt)
769{
770 return as_a<gphi *>(stmt);
771}
772
773static inline const gphi *as_a_const_gphi(const_gimple stmt)
774{
775 return as_a<const gphi *>(stmt);
776}
777
778static inline greturn *as_a_greturn(gimple stmt)
779{
780 return as_a<greturn *>(stmt);
781}
782
783static inline const greturn *as_a_const_greturn(const_gimple stmt)
784{
785 return as_a<const greturn *>(stmt);
786}
787
788/* IPA/LTO related */
789#define ipa_ref_list_referring_iterate(L, I, P) \
790 (L)->referring.iterate((I), &(P))
791#define ipa_ref_list_reference_iterate(L, I, P) \
792 (L)->reference.iterate((I), &(P))
793
794static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
795{
796 return dyn_cast<cgraph_node_ptr>(ref->referring);
797}
798
799static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
800{
801 referring_node->remove_stmt_references(stmt);
802}
803#endif
804
805#if BUILDING_GCC_VERSION < 6000
806#define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
807 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning)
808#define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1))
809#endif
810
811#if BUILDING_GCC_VERSION >= 6000
812#define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
813#endif
814
815#ifdef __cplusplus
816static inline void debug_tree(const_tree t)
817{
818 debug_tree(CONST_CAST_TREE(t));
819}
820
821static inline void debug_gimple_stmt(const_gimple s)
822{
823 debug_gimple_stmt(CONST_CAST_GIMPLE(s));
824}
825#else
826#define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
827#define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
828#endif
829
830#endif
diff --git a/scripts/gcc-plugins/gcc-generate-gimple-pass.h b/scripts/gcc-plugins/gcc-generate-gimple-pass.h
new file mode 100644
index 000000000000..526c3c79b68e
--- /dev/null
+++ b/scripts/gcc-plugins/gcc-generate-gimple-pass.h
@@ -0,0 +1,175 @@
1/*
2 * Generator for GIMPLE pass related boilerplate code/data
3 *
4 * Supports gcc 4.5-6
5 *
6 * Usage:
7 *
8 * 1. before inclusion define PASS_NAME
9 * 2. before inclusion define NO_* for unimplemented callbacks
10 * NO_GATE
11 * NO_EXECUTE
12 * 3. before inclusion define PROPERTIES_* and TODO_FLAGS_* to override
13 * the default 0 values
14 * 4. for convenience, all the above will be undefined after inclusion!
15 * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
16 */
17
18#ifndef PASS_NAME
19#error at least PASS_NAME must be defined
20#else
21#define __GCC_PLUGIN_STRINGIFY(n) #n
22#define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n)
23#define _GCC_PLUGIN_CONCAT2(x, y) x ## y
24#define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z
25
26#define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data)
27#define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME)
28
29#define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass)
30#define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME)
31
32#define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME)
33
34#define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass)
35#define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME)
36
37#ifdef NO_GATE
38#define _GATE NULL
39#define _HAS_GATE false
40#else
41#define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate)
42#define _GATE __GATE(PASS_NAME)
43#define _HAS_GATE true
44#endif
45
46#ifdef NO_EXECUTE
47#define _EXECUTE NULL
48#define _HAS_EXECUTE false
49#else
50#define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute)
51#define _EXECUTE __EXECUTE(PASS_NAME)
52#define _HAS_EXECUTE true
53#endif
54
55#ifndef PROPERTIES_REQUIRED
56#define PROPERTIES_REQUIRED 0
57#endif
58
59#ifndef PROPERTIES_PROVIDED
60#define PROPERTIES_PROVIDED 0
61#endif
62
63#ifndef PROPERTIES_DESTROYED
64#define PROPERTIES_DESTROYED 0
65#endif
66
67#ifndef TODO_FLAGS_START
68#define TODO_FLAGS_START 0
69#endif
70
71#ifndef TODO_FLAGS_FINISH
72#define TODO_FLAGS_FINISH 0
73#endif
74
75#if BUILDING_GCC_VERSION >= 4009
76namespace {
77static const pass_data _PASS_NAME_PASS_DATA = {
78#else
79static struct gimple_opt_pass _PASS_NAME_PASS = {
80 .pass = {
81#endif
82 .type = GIMPLE_PASS,
83 .name = _PASS_NAME_NAME,
84#if BUILDING_GCC_VERSION >= 4008
85 .optinfo_flags = OPTGROUP_NONE,
86#endif
87#if BUILDING_GCC_VERSION >= 5000
88#elif BUILDING_GCC_VERSION == 4009
89 .has_gate = _HAS_GATE,
90 .has_execute = _HAS_EXECUTE,
91#else
92 .gate = _GATE,
93 .execute = _EXECUTE,
94 .sub = NULL,
95 .next = NULL,
96 .static_pass_number = 0,
97#endif
98 .tv_id = TV_NONE,
99 .properties_required = PROPERTIES_REQUIRED,
100 .properties_provided = PROPERTIES_PROVIDED,
101 .properties_destroyed = PROPERTIES_DESTROYED,
102 .todo_flags_start = TODO_FLAGS_START,
103 .todo_flags_finish = TODO_FLAGS_FINISH,
104#if BUILDING_GCC_VERSION < 4009
105 }
106#endif
107};
108
109#if BUILDING_GCC_VERSION >= 4009
110class _PASS_NAME_PASS : public gimple_opt_pass {
111public:
112 _PASS_NAME_PASS() : gimple_opt_pass(_PASS_NAME_PASS_DATA, g) {}
113
114#ifndef NO_GATE
115#if BUILDING_GCC_VERSION >= 5000
116 virtual bool gate(function *) { return _GATE(); }
117#else
118 virtual bool gate(void) { return _GATE(); }
119#endif
120#endif
121
122 virtual opt_pass * clone () { return new _PASS_NAME_PASS(); }
123
124#ifndef NO_EXECUTE
125#if BUILDING_GCC_VERSION >= 5000
126 virtual unsigned int execute(function *) { return _EXECUTE(); }
127#else
128 virtual unsigned int execute(void) { return _EXECUTE(); }
129#endif
130#endif
131};
132}
133
134opt_pass *_MAKE_PASS_NAME_PASS(void)
135{
136 return new _PASS_NAME_PASS();
137}
138#else
139struct opt_pass *_MAKE_PASS_NAME_PASS(void)
140{
141 return &_PASS_NAME_PASS.pass;
142}
143#endif
144
145/* clean up user provided defines */
146#undef PASS_NAME
147#undef NO_GATE
148#undef NO_EXECUTE
149
150#undef PROPERTIES_DESTROYED
151#undef PROPERTIES_PROVIDED
152#undef PROPERTIES_REQUIRED
153#undef TODO_FLAGS_FINISH
154#undef TODO_FLAGS_START
155
156/* clean up generated defines */
157#undef _EXECUTE
158#undef __EXECUTE
159#undef _GATE
160#undef __GATE
161#undef _GCC_PLUGIN_CONCAT2
162#undef _GCC_PLUGIN_CONCAT3
163#undef _GCC_PLUGIN_STRINGIFY
164#undef __GCC_PLUGIN_STRINGIFY
165#undef _HAS_EXECUTE
166#undef _HAS_GATE
167#undef _MAKE_PASS_NAME_PASS
168#undef __MAKE_PASS_NAME_PASS
169#undef _PASS_NAME_NAME
170#undef _PASS_NAME_PASS
171#undef __PASS_NAME_PASS
172#undef _PASS_NAME_PASS_DATA
173#undef __PASS_NAME_PASS_DATA
174
175#endif /* PASS_NAME */
diff --git a/scripts/gcc-plugins/gcc-generate-ipa-pass.h b/scripts/gcc-plugins/gcc-generate-ipa-pass.h
new file mode 100644
index 000000000000..9bd926e072f0
--- /dev/null
+++ b/scripts/gcc-plugins/gcc-generate-ipa-pass.h
@@ -0,0 +1,289 @@
1/*
2 * Generator for IPA pass related boilerplate code/data
3 *
4 * Supports gcc 4.5-6
5 *
6 * Usage:
7 *
8 * 1. before inclusion define PASS_NAME
9 * 2. before inclusion define NO_* for unimplemented callbacks
10 * NO_GENERATE_SUMMARY
11 * NO_READ_SUMMARY
12 * NO_WRITE_SUMMARY
13 * NO_READ_OPTIMIZATION_SUMMARY
14 * NO_WRITE_OPTIMIZATION_SUMMARY
15 * NO_STMT_FIXUP
16 * NO_FUNCTION_TRANSFORM
17 * NO_VARIABLE_TRANSFORM
18 * NO_GATE
19 * NO_EXECUTE
20 * 3. before inclusion define PROPERTIES_* and *TODO_FLAGS_* to override
21 * the default 0 values
22 * 4. for convenience, all the above will be undefined after inclusion!
23 * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
24 */
25
26#ifndef PASS_NAME
27#error at least PASS_NAME must be defined
28#else
29#define __GCC_PLUGIN_STRINGIFY(n) #n
30#define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n)
31#define _GCC_PLUGIN_CONCAT2(x, y) x ## y
32#define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z
33
34#define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data)
35#define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME)
36
37#define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass)
38#define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME)
39
40#define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME)
41
42#define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass)
43#define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME)
44
45#ifdef NO_GENERATE_SUMMARY
46#define _GENERATE_SUMMARY NULL
47#else
48#define __GENERATE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _generate_summary)
49#define _GENERATE_SUMMARY __GENERATE_SUMMARY(PASS_NAME)
50#endif
51
52#ifdef NO_READ_SUMMARY
53#define _READ_SUMMARY NULL
54#else
55#define __READ_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_summary)
56#define _READ_SUMMARY __READ_SUMMARY(PASS_NAME)
57#endif
58
59#ifdef NO_WRITE_SUMMARY
60#define _WRITE_SUMMARY NULL
61#else
62#define __WRITE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_summary)
63#define _WRITE_SUMMARY __WRITE_SUMMARY(PASS_NAME)
64#endif
65
66#ifdef NO_READ_OPTIMIZATION_SUMMARY
67#define _READ_OPTIMIZATION_SUMMARY NULL
68#else
69#define __READ_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_optimization_summary)
70#define _READ_OPTIMIZATION_SUMMARY __READ_OPTIMIZATION_SUMMARY(PASS_NAME)
71#endif
72
73#ifdef NO_WRITE_OPTIMIZATION_SUMMARY
74#define _WRITE_OPTIMIZATION_SUMMARY NULL
75#else
76#define __WRITE_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_optimization_summary)
77#define _WRITE_OPTIMIZATION_SUMMARY __WRITE_OPTIMIZATION_SUMMARY(PASS_NAME)
78#endif
79
80#ifdef NO_STMT_FIXUP
81#define _STMT_FIXUP NULL
82#else
83#define __STMT_FIXUP(n) _GCC_PLUGIN_CONCAT2(n, _stmt_fixup)
84#define _STMT_FIXUP __STMT_FIXUP(PASS_NAME)
85#endif
86
87#ifdef NO_FUNCTION_TRANSFORM
88#define _FUNCTION_TRANSFORM NULL
89#else
90#define __FUNCTION_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _function_transform)
91#define _FUNCTION_TRANSFORM __FUNCTION_TRANSFORM(PASS_NAME)
92#endif
93
94#ifdef NO_VARIABLE_TRANSFORM
95#define _VARIABLE_TRANSFORM NULL
96#else
97#define __VARIABLE_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _variable_transform)
98#define _VARIABLE_TRANSFORM __VARIABLE_TRANSFORM(PASS_NAME)
99#endif
100
101#ifdef NO_GATE
102#define _GATE NULL
103#define _HAS_GATE false
104#else
105#define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate)
106#define _GATE __GATE(PASS_NAME)
107#define _HAS_GATE true
108#endif
109
110#ifdef NO_EXECUTE
111#define _EXECUTE NULL
112#define _HAS_EXECUTE false
113#else
114#define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute)
115#define _EXECUTE __EXECUTE(PASS_NAME)
116#define _HAS_EXECUTE true
117#endif
118
119#ifndef PROPERTIES_REQUIRED
120#define PROPERTIES_REQUIRED 0
121#endif
122
123#ifndef PROPERTIES_PROVIDED
124#define PROPERTIES_PROVIDED 0
125#endif
126
127#ifndef PROPERTIES_DESTROYED
128#define PROPERTIES_DESTROYED 0
129#endif
130
131#ifndef TODO_FLAGS_START
132#define TODO_FLAGS_START 0
133#endif
134
135#ifndef TODO_FLAGS_FINISH
136#define TODO_FLAGS_FINISH 0
137#endif
138
139#ifndef FUNCTION_TRANSFORM_TODO_FLAGS_START
140#define FUNCTION_TRANSFORM_TODO_FLAGS_START 0
141#endif
142
143#if BUILDING_GCC_VERSION >= 4009
144namespace {
145static const pass_data _PASS_NAME_PASS_DATA = {
146#else
147static struct ipa_opt_pass_d _PASS_NAME_PASS = {
148 .pass = {
149#endif
150 .type = IPA_PASS,
151 .name = _PASS_NAME_NAME,
152#if BUILDING_GCC_VERSION >= 4008
153 .optinfo_flags = OPTGROUP_NONE,
154#endif
155#if BUILDING_GCC_VERSION >= 5000
156#elif BUILDING_GCC_VERSION == 4009
157 .has_gate = _HAS_GATE,
158 .has_execute = _HAS_EXECUTE,
159#else
160 .gate = _GATE,
161 .execute = _EXECUTE,
162 .sub = NULL,
163 .next = NULL,
164 .static_pass_number = 0,
165#endif
166 .tv_id = TV_NONE,
167 .properties_required = PROPERTIES_REQUIRED,
168 .properties_provided = PROPERTIES_PROVIDED,
169 .properties_destroyed = PROPERTIES_DESTROYED,
170 .todo_flags_start = TODO_FLAGS_START,
171 .todo_flags_finish = TODO_FLAGS_FINISH,
172#if BUILDING_GCC_VERSION < 4009
173 },
174 .generate_summary = _GENERATE_SUMMARY,
175 .write_summary = _WRITE_SUMMARY,
176 .read_summary = _READ_SUMMARY,
177#if BUILDING_GCC_VERSION >= 4006
178 .write_optimization_summary = _WRITE_OPTIMIZATION_SUMMARY,
179 .read_optimization_summary = _READ_OPTIMIZATION_SUMMARY,
180#endif
181 .stmt_fixup = _STMT_FIXUP,
182 .function_transform_todo_flags_start = FUNCTION_TRANSFORM_TODO_FLAGS_START,
183 .function_transform = _FUNCTION_TRANSFORM,
184 .variable_transform = _VARIABLE_TRANSFORM,
185#endif
186};
187
188#if BUILDING_GCC_VERSION >= 4009
189class _PASS_NAME_PASS : public ipa_opt_pass_d {
190public:
191 _PASS_NAME_PASS() : ipa_opt_pass_d(_PASS_NAME_PASS_DATA,
192 g,
193 _GENERATE_SUMMARY,
194 _WRITE_SUMMARY,
195 _READ_SUMMARY,
196 _WRITE_OPTIMIZATION_SUMMARY,
197 _READ_OPTIMIZATION_SUMMARY,
198 _STMT_FIXUP,
199 FUNCTION_TRANSFORM_TODO_FLAGS_START,
200 _FUNCTION_TRANSFORM,
201 _VARIABLE_TRANSFORM) {}
202
203#ifndef NO_GATE
204#if BUILDING_GCC_VERSION >= 5000
205 virtual bool gate(function *) { return _GATE(); }
206#else
207 virtual bool gate(void) { return _GATE(); }
208#endif
209#endif
210
211 virtual opt_pass *clone() { return new _PASS_NAME_PASS(); }
212
213#ifndef NO_EXECUTE
214#if BUILDING_GCC_VERSION >= 5000
215 virtual unsigned int execute(function *) { return _EXECUTE(); }
216#else
217 virtual unsigned int execute(void) { return _EXECUTE(); }
218#endif
219#endif
220};
221}
222
223opt_pass *_MAKE_PASS_NAME_PASS(void)
224{
225 return new _PASS_NAME_PASS();
226}
227#else
228struct opt_pass *_MAKE_PASS_NAME_PASS(void)
229{
230 return &_PASS_NAME_PASS.pass;
231}
232#endif
233
234/* clean up user provided defines */
235#undef PASS_NAME
236#undef NO_GENERATE_SUMMARY
237#undef NO_WRITE_SUMMARY
238#undef NO_READ_SUMMARY
239#undef NO_WRITE_OPTIMIZATION_SUMMARY
240#undef NO_READ_OPTIMIZATION_SUMMARY
241#undef NO_STMT_FIXUP
242#undef NO_FUNCTION_TRANSFORM
243#undef NO_VARIABLE_TRANSFORM
244#undef NO_GATE
245#undef NO_EXECUTE
246
247#undef FUNCTION_TRANSFORM_TODO_FLAGS_START
248#undef PROPERTIES_DESTROYED
249#undef PROPERTIES_PROVIDED
250#undef PROPERTIES_REQUIRED
251#undef TODO_FLAGS_FINISH
252#undef TODO_FLAGS_START
253
254/* clean up generated defines */
255#undef _EXECUTE
256#undef __EXECUTE
257#undef _FUNCTION_TRANSFORM
258#undef __FUNCTION_TRANSFORM
259#undef _GATE
260#undef __GATE
261#undef _GCC_PLUGIN_CONCAT2
262#undef _GCC_PLUGIN_CONCAT3
263#undef _GCC_PLUGIN_STRINGIFY
264#undef __GCC_PLUGIN_STRINGIFY
265#undef _GENERATE_SUMMARY
266#undef __GENERATE_SUMMARY
267#undef _HAS_EXECUTE
268#undef _HAS_GATE
269#undef _MAKE_PASS_NAME_PASS
270#undef __MAKE_PASS_NAME_PASS
271#undef _PASS_NAME_NAME
272#undef _PASS_NAME_PASS
273#undef __PASS_NAME_PASS
274#undef _PASS_NAME_PASS_DATA
275#undef __PASS_NAME_PASS_DATA
276#undef _READ_OPTIMIZATION_SUMMARY
277#undef __READ_OPTIMIZATION_SUMMARY
278#undef _READ_SUMMARY
279#undef __READ_SUMMARY
280#undef _STMT_FIXUP
281#undef __STMT_FIXUP
282#undef _VARIABLE_TRANSFORM
283#undef __VARIABLE_TRANSFORM
284#undef _WRITE_OPTIMIZATION_SUMMARY
285#undef __WRITE_OPTIMIZATION_SUMMARY
286#undef _WRITE_SUMMARY
287#undef __WRITE_SUMMARY
288
289#endif /* PASS_NAME */
diff --git a/scripts/gcc-plugins/gcc-generate-rtl-pass.h b/scripts/gcc-plugins/gcc-generate-rtl-pass.h
new file mode 100644
index 000000000000..1dc67a5aeadf
--- /dev/null
+++ b/scripts/gcc-plugins/gcc-generate-rtl-pass.h
@@ -0,0 +1,175 @@
1/*
2 * Generator for RTL pass related boilerplate code/data
3 *
4 * Supports gcc 4.5-6
5 *
6 * Usage:
7 *
8 * 1. before inclusion define PASS_NAME
9 * 2. before inclusion define NO_* for unimplemented callbacks
10 * NO_GATE
11 * NO_EXECUTE
12 * 3. before inclusion define PROPERTIES_* and TODO_FLAGS_* to override
13 * the default 0 values
14 * 4. for convenience, all the above will be undefined after inclusion!
15 * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
16 */
17
18#ifndef PASS_NAME
19#error at least PASS_NAME must be defined
20#else
21#define __GCC_PLUGIN_STRINGIFY(n) #n
22#define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n)
23#define _GCC_PLUGIN_CONCAT2(x, y) x ## y
24#define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z
25
26#define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data)
27#define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME)
28
29#define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass)
30#define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME)
31
32#define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME)
33
34#define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass)
35#define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME)
36
37#ifdef NO_GATE
38#define _GATE NULL
39#define _HAS_GATE false
40#else
41#define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate)
42#define _GATE __GATE(PASS_NAME)
43#define _HAS_GATE true
44#endif
45
46#ifdef NO_EXECUTE
47#define _EXECUTE NULL
48#define _HAS_EXECUTE false
49#else
50#define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute)
51#define _EXECUTE __EXECUTE(PASS_NAME)
52#define _HAS_EXECUTE true
53#endif
54
55#ifndef PROPERTIES_REQUIRED
56#define PROPERTIES_REQUIRED 0
57#endif
58
59#ifndef PROPERTIES_PROVIDED
60#define PROPERTIES_PROVIDED 0
61#endif
62
63#ifndef PROPERTIES_DESTROYED
64#define PROPERTIES_DESTROYED 0
65#endif
66
67#ifndef TODO_FLAGS_START
68#define TODO_FLAGS_START 0
69#endif
70
71#ifndef TODO_FLAGS_FINISH
72#define TODO_FLAGS_FINISH 0
73#endif
74
75#if BUILDING_GCC_VERSION >= 4009
76namespace {
77static const pass_data _PASS_NAME_PASS_DATA = {
78#else
79static struct rtl_opt_pass _PASS_NAME_PASS = {
80 .pass = {
81#endif
82 .type = RTL_PASS,
83 .name = _PASS_NAME_NAME,
84#if BUILDING_GCC_VERSION >= 4008
85 .optinfo_flags = OPTGROUP_NONE,
86#endif
87#if BUILDING_GCC_VERSION >= 5000
88#elif BUILDING_GCC_VERSION == 4009
89 .has_gate = _HAS_GATE,
90 .has_execute = _HAS_EXECUTE,
91#else
92 .gate = _GATE,
93 .execute = _EXECUTE,
94 .sub = NULL,
95 .next = NULL,
96 .static_pass_number = 0,
97#endif
98 .tv_id = TV_NONE,
99 .properties_required = PROPERTIES_REQUIRED,
100 .properties_provided = PROPERTIES_PROVIDED,
101 .properties_destroyed = PROPERTIES_DESTROYED,
102 .todo_flags_start = TODO_FLAGS_START,
103 .todo_flags_finish = TODO_FLAGS_FINISH,
104#if BUILDING_GCC_VERSION < 4009
105 }
106#endif
107};
108
109#if BUILDING_GCC_VERSION >= 4009
110class _PASS_NAME_PASS : public rtl_opt_pass {
111public:
112 _PASS_NAME_PASS() : rtl_opt_pass(_PASS_NAME_PASS_DATA, g) {}
113
114#ifndef NO_GATE
115#if BUILDING_GCC_VERSION >= 5000
116 virtual bool gate(function *) { return _GATE(); }
117#else
118 virtual bool gate(void) { return _GATE(); }
119#endif
120#endif
121
122 virtual opt_pass *clone() { return new _PASS_NAME_PASS(); }
123
124#ifndef NO_EXECUTE
125#if BUILDING_GCC_VERSION >= 5000
126 virtual unsigned int execute(function *) { return _EXECUTE(); }
127#else
128 virtual unsigned int execute(void) { return _EXECUTE(); }
129#endif
130#endif
131};
132}
133
134opt_pass *_MAKE_PASS_NAME_PASS(void)
135{
136 return new _PASS_NAME_PASS();
137}
138#else
139struct opt_pass *_MAKE_PASS_NAME_PASS(void)
140{
141 return &_PASS_NAME_PASS.pass;
142}
143#endif
144
145/* clean up user provided defines */
146#undef PASS_NAME
147#undef NO_GATE
148#undef NO_EXECUTE
149
150#undef PROPERTIES_DESTROYED
151#undef PROPERTIES_PROVIDED
152#undef PROPERTIES_REQUIRED
153#undef TODO_FLAGS_FINISH
154#undef TODO_FLAGS_START
155
156/* clean up generated defines */
157#undef _EXECUTE
158#undef __EXECUTE
159#undef _GATE
160#undef __GATE
161#undef _GCC_PLUGIN_CONCAT2
162#undef _GCC_PLUGIN_CONCAT3
163#undef _GCC_PLUGIN_STRINGIFY
164#undef __GCC_PLUGIN_STRINGIFY
165#undef _HAS_EXECUTE
166#undef _HAS_GATE
167#undef _MAKE_PASS_NAME_PASS
168#undef __MAKE_PASS_NAME_PASS
169#undef _PASS_NAME_NAME
170#undef _PASS_NAME_PASS
171#undef __PASS_NAME_PASS
172#undef _PASS_NAME_PASS_DATA
173#undef __PASS_NAME_PASS_DATA
174
175#endif /* PASS_NAME */
diff --git a/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h b/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h
new file mode 100644
index 000000000000..a27e2b36afaa
--- /dev/null
+++ b/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h
@@ -0,0 +1,175 @@
1/*
2 * Generator for SIMPLE_IPA pass related boilerplate code/data
3 *
4 * Supports gcc 4.5-6
5 *
6 * Usage:
7 *
8 * 1. before inclusion define PASS_NAME
9 * 2. before inclusion define NO_* for unimplemented callbacks
10 * NO_GATE
11 * NO_EXECUTE
12 * 3. before inclusion define PROPERTIES_* and TODO_FLAGS_* to override
13 * the default 0 values
14 * 4. for convenience, all the above will be undefined after inclusion!
15 * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
16 */
17
18#ifndef PASS_NAME
19#error at least PASS_NAME must be defined
20#else
21#define __GCC_PLUGIN_STRINGIFY(n) #n
22#define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n)
23#define _GCC_PLUGIN_CONCAT2(x, y) x ## y
24#define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z
25
26#define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data)
27#define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME)
28
29#define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass)
30#define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME)
31
32#define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME)
33
34#define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass)
35#define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME)
36
37#ifdef NO_GATE
38#define _GATE NULL
39#define _HAS_GATE false
40#else
41#define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate)
42#define _GATE __GATE(PASS_NAME)
43#define _HAS_GATE true
44#endif
45
46#ifdef NO_EXECUTE
47#define _EXECUTE NULL
48#define _HAS_EXECUTE false
49#else
50#define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute)
51#define _EXECUTE __EXECUTE(PASS_NAME)
52#define _HAS_EXECUTE true
53#endif
54
55#ifndef PROPERTIES_REQUIRED
56#define PROPERTIES_REQUIRED 0
57#endif
58
59#ifndef PROPERTIES_PROVIDED
60#define PROPERTIES_PROVIDED 0
61#endif
62
63#ifndef PROPERTIES_DESTROYED
64#define PROPERTIES_DESTROYED 0
65#endif
66
67#ifndef TODO_FLAGS_START
68#define TODO_FLAGS_START 0
69#endif
70
71#ifndef TODO_FLAGS_FINISH
72#define TODO_FLAGS_FINISH 0
73#endif
74
75#if BUILDING_GCC_VERSION >= 4009
76namespace {
77static const pass_data _PASS_NAME_PASS_DATA = {
78#else
79static struct simple_ipa_opt_pass _PASS_NAME_PASS = {
80 .pass = {
81#endif
82 .type = SIMPLE_IPA_PASS,
83 .name = _PASS_NAME_NAME,
84#if BUILDING_GCC_VERSION >= 4008
85 .optinfo_flags = OPTGROUP_NONE,
86#endif
87#if BUILDING_GCC_VERSION >= 5000
88#elif BUILDING_GCC_VERSION == 4009
89 .has_gate = _HAS_GATE,
90 .has_execute = _HAS_EXECUTE,
91#else
92 .gate = _GATE,
93 .execute = _EXECUTE,
94 .sub = NULL,
95 .next = NULL,
96 .static_pass_number = 0,
97#endif
98 .tv_id = TV_NONE,
99 .properties_required = PROPERTIES_REQUIRED,
100 .properties_provided = PROPERTIES_PROVIDED,
101 .properties_destroyed = PROPERTIES_DESTROYED,
102 .todo_flags_start = TODO_FLAGS_START,
103 .todo_flags_finish = TODO_FLAGS_FINISH,
104#if BUILDING_GCC_VERSION < 4009
105 }
106#endif
107};
108
109#if BUILDING_GCC_VERSION >= 4009
110class _PASS_NAME_PASS : public simple_ipa_opt_pass {
111public:
112 _PASS_NAME_PASS() : simple_ipa_opt_pass(_PASS_NAME_PASS_DATA, g) {}
113
114#ifndef NO_GATE
115#if BUILDING_GCC_VERSION >= 5000
116 virtual bool gate(function *) { return _GATE(); }
117#else
118 virtual bool gate(void) { return _GATE(); }
119#endif
120#endif
121
122 virtual opt_pass *clone() { return new _PASS_NAME_PASS(); }
123
124#ifndef NO_EXECUTE
125#if BUILDING_GCC_VERSION >= 5000
126 virtual unsigned int execute(function *) { return _EXECUTE(); }
127#else
128 virtual unsigned int execute(void) { return _EXECUTE(); }
129#endif
130#endif
131};
132}
133
134opt_pass *_MAKE_PASS_NAME_PASS(void)
135{
136 return new _PASS_NAME_PASS();
137}
138#else
139struct opt_pass *_MAKE_PASS_NAME_PASS(void)
140{
141 return &_PASS_NAME_PASS.pass;
142}
143#endif
144
145/* clean up user provided defines */
146#undef PASS_NAME
147#undef NO_GATE
148#undef NO_EXECUTE
149
150#undef PROPERTIES_DESTROYED
151#undef PROPERTIES_PROVIDED
152#undef PROPERTIES_REQUIRED
153#undef TODO_FLAGS_FINISH
154#undef TODO_FLAGS_START
155
156/* clean up generated defines */
157#undef _EXECUTE
158#undef __EXECUTE
159#undef _GATE
160#undef __GATE
161#undef _GCC_PLUGIN_CONCAT2
162#undef _GCC_PLUGIN_CONCAT3
163#undef _GCC_PLUGIN_STRINGIFY
164#undef __GCC_PLUGIN_STRINGIFY
165#undef _HAS_EXECUTE
166#undef _HAS_GATE
167#undef _MAKE_PASS_NAME_PASS
168#undef __MAKE_PASS_NAME_PASS
169#undef _PASS_NAME_NAME
170#undef _PASS_NAME_PASS
171#undef __PASS_NAME_PASS
172#undef _PASS_NAME_PASS_DATA
173#undef __PASS_NAME_PASS_DATA
174
175#endif /* PASS_NAME */
diff --git a/scripts/gcc-plugins/sancov_plugin.c b/scripts/gcc-plugins/sancov_plugin.c
new file mode 100644
index 000000000000..aedd6113cb73
--- /dev/null
+++ b/scripts/gcc-plugins/sancov_plugin.c
@@ -0,0 +1,144 @@
1/*
2 * Copyright 2011-2016 by Emese Revfy <re.emese@gmail.com>
3 * Licensed under the GPL v2, or (at your option) v3
4 *
5 * Homepage:
6 * https://github.com/ephox-gcc-plugins/sancov
7 *
8 * This plugin inserts a __sanitizer_cov_trace_pc() call at the start of basic blocks.
9 * It supports all gcc versions with plugin support (from gcc-4.5 on).
10 * It is based on the commit "Add fuzzing coverage support" by Dmitry Vyukov <dvyukov@google.com>.
11 *
12 * You can read about it more here:
13 * https://gcc.gnu.org/viewcvs/gcc?limit_changes=0&view=revision&revision=231296
14 * http://lwn.net/Articles/674854/
15 * https://github.com/google/syzkaller
16 * https://lwn.net/Articles/677764/
17 *
18 * Usage:
19 * make run
20 */
21
22#include "gcc-common.h"
23
24int plugin_is_GPL_compatible;
25
26tree sancov_fndecl;
27
28static struct plugin_info sancov_plugin_info = {
29 .version = "20160402",
30 .help = "sancov plugin\n",
31};
32
33static unsigned int sancov_execute(void)
34{
35 basic_block bb;
36
37 /* Remove this line when this plugin and kcov will be in the kernel.
38 if (!strcmp(DECL_NAME_POINTER(current_function_decl), DECL_NAME_POINTER(sancov_fndecl)))
39 return 0;
40 */
41
42 FOR_EACH_BB_FN(bb, cfun) {
43 const_gimple stmt;
44 gcall *gcall;
45 gimple_stmt_iterator gsi = gsi_after_labels(bb);
46
47 if (gsi_end_p(gsi))
48 continue;
49
50 stmt = gsi_stmt(gsi);
51 gcall = as_a_gcall(gimple_build_call(sancov_fndecl, 0));
52 gimple_set_location(gcall, gimple_location(stmt));
53 gsi_insert_before(&gsi, gcall, GSI_SAME_STMT);
54 }
55 return 0;
56}
57
58#define PASS_NAME sancov
59
60#define NO_GATE
61#define TODO_FLAGS_FINISH TODO_dump_func | TODO_verify_stmts | TODO_update_ssa_no_phi | TODO_verify_flow
62
63#include "gcc-generate-gimple-pass.h"
64
65static void sancov_start_unit(void __unused *gcc_data, void __unused *user_data)
66{
67 tree leaf_attr, nothrow_attr;
68 tree BT_FN_VOID = build_function_type_list(void_type_node, NULL_TREE);
69
70 sancov_fndecl = build_fn_decl("__sanitizer_cov_trace_pc", BT_FN_VOID);
71
72 DECL_ASSEMBLER_NAME(sancov_fndecl);
73 TREE_PUBLIC(sancov_fndecl) = 1;
74 DECL_EXTERNAL(sancov_fndecl) = 1;
75 DECL_ARTIFICIAL(sancov_fndecl) = 1;
76 DECL_PRESERVE_P(sancov_fndecl) = 1;
77 DECL_UNINLINABLE(sancov_fndecl) = 1;
78 TREE_USED(sancov_fndecl) = 1;
79
80 nothrow_attr = tree_cons(get_identifier("nothrow"), NULL, NULL);
81 decl_attributes(&sancov_fndecl, nothrow_attr, 0);
82 gcc_assert(TREE_NOTHROW(sancov_fndecl));
83#if BUILDING_GCC_VERSION > 4005
84 leaf_attr = tree_cons(get_identifier("leaf"), NULL, NULL);
85 decl_attributes(&sancov_fndecl, leaf_attr, 0);
86#endif
87}
88
89int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
90{
91 int i;
92 struct register_pass_info sancov_plugin_pass_info;
93 const char * const plugin_name = plugin_info->base_name;
94 const int argc = plugin_info->argc;
95 const struct plugin_argument * const argv = plugin_info->argv;
96 bool enable = true;
97
98 static const struct ggc_root_tab gt_ggc_r_gt_sancov[] = {
99 {
100 .base = &sancov_fndecl,
101 .nelt = 1,
102 .stride = sizeof(sancov_fndecl),
103 .cb = &gt_ggc_mx_tree_node,
104 .pchw = &gt_pch_nx_tree_node
105 },
106 LAST_GGC_ROOT_TAB
107 };
108
109 /* BBs can be split afterwards?? */
110 sancov_plugin_pass_info.pass = make_sancov_pass();
111#if BUILDING_GCC_VERSION >= 4009
112 sancov_plugin_pass_info.reference_pass_name = "asan";
113#else
114 sancov_plugin_pass_info.reference_pass_name = "nrv";
115#endif
116 sancov_plugin_pass_info.ref_pass_instance_number = 0;
117 sancov_plugin_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118
119 if (!plugin_default_version_check(version, &gcc_version)) {
120 error(G_("incompatible gcc/plugin versions"));
121 return 1;
122 }
123
124 for (i = 0; i < argc; ++i) {
125 if (!strcmp(argv[i].key, "no-sancov")) {
126 enable = false;
127 continue;
128 }
129 error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
130 }
131
132 register_callback(plugin_name, PLUGIN_INFO, NULL, &sancov_plugin_info);
133
134 if (!enable)
135 return 0;
136
137#if BUILDING_GCC_VERSION < 6000
138 register_callback(plugin_name, PLUGIN_START_UNIT, &sancov_start_unit, NULL);
139 register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_sancov);
140 register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &sancov_plugin_pass_info);
141#endif
142
143 return 0;
144}
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index f0f6d9d75435..4f727eb5ec43 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -180,7 +180,7 @@ else
180fi; 180fi;
181 181
182# final build of init/ 182# final build of init/
183${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init 183${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}"
184 184
185kallsymso="" 185kallsymso=""
186kallsyms_vmlinux="" 186kallsyms_vmlinux=""
diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 86e56fef7473..4d4418a8d54d 100755
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -329,6 +329,7 @@ fi
329(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles" 329(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
330(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles" 330(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
331(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles" 331(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
332(cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles"
332destdir=$kernel_headers_dir/usr/src/linux-headers-$version 333destdir=$kernel_headers_dir/usr/src/linux-headers-$version
333mkdir -p "$destdir" 334mkdir -p "$destdir"
334(cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -) 335(cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 63d91e22ed7c..966dd3924ea9 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -143,7 +143,7 @@ fi
143if test -e include/config/auto.conf; then 143if test -e include/config/auto.conf; then
144 . include/config/auto.conf 144 . include/config/auto.conf
145else 145else
146 echo "Error: kernelrelease not valid - run 'make prepare' to update it" 146 echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
147 exit 1 147 exit 1
148fi 148fi
149 149