Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild

Pull kbuild updates from Michal Marek:

- new option CONFIG_TRIM_UNUSED_KSYMS which does a two-pass build and
unexports symbols which are not used in the current config [Nicolas
Pitre]

- several kbuild rule cleanups [Masahiro Yamada]

- warning option adjustments for gcov etc [Arnd Bergmann]

- a few more small fixes

* 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild: (31 commits)
kbuild: move -Wunused-const-variable to W=1 warning level
kbuild: fix if_change and friends to consider argument order
kbuild: fix adjust_autoksyms.sh for modules that need only one symbol
kbuild: fix ksym_dep_filter when multiple EXPORT_SYMBOL() on the same line
gcov: disable -Wmaybe-uninitialized warning
gcov: disable tree-loop-im to reduce stack usage
gcov: disable for COMPILE_TEST
Kbuild: disable 'maybe-uninitialized' warning for CONFIG_PROFILE_ALL_BRANCHES
Kbuild: change CC_OPTIMIZE_FOR_SIZE definition
kbuild: forbid kernel directory to contain spaces and colons
kbuild: adjust ksym_dep_filter for some cmd_* renames
kbuild: Fix dependencies for final vmlinux link
kbuild: better abstract vmlinux sequential prerequisites
kbuild: fix call to adjust_autoksyms.sh when output directory specified
kbuild: Get rid of KBUILD_STR
kbuild: rename cmd_as_s_S to cmd_cpp_s_S
kbuild: rename cmd_cc_i_c to cmd_cpp_i_c
kbuild: drop redundant "PHONY += FORCE"
kbuild: delete unnecessary "@:"
kbuild: mark help target as PHONY
...

+335 -95
+47 -19
Makefile
··· 128 128 # Cancel implicit rules on top Makefile 129 129 $(CURDIR)/Makefile Makefile: ; 130 130 131 + ifneq ($(words $(subst :, ,$(CURDIR))), 1) 132 + $(error main directory cannot contain spaces nor colons) 133 + endif 134 + 131 135 ifneq ($(KBUILD_OUTPUT),) 132 136 # Invoke a second make in the output directory, passing relevant variables 133 137 # check that the output directory actually exists ··· 146 142 $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make 147 143 @: 148 144 149 - sub-make: FORCE 145 + sub-make: 150 146 $(Q)$(MAKE) -C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR) \ 151 147 -f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS)) 152 148 ··· 368 364 LDFLAGS_MODULE = 369 365 CFLAGS_KERNEL = 370 366 AFLAGS_KERNEL = 371 - CFLAGS_GCOV = -fprofile-arcs -ftest-coverage 367 + CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -fno-tree-loop-im -Wno-maybe-uninitialized 372 368 CFLAGS_KCOV = -fsanitize-coverage=trace-pc 373 369 374 370 ··· 621 617 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE 622 618 KBUILD_CFLAGS += -Os $(call cc-disable-warning,maybe-uninitialized,) 623 619 else 624 - KBUILD_CFLAGS += -O2 620 + ifdef CONFIG_PROFILE_ALL_BRANCHES 621 + KBUILD_CFLAGS += -O2 $(call cc-disable-warning,maybe-uninitialized,) 622 + else 623 + KBUILD_CFLAGS += -O2 624 + endif 625 625 endif 626 626 627 627 # Tell gcc to never replace conditional load with a non-conditional one ··· 705 697 KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) 706 698 else 707 699 708 - # This warning generated too much noise in a regular build. 709 - # Use make W=1 to enable this warning (see scripts/Makefile.build) 700 + # These warnings generated too much noise in a regular build. 701 + # Use make W=1 to enable them (see scripts/Makefile.build) 710 702 KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) 703 + KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) 711 704 endif 712 705 713 706 ifdef CONFIG_FRAME_POINTER ··· 935 926 936 927 vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) 937 928 938 - # Final link of vmlinux 939 - cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) 940 - quiet_cmd_link-vmlinux = LINK $@ 941 - 942 - # Include targets which we want to 943 - # execute if the rest of the kernel build went well. 944 - vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE 929 + # Include targets which we want to execute sequentially if the rest of the 930 + # kernel build went well. If CONFIG_TRIM_UNUSED_KSYMS is set, this might be 931 + # evaluated more than once. 932 + PHONY += vmlinux_prereq 933 + vmlinux_prereq: $(vmlinux-deps) FORCE 945 934 ifdef CONFIG_HEADERS_CHECK 946 935 $(Q)$(MAKE) -f $(srctree)/Makefile headers_check 947 - endif 948 - ifdef CONFIG_SAMPLES 949 - $(Q)$(MAKE) $(build)=samples 950 936 endif 951 937 ifdef CONFIG_BUILD_DOCSRC 952 938 $(Q)$(MAKE) $(build)=Documentation ··· 949 945 ifdef CONFIG_GDB_SCRIPTS 950 946 $(Q)ln -fsn `cd $(srctree) && /bin/pwd`/scripts/gdb/vmlinux-gdb.py 951 947 endif 948 + ifdef CONFIG_TRIM_UNUSED_KSYMS 949 + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ 950 + "$(MAKE) KBUILD_MODULES=1 -f $(srctree)/Makefile vmlinux_prereq" 951 + endif 952 + 953 + # standalone target for easier testing 954 + include/generated/autoksyms.h: FORCE 955 + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh true 956 + 957 + # Final link of vmlinux 958 + cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) 959 + quiet_cmd_link-vmlinux = LINK $@ 960 + 961 + vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE 952 962 +$(call if_changed,link-vmlinux) 963 + 964 + # Build samples along the rest of the kernel 965 + ifdef CONFIG_SAMPLES 966 + vmlinux-dirs += samples 967 + endif 953 968 954 969 # The actual objects are generated when descending, 955 970 # make sure no implicit rule kicks in ··· 1021 998 prepare1: prepare2 $(version_h) include/generated/utsrelease.h \ 1022 999 include/config/auto.conf 1023 1000 $(cmd_crmodverdir) 1001 + $(Q)test -e include/generated/autoksyms.h || \ 1002 + touch include/generated/autoksyms.h 1024 1003 1025 1004 archprepare: archheaders archscripts prepare1 scripts_basic 1026 1005 1027 - prepare0: archprepare FORCE 1006 + prepare0: archprepare 1028 1007 $(Q)$(MAKE) $(build)=. 1029 1008 1030 1009 # All the preparing.. ··· 1086 1061 export INSTALL_FW_PATH 1087 1062 1088 1063 PHONY += firmware_install 1089 - firmware_install: FORCE 1064 + firmware_install: 1090 1065 @mkdir -p $(objtree)/firmware 1091 1066 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_install 1092 1067 ··· 1106 1081 archscripts: 1107 1082 1108 1083 PHONY += __headers 1109 - __headers: $(version_h) scripts_basic asm-generic archheaders archscripts FORCE 1084 + __headers: $(version_h) scripts_basic asm-generic archheaders archscripts 1110 1085 $(Q)$(MAKE) $(build)=scripts build_unifdef 1111 1086 1112 1087 PHONY += headers_install_all ··· 1217 1192 # Modules not configured 1218 1193 # --------------------------------------------------------------------------- 1219 1194 1220 - modules modules_install: FORCE 1195 + PHONY += modules modules_install 1196 + modules modules_install: 1221 1197 @echo >&2 1222 1198 @echo >&2 "The present kernel configuration has modules disabled." 1223 1199 @echo >&2 "Type 'make config' and enable loadable module support." ··· 1309 1283 board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig)) 1310 1284 board-dirs := $(sort $(notdir $(board-dirs:/=))) 1311 1285 1286 + PHONY += help 1312 1287 help: 1313 1288 @echo 'Cleaning targets:' 1314 1289 @echo ' clean - Remove most generated files but keep the config and' ··· 1480 1453 clean: rm-dirs := $(MODVERDIR) 1481 1454 clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers 1482 1455 1456 + PHONY += help 1483 1457 help: 1484 1458 @echo ' Building external modules.' 1485 1459 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
-1
arch/arm/boot/Makefile
··· 82 82 83 83 $(obj)/bootp/bootp: $(obj)/zImage initrd FORCE 84 84 $(Q)$(MAKE) $(build)=$(obj)/bootp $@ 85 - @: 86 85 87 86 $(obj)/bootpImage: $(obj)/bootp/bootp FORCE 88 87 $(call if_changed,objcopy)
+1 -2
arch/arm/boot/bootp/Makefile
··· 17 17 # Note that bootp.lds picks up kernel.o and initrd.o 18 18 $(obj)/bootp: $(src)/bootp.lds $(addprefix $(obj)/,init.o kernel.o initrd.o) FORCE 19 19 $(call if_changed,ld) 20 - @: 21 20 22 21 # kernel.o and initrd.o includes a binary image using 23 22 # .incbin, a dependency which is not tracked automatically ··· 25 26 26 27 $(obj)/initrd.o: $(INITRD) FORCE 27 28 28 - PHONY += $(INITRD) FORCE 29 + PHONY += $(INITRD)
+1 -1
arch/arm/vdso/Makefile
··· 74 74 @mkdir -p $(MODLIB)/vdso 75 75 76 76 PHONY += vdso_install 77 - vdso_install: $(obj)/vdso.so.dbg $(MODLIB)/vdso FORCE 77 + vdso_install: $(obj)/vdso.so.dbg $(MODLIB)/vdso 78 78 $(call cmd,vdso_install)
-1
arch/h8300/boot/compressed/Makefile
··· 23 23 24 24 $(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o $(LIBGCC) FORCE 25 25 $(call if_changed,ld) 26 - @: 27 26 28 27 $(obj)/vmlinux.bin: vmlinux FORCE 29 28 $(call if_changed,objcopy)
+3 -3
arch/ia64/Makefile
··· 95 95 echo '* unwcheck - Check vmlinux for invalid unwind info' 96 96 endef 97 97 98 - archprepare: make_nr_irqs_h FORCE 99 - PHONY += make_nr_irqs_h FORCE 98 + archprepare: make_nr_irqs_h 99 + PHONY += make_nr_irqs_h 100 100 101 - make_nr_irqs_h: FORCE 101 + make_nr_irqs_h: 102 102 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
-1
arch/m32r/boot/compressed/Makefile
··· 19 19 20 20 $(obj)/vmlinux: $(obj)/vmlinux.lds $(OBJECTS) $(obj)/piggy.o FORCE 21 21 $(call if_changed,ld) 22 - @: 23 22 24 23 $(obj)/vmlinux.bin: vmlinux FORCE 25 24 $(call if_changed,objcopy)
-1
arch/mn10300/boot/compressed/Makefile
··· 8 8 9 9 $(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE 10 10 $(call if_changed,ld) 11 - @: 12 11 13 12 $(obj)/vmlinux.bin: vmlinux FORCE 14 13 $(call if_changed,objcopy)
-1
arch/nios2/boot/compressed/Makefile
··· 11 11 12 12 $(obj)/vmlinux: $(obj)/vmlinux.lds $(OBJECTS) $(obj)/piggy.o FORCE 13 13 $(call if_changed,ld) 14 - @: 15 14 16 15 LDFLAGS_piggy.o := -r --format binary --oformat elf32-littlenios2 -T 17 16
-1
arch/s390/boot/compressed/Makefile
··· 22 22 LDFLAGS_vmlinux := --oformat $(LD_BFD) -e startup -T 23 23 $(obj)/vmlinux: $(obj)/vmlinux.lds $(OBJECTS) 24 24 $(call if_changed,ld) 25 - @: 26 25 27 26 sed-sizes := -e 's/^\([0-9a-fA-F]*\) . \(__bss_start\|_end\)$$/\#define SZ\2 0x\1/p' 28 27
-1
arch/sh/boot/compressed/Makefile
··· 55 55 56 56 $(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o $(lib1funcs-obj) FORCE 57 57 $(call if_changed,ld) 58 - @: 59 58 60 59 $(obj)/vmlinux.bin: vmlinux FORCE 61 60 $(call if_changed,objcopy)
-1
arch/sh/boot/romimage/Makefile
··· 17 17 18 18 $(obj)/vmlinux: $(obj)/head.o $(obj-y) $(obj)/piggy.o FORCE 19 19 $(call if_changed,ld) 20 - @: 21 20 22 21 OBJCOPYFLAGS += -j .empty_zero_page 23 22
+1 -1
arch/unicore32/boot/Makefile
··· 31 31 $(call if_changed,uimage) 32 32 @echo ' Image $@ is ready' 33 33 34 - PHONY += initrd FORCE 34 + PHONY += initrd 35 35 initrd: 36 36 @test "$(INITRD)" != "" || \ 37 37 (echo You must specify INITRD; exit -1)
-1
arch/unicore32/boot/compressed/Makefile
··· 54 54 $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/head.o $(obj)/piggy.o \ 55 55 $(obj)/misc.o FORCE 56 56 $(call if_changed,ld) 57 - @: 58 57 59 58 # We now have a PIC decompressor implementation. Decompressors running 60 59 # from RAM should not define ZTEXTADDR. Decompressors running directly
-1
arch/x86/boot/compressed/Makefile
··· 87 87 88 88 $(obj)/vmlinux: $(vmlinux-objs-y) FORCE 89 89 $(call if_changed,ld) 90 - @: 91 90 92 91 OBJCOPYFLAGS_vmlinux.bin := -R .comment -S 93 92 $(obj)/vmlinux.bin: vmlinux FORCE
+2 -2
arch/x86/entry/vdso/Makefile
··· 193 193 $(MODLIB)/vdso: FORCE 194 194 @mkdir -p $(MODLIB)/vdso 195 195 196 - $(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso FORCE 196 + $(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso 197 197 $(call cmd,vdso_install) 198 198 199 199 PHONY += vdso_install $(vdso_img_insttargets) 200 - vdso_install: $(vdso_img_insttargets) FORCE 200 + vdso_install: $(vdso_img_insttargets) 201 201 202 202 clean-files := vdso32.so vdso32.so.dbg vdso64* vdso-image-*.c vdsox32.so*
-2
arch/x86/purgatory/Makefile
··· 26 26 27 27 $(obj)/kexec-purgatory.c: $(obj)/purgatory.ro FORCE 28 28 $(call if_changed,bin2c) 29 - @: 30 - 31 29 32 30 obj-$(CONFIG_KEXEC_FILE) += kexec-purgatory.o
-1
arch/x86/realmode/rm/Makefile
··· 59 59 targets += realmode.bin 60 60 $(obj)/realmode.bin: $(obj)/realmode.elf $(obj)/realmode.relocs FORCE 61 61 $(call if_changed,objcopy) 62 - @: 63 62 64 63 quiet_cmd_relocs = RELOCS $@ 65 64 cmd_relocs = arch/x86/tools/relocs --realmode $< > $@
+31 -2
include/linux/export.h
··· 38 38 39 39 #ifdef CONFIG_MODULES 40 40 41 - #ifndef __GENKSYMS__ 41 + #if defined(__KERNEL__) && !defined(__GENKSYMS__) 42 42 #ifdef CONFIG_MODVERSIONS 43 43 /* Mark the CRC weak since genksyms apparently decides not to 44 44 * generate a checksums for some symbols */ ··· 53 53 #endif 54 54 55 55 /* For every exported symbol, place a struct in the __ksymtab section */ 56 - #define __EXPORT_SYMBOL(sym, sec) \ 56 + #define ___EXPORT_SYMBOL(sym, sec) \ 57 57 extern typeof(sym) sym; \ 58 58 __CRC_SYMBOL(sym, sec) \ 59 59 static const char __kstrtab_##sym[] \ ··· 64 64 __used \ 65 65 __attribute__((section("___ksymtab" sec "+" #sym), unused)) \ 66 66 = { (unsigned long)&sym, __kstrtab_##sym } 67 + 68 + #if defined(__KSYM_DEPS__) 69 + 70 + /* 71 + * For fine grained build dependencies, we want to tell the build system 72 + * about each possible exported symbol even if they're not actually exported. 73 + * We use a string pattern that is unlikely to be valid code that the build 74 + * system filters out from the preprocessor output (see ksym_dep_filter 75 + * in scripts/Kbuild.include). 76 + */ 77 + #define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym === 78 + 79 + #elif defined(CONFIG_TRIM_UNUSED_KSYMS) 80 + 81 + #include <linux/kconfig.h> 82 + #include <generated/autoksyms.h> 83 + 84 + #define __EXPORT_SYMBOL(sym, sec) \ 85 + __cond_export_sym(sym, sec, config_enabled(__KSYM_##sym)) 86 + #define __cond_export_sym(sym, sec, conf) \ 87 + ___cond_export_sym(sym, sec, conf) 88 + #define ___cond_export_sym(sym, sec, enabled) \ 89 + __cond_export_sym_##enabled(sym, sec) 90 + #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec) 91 + #define __cond_export_sym_0(sym, sec) /* nothing */ 92 + 93 + #else 94 + #define __EXPORT_SYMBOL ___EXPORT_SYMBOL 95 + #endif 67 96 68 97 #define EXPORT_SYMBOL(sym) \ 69 98 __EXPORT_SYMBOL(sym, "")
+29
init/Kconfig
··· 1306 1306 1307 1307 endif 1308 1308 1309 + choice 1310 + prompt "Compiler optimization level" 1311 + default CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE 1312 + 1313 + config CC_OPTIMIZE_FOR_PERFORMANCE 1314 + bool "Optimize for performance" 1315 + help 1316 + This is the default optimization level for the kernel, building 1317 + with the "-O2" compiler flag for best performance and most 1318 + helpful compile-time warnings. 1319 + 1309 1320 config CC_OPTIMIZE_FOR_SIZE 1310 1321 bool "Optimize for size" 1311 1322 help ··· 1324 1313 your compiler resulting in a smaller kernel. 1325 1314 1326 1315 If unsure, say N. 1316 + 1317 + endchoice 1327 1318 1328 1319 config SYSCTL 1329 1320 bool ··· 2061 2048 bool "XZ" 2062 2049 2063 2050 endchoice 2051 + 2052 + config TRIM_UNUSED_KSYMS 2053 + bool "Trim unused exported kernel symbols" 2054 + depends on MODULES && !UNUSED_SYMBOLS 2055 + help 2056 + The kernel and some modules make many symbols available for 2057 + other modules to use via EXPORT_SYMBOL() and variants. Depending 2058 + on the set of modules being selected in your kernel configuration, 2059 + many of those exported symbols might never be used. 2060 + 2061 + This option allows for unused exported symbols to be dropped from 2062 + the build. In turn, this provides the compiler more opportunities 2063 + (especially when using LTO) for optimizing the code and reducing 2064 + binary size. This might have some security advantages as well. 2065 + 2066 + If unsure say N. 2064 2067 2065 2068 endif # MODULES 2066 2069
+1
kernel/gcov/Kconfig
··· 37 37 38 38 config GCOV_PROFILE_ALL 39 39 bool "Profile entire Kernel" 40 + depends on !COMPILE_TEST 40 41 depends on GCOV_KERNEL 41 42 depends on ARCH_HAS_GCOV_PROFILE_ALL 42 43 default n
+38 -7
scripts/Kbuild.include
··· 7 7 squote := ' 8 8 empty := 9 9 space := $(empty) $(empty) 10 + space_escape := _-_SPACE_-_ 10 11 11 12 ### 12 13 # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o ··· 227 226 # See Documentation/kbuild/makefiles.txt for more info 228 227 229 228 ifneq ($(KBUILD_NOCMDDEP),1) 230 - # Check if both arguments has same arguments. Result is empty string if equal. 231 - # User may override this check using make KBUILD_NOCMDDEP=1 232 - arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ 233 - $(filter-out $(cmd_$@), $(cmd_$(1))) ) 229 + # Check if both arguments are the same including their order. Result is empty 230 + # string if equal. User may override this check using make KBUILD_NOCMDDEP=1 231 + arg-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \ 232 + $(subst $(space),$(space_escape),$(strip $(cmd_$1)))) 234 233 else 235 234 arg-check = $(if $(strip $(cmd_$@)),,1) 236 235 endif ··· 257 256 # Execute the command and also postprocess generated .d dependencies file. 258 257 if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ 259 258 @set -e; \ 259 + $(cmd_and_fixdep), @:) 260 + 261 + ifndef CONFIG_TRIM_UNUSED_KSYMS 262 + 263 + cmd_and_fixdep = \ 260 264 $(echo-cmd) $(cmd_$(1)); \ 261 265 scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ 262 266 rm -f $(depfile); \ 263 - mv -f $(dot-target).tmp $(dot-target).cmd, @:) 267 + mv -f $(dot-target).tmp $(dot-target).cmd; 268 + 269 + else 270 + 271 + # Filter out exported kernel symbol names from the preprocessor output. 272 + # See also __KSYM_DEPS__ in include/linux/export.h. 273 + # We disable the depfile generation here, so as not to overwrite the existing 274 + # depfile while fixdep is parsing it. 275 + flags_nodeps = $(filter-out -Wp$(comma)-M%, $($(1))) 276 + ksym_dep_filter = \ 277 + case "$(1)" in \ 278 + cc_*_c|cpp_i_c) \ 279 + $(CPP) $(call flags_nodeps,c_flags) -D__KSYM_DEPS__ $< ;; \ 280 + as_*_S|cpp_s_S) \ 281 + $(CPP) $(call flags_nodeps,a_flags) -D__KSYM_DEPS__ $< ;; \ 282 + boot*|build*|*cpp_lds_S|dtc|host*|vdso*) : ;; \ 283 + *) echo "Don't know how to preprocess $(1)" >&2; false ;; \ 284 + esac | tr ";" "\n" | sed -rn 's/^.*=== __KSYM_(.*) ===.*$$/KSYM_\1/p' 285 + 286 + cmd_and_fixdep = \ 287 + $(echo-cmd) $(cmd_$(1)); \ 288 + $(ksym_dep_filter) | \ 289 + scripts/basic/fixdep -e $(depfile) $@ '$(make-cmd)' \ 290 + > $(dot-target).tmp; \ 291 + rm -f $(depfile); \ 292 + mv -f $(dot-target).tmp $(dot-target).cmd; 293 + 294 + endif 264 295 265 296 # Usage: $(call if_changed_rule,foo) 266 297 # Will check if $(cmd_foo) or any of the prerequisites changed, ··· 373 340 # and double quotes, backslashes and spaces in the filenames. 374 341 # 375 342 ############################################################################### 376 - # 377 - space_escape := %%%SPACE%%% 378 343 # 379 344 define config_filename 380 345 ifneq ($$(CONFIG_$(1)),"")
+22 -22
scripts/Makefile.build
··· 152 152 $(obj)/%.s: $(src)/%.c FORCE 153 153 $(call if_changed_dep,cc_s_c) 154 154 155 - quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@ 156 - cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $< 155 + quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@ 156 + cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $< 157 157 158 158 $(obj)/%.i: $(src)/%.c FORCE 159 - $(call if_changed_dep,cc_i_c) 159 + $(call if_changed_dep,cpp_i_c) 160 160 161 161 cmd_gensymtypes = \ 162 162 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ ··· 266 266 267 267 define rule_cc_o_c 268 268 $(call echo-cmd,checksrc) $(cmd_checksrc) \ 269 - $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ 269 + $(call cmd_and_fixdep,cc_o_c) \ 270 270 $(cmd_modversions) \ 271 - $(cmd_objtool) \ 272 - $(call echo-cmd,record_mcount) \ 273 - $(cmd_record_mcount) \ 274 - scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \ 275 - $(dot-target).tmp; \ 276 - rm -f $(depfile); \ 277 - mv -f $(dot-target).tmp $(dot-target).cmd 271 + $(cmd_objtool) \ 272 + $(call echo-cmd,record_mcount) $(cmd_record_mcount) 278 273 endef 279 274 280 275 define rule_as_o_S 281 - $(call echo-cmd,as_o_S) $(cmd_as_o_S); \ 282 - $(cmd_objtool) \ 283 - scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,as_o_S)' > \ 284 - $(dot-target).tmp; \ 285 - rm -f $(depfile); \ 286 - mv -f $(dot-target).tmp $(dot-target).cmd 276 + $(call cmd_and_fixdep,as_o_S) \ 277 + $(cmd_objtool) 287 278 endef 279 + 280 + # List module undefined symbols (or empty line if not enabled) 281 + ifdef CONFIG_TRIM_UNUSED_KSYMS 282 + cmd_undef_syms = $(NM) $@ | sed -n 's/^ \+U //p' | xargs echo 283 + else 284 + cmd_undef_syms = echo 285 + endif 288 286 289 287 # Built-in and composite module parts 290 288 $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_obj) FORCE ··· 294 296 $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_obj) FORCE 295 297 $(call cmd,force_checksrc) 296 298 $(call if_changed_rule,cc_o_c) 297 - @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod) 299 + @{ echo $(@:.o=.ko); echo $@; \ 300 + $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod) 298 301 299 302 quiet_cmd_cc_lst_c = MKLST $@ 300 303 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ ··· 313 314 $(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) 314 315 $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) 315 316 316 - quiet_cmd_as_s_S = CPP $(quiet_modtag) $@ 317 - cmd_as_s_S = $(CPP) $(a_flags) -o $@ $< 317 + quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@ 318 + cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $< 318 319 319 320 $(obj)/%.s: $(src)/%.S FORCE 320 - $(call if_changed_dep,as_s_S) 321 + $(call if_changed_dep,cpp_s_S) 321 322 322 323 quiet_cmd_as_o_S = AS $(quiet_modtag) $@ 323 324 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< ··· 425 426 426 427 $(multi-used-m): FORCE 427 428 $(call if_changed,link_multi-m) 428 - @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod) 429 + @{ echo $(@:.o=.ko); echo $(link_multi_deps); \ 430 + $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod) 429 431 $(call multi_depend, $(multi-used-m), .o, -objs -y -m) 430 432 431 433 targets += $(multi-used-y) $(multi-used-m)
+1
scripts/Makefile.extrawarn
··· 24 24 warning-1 += -Wold-style-definition 25 25 warning-1 += $(call cc-option, -Wmissing-include-dirs) 26 26 warning-1 += $(call cc-option, -Wunused-but-set-variable) 27 + warning-1 += $(call cc-option, -Wunused-const-variable) 27 28 warning-1 += $(call cc-disable-warning, missing-field-initializers) 28 29 warning-1 += $(call cc-disable-warning, sign-compare) 29 30
+4 -4
scripts/Makefile.lib
··· 96 96 # Note: Files that end up in two or more modules are compiled without the 97 97 # KBUILD_MODNAME definition. The reason is that any made-up name would 98 98 # differ in different configs. 99 - name-fix = $(subst $(comma),_,$(subst -,_,$1)) 100 - basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" 99 + name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote) 100 + basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) 101 101 modname_flags = $(if $(filter 1,$(words $(modname))),\ 102 - -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") 102 + -DKBUILD_MODNAME=$(call name-fix,$(modname))) 103 103 104 104 orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ 105 105 $(ccflags-y) $(CFLAGS_$(basetarget).o) ··· 162 162 163 163 c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 164 164 $(__c_flags) $(modkern_cflags) \ 165 - -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) 165 + $(basename_flags) $(modname_flags) 166 166 167 167 a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 168 168 $(__a_flags) $(modkern_aflags)
+101
scripts/adjust_autoksyms.sh
··· 1 + #!/bin/sh 2 + 3 + # Script to create/update include/generated/autoksyms.h and dependency files 4 + # 5 + # Copyright: (C) 2016 Linaro Limited 6 + # Created by: Nicolas Pitre, January 2016 7 + # 8 + # This program is free software; you can redistribute it and/or modify 9 + # it under the terms of the GNU General Public License version 2 as 10 + # published by the Free Software Foundation. 11 + 12 + # Create/update the include/generated/autoksyms.h file from the list 13 + # of all module's needed symbols as recorded on the third line of 14 + # .tmp_versions/*.mod files. 15 + # 16 + # For each symbol being added or removed, the corresponding dependency 17 + # file's timestamp is updated to force a rebuild of the affected source 18 + # file. All arguments passed to this script are assumed to be a command 19 + # to be exec'd to trigger a rebuild of those files. 20 + 21 + set -e 22 + 23 + cur_ksyms_file="include/generated/autoksyms.h" 24 + new_ksyms_file="include/generated/autoksyms.h.tmpnew" 25 + 26 + info() { 27 + if [ "$quiet" != "silent_" ]; then 28 + printf " %-7s %s\n" "$1" "$2" 29 + fi 30 + } 31 + 32 + info "CHK" "$cur_ksyms_file" 33 + 34 + # Use "make V=1" to debug this script. 35 + case "$KBUILD_VERBOSE" in 36 + *1*) 37 + set -x 38 + ;; 39 + esac 40 + 41 + # We need access to CONFIG_ symbols 42 + case "${KCONFIG_CONFIG}" in 43 + */*) 44 + . "${KCONFIG_CONFIG}" 45 + ;; 46 + *) 47 + # Force using a file from the current directory 48 + . "./${KCONFIG_CONFIG}" 49 + esac 50 + 51 + # In case it doesn't exist yet... 52 + if [ -e "$cur_ksyms_file" ]; then touch "$cur_ksyms_file"; fi 53 + 54 + # Generate a new ksym list file with symbols needed by the current 55 + # set of modules. 56 + cat > "$new_ksyms_file" << EOT 57 + /* 58 + * Automatically generated file; DO NOT EDIT. 59 + */ 60 + 61 + EOT 62 + sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u | 63 + while read sym; do 64 + if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then 65 + sym="${sym#_}" 66 + fi 67 + echo "#define __KSYM_${sym} 1" 68 + done >> "$new_ksyms_file" 69 + 70 + # Special case for modversions (see modpost.c) 71 + if [ -n "$CONFIG_MODVERSIONS" ]; then 72 + echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file" 73 + fi 74 + 75 + # Extract changes between old and new list and touch corresponding 76 + # dependency files. 77 + changed=$( 78 + count=0 79 + sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u | 80 + sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" | 81 + while read sympath; do 82 + if [ -z "$sympath" ]; then continue; fi 83 + depfile="include/config/ksym/${sympath}.h" 84 + mkdir -p "$(dirname "$depfile")" 85 + touch "$depfile" 86 + echo $((count += 1)) 87 + done | tail -1 ) 88 + changed=${changed:-0} 89 + 90 + if [ $changed -gt 0 ]; then 91 + # Replace the old list with tne new one 92 + old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true) 93 + new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true) 94 + info "KSYMS" "symbols: before=$old, after=$new, changed=$changed" 95 + info "UPD" "$cur_ksyms_file" 96 + mv -f "$new_ksyms_file" "$cur_ksyms_file" 97 + # Then trigger a rebuild of affected source files 98 + exec $@ 99 + else 100 + rm -f "$new_ksyms_file" 101 + fi
+46 -15
scripts/basic/fixdep.c
··· 120 120 #define INT_NFIG ntohl(0x4e464947) 121 121 #define INT_FIG_ ntohl(0x4649475f) 122 122 123 + int insert_extra_deps; 123 124 char *target; 124 125 char *depfile; 125 126 char *cmdline; 126 127 127 128 static void usage(void) 128 129 { 129 - fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); 130 + fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n"); 131 + fprintf(stderr, " -e insert extra dependencies given on stdin\n"); 130 132 exit(1); 131 133 } 132 134 ··· 138 136 static void print_cmdline(void) 139 137 { 140 138 printf("cmd_%s := %s\n\n", target, cmdline); 139 + } 140 + 141 + /* 142 + * Print out a dependency path from a symbol name 143 + */ 144 + static void print_config(const char *m, int slen) 145 + { 146 + int c, i; 147 + 148 + printf(" $(wildcard include/config/"); 149 + for (i = 0; i < slen; i++) { 150 + c = m[i]; 151 + if (c == '_') 152 + c = '/'; 153 + else 154 + c = tolower(c); 155 + putchar(c); 156 + } 157 + printf(".h) \\\n"); 158 + } 159 + 160 + static void do_extra_deps(void) 161 + { 162 + if (insert_extra_deps) { 163 + char buf[80]; 164 + while(fgets(buf, sizeof(buf), stdin)) { 165 + int len = strlen(buf); 166 + if (len < 2 || buf[len-1] != '\n') { 167 + fprintf(stderr, "fixdep: bad data on stdin\n"); 168 + exit(1); 169 + } 170 + print_config(buf, len-1); 171 + } 172 + } 141 173 } 142 174 143 175 struct item { ··· 233 197 static void use_config(const char *m, int slen) 234 198 { 235 199 unsigned int hash = strhash(m, slen); 236 - int c, i; 237 200 238 201 if (is_defined_config(m, slen, hash)) 239 202 return; 240 203 241 204 define_config(m, slen, hash); 242 - 243 - printf(" $(wildcard include/config/"); 244 - for (i = 0; i < slen; i++) { 245 - c = m[i]; 246 - if (c == '_') 247 - c = '/'; 248 - else 249 - c = tolower(c); 250 - putchar(c); 251 - } 252 - printf(".h) \\\n"); 205 + print_config(m, slen); 253 206 } 254 207 255 208 static void parse_config_file(const char *map, size_t len) ··· 275 250 } 276 251 } 277 252 278 - /* test is s ends in sub */ 253 + /* test if s ends in sub */ 279 254 static int strrcmp(const char *s, const char *sub) 280 255 { 281 256 int slen = strlen(s); ··· 358 333 359 334 /* Ignore certain dependencies */ 360 335 if (strrcmp(s, "include/generated/autoconf.h") && 336 + strrcmp(s, "include/generated/autoksyms.h") && 361 337 strrcmp(s, "arch/um/include/uml-config.h") && 362 338 strrcmp(s, "include/linux/kconfig.h") && 363 339 strrcmp(s, ".ver")) { ··· 403 377 fprintf(stderr, "fixdep: parse error; no targets found\n"); 404 378 exit(1); 405 379 } 380 + 381 + do_extra_deps(); 406 382 407 383 printf("\n%s: $(deps_%s)\n\n", target, target); 408 384 printf("$(deps_%s):\n", target); ··· 462 434 { 463 435 traps(); 464 436 465 - if (argc != 4) 437 + if (argc == 5 && !strcmp(argv[1], "-e")) { 438 + insert_extra_deps = 1; 439 + argv++; 440 + } else if (argc != 4) 466 441 usage(); 467 442 468 443 depfile = argv[1];
+3
scripts/genksyms/genksyms.c
··· 873 873 (double)nsyms / (double)HASH_BUCKETS); 874 874 } 875 875 876 + if (dumpfile) 877 + fclose(dumpfile); 878 + 876 879 return errors != 0; 877 880 }
+4 -4
tools/build/Makefile.build
··· 58 58 quiet_cmd_cc_o_c = CC $@ 59 59 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 60 60 61 - quiet_cmd_cc_i_c = CPP $@ 62 - cmd_cc_i_c = $(CC) $(c_flags) -E -o $@ $< 61 + quiet_cmd_cpp_i_c = CPP $@ 62 + cmd_cpp_i_c = $(CC) $(c_flags) -E -o $@ $< 63 63 64 64 quiet_cmd_cc_s_c = AS $@ 65 65 cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $< ··· 83 83 84 84 $(OUTPUT)%.i: %.c FORCE 85 85 $(call rule_mkdir) 86 - $(call if_changed_dep,cc_i_c) 86 + $(call if_changed_dep,cpp_i_c) 87 87 88 88 $(OUTPUT)%.s: %.S FORCE 89 89 $(call rule_mkdir) 90 - $(call if_changed_dep,cc_i_c) 90 + $(call if_changed_dep,cpp_i_c) 91 91 92 92 $(OUTPUT)%.s: %.c FORCE 93 93 $(call rule_mkdir)