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

Pull kbuild fixes from Michal Marek:
"Here are some regression fixes for kbuild:

- modversion support for exported asm symbols (Nick Piggin). The
affected architectures need separate patches adding
asm-prototypes.h.

- fix rebuilds of lib-ksyms.o (Nick Piggin)

- -fno-PIE builds (Sebastian Siewior and Borislav Petkov). This is
not a kernel regression, but one of the Debian gcc package.
Nevertheless, it's quite annoying, so I think it should go into
mainline and stable now"

* 'rc-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild:
kbuild: Steal gcc's pie from the very beginning
kbuild: be more careful about matching preprocessed asm ___EXPORT_SYMBOL
x86/kexec: add -fno-PIE
scripts/has-stack-protector: add -fno-PIE
kbuild: add -fno-PIE
kbuild: modversions for EXPORT_SYMBOL() for asm
kbuild: prevent lib-ksyms.o rebuilds

+80 -9
+3 -2
Makefile
··· 399 -fno-strict-aliasing -fno-common \ 400 -Werror-implicit-function-declaration \ 401 -Wno-format-security \ 402 - -std=gnu89 403 404 KBUILD_AFLAGS_KERNEL := 405 KBUILD_CFLAGS_KERNEL := 406 - KBUILD_AFLAGS := -D__ASSEMBLY__ 407 KBUILD_AFLAGS_MODULE := -DMODULE 408 KBUILD_CFLAGS_MODULE := -DMODULE 409 KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
··· 399 -fno-strict-aliasing -fno-common \ 400 -Werror-implicit-function-declaration \ 401 -Wno-format-security \ 402 + -std=gnu89 $(call cc-option,-fno-PIE) 403 + 404 405 KBUILD_AFLAGS_KERNEL := 406 KBUILD_CFLAGS_KERNEL := 407 + KBUILD_AFLAGS := -D__ASSEMBLY__ $(call cc-option,-fno-PIE) 408 KBUILD_AFLAGS_MODULE := -DMODULE 409 KBUILD_CFLAGS_MODULE := -DMODULE 410 KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
+1
arch/x86/purgatory/Makefile
··· 16 17 KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes -fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -MD -Os -mcmodel=large 18 KBUILD_CFLAGS += -m$(BITS) 19 20 $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE 21 $(call if_changed,ld)
··· 16 17 KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes -fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -MD -Os -mcmodel=large 18 KBUILD_CFLAGS += -m$(BITS) 19 + KBUILD_CFLAGS += $(call cc-option,-fno-PIE) 20 21 $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE 22 $(call if_changed,ld)
+75 -6
scripts/Makefile.build
··· 159 $(obj)/%.i: $(src)/%.c FORCE 160 $(call if_changed_dep,cpp_i_c) 161 162 - cmd_gensymtypes = \ 163 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ 164 $(GENKSYMS) $(if $(1), -T $(2)) \ 165 $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \ ··· 170 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ 171 cmd_cc_symtypes_c = \ 172 set -e; \ 173 - $(call cmd_gensymtypes,true,$@) >/dev/null; \ 174 test -s $@ || rm -f $@ 175 176 $(obj)/%.symtypes : $(src)/%.c FORCE ··· 199 # the actual value of the checksum generated by genksyms 200 201 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $< 202 - cmd_modversions = \ 203 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 204 - $(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 205 > $(@D)/.tmp_$(@F:.o=.ver); \ 206 \ 207 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ ··· 270 define rule_cc_o_c 271 $(call echo-cmd,checksrc) $(cmd_checksrc) \ 272 $(call cmd_and_fixdep,cc_o_c) \ 273 - $(cmd_modversions) \ 274 $(cmd_objtool) \ 275 $(call echo-cmd,record_mcount) $(cmd_record_mcount) 276 endef 277 278 define rule_as_o_S 279 $(call cmd_and_fixdep,as_o_S) \ 280 $(cmd_objtool) 281 endef 282 ··· 317 $(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) 318 $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) 319 320 quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@ 321 cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $< 322 ··· 357 $(call if_changed_dep,cpp_s_S) 358 359 quiet_cmd_as_o_S = AS $(quiet_modtag) $@ 360 - cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< 361 362 $(obj)/%.o: $(src)/%.S $(objtool_obj) FORCE 363 $(call if_changed_rule,as_o_S) ··· 496 497 $(obj)/lib-ksyms.o: $(lib-target) FORCE 498 $(call if_changed,export_list) 499 endif 500 501 #
··· 159 $(obj)/%.i: $(src)/%.c FORCE 160 $(call if_changed_dep,cpp_i_c) 161 162 + # These mirror gensymtypes_S and co below, keep them in synch. 163 + cmd_gensymtypes_c = \ 164 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ 165 $(GENKSYMS) $(if $(1), -T $(2)) \ 166 $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \ ··· 169 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ 170 cmd_cc_symtypes_c = \ 171 set -e; \ 172 + $(call cmd_gensymtypes_c,true,$@) >/dev/null; \ 173 test -s $@ || rm -f $@ 174 175 $(obj)/%.symtypes : $(src)/%.c FORCE ··· 198 # the actual value of the checksum generated by genksyms 199 200 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $< 201 + 202 + cmd_modversions_c = \ 203 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 204 + $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 205 > $(@D)/.tmp_$(@F:.o=.ver); \ 206 \ 207 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ ··· 268 define rule_cc_o_c 269 $(call echo-cmd,checksrc) $(cmd_checksrc) \ 270 $(call cmd_and_fixdep,cc_o_c) \ 271 + $(cmd_modversions_c) \ 272 $(cmd_objtool) \ 273 $(call echo-cmd,record_mcount) $(cmd_record_mcount) 274 endef 275 276 define rule_as_o_S 277 $(call cmd_and_fixdep,as_o_S) \ 278 + $(cmd_modversions_S) \ 279 $(cmd_objtool) 280 endef 281 ··· 314 $(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) 315 $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) 316 317 + # .S file exports must have their C prototypes defined in asm/asm-prototypes.h 318 + # or a file that it includes, in order to get versioned symbols. We build a 319 + # dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from 320 + # the .S file (with trailing ';'), and run genksyms on that, to extract vers. 321 + # 322 + # This is convoluted. The .S file must first be preprocessed to run guards and 323 + # expand names, then the resulting exports must be constructed into plain 324 + # EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed 325 + # to make the genksyms input. 326 + # 327 + # These mirror gensymtypes_c and co above, keep them in synch. 328 + cmd_gensymtypes_S = \ 329 + (echo "\#include <linux/kernel.h>" ; \ 330 + echo "\#include <asm/asm-prototypes.h>" ; \ 331 + $(CPP) $(a_flags) $< | \ 332 + grep "\<___EXPORT_SYMBOL\>" | \ 333 + sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ) | \ 334 + $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \ 335 + $(GENKSYMS) $(if $(1), -T $(2)) \ 336 + $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \ 337 + $(if $(KBUILD_PRESERVE),-p) \ 338 + -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null)) 339 + 340 + quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@ 341 + cmd_cc_symtypes_S = \ 342 + set -e; \ 343 + $(call cmd_gensymtypes_S,true,$@) >/dev/null; \ 344 + test -s $@ || rm -f $@ 345 + 346 + $(obj)/%.symtypes : $(src)/%.S FORCE 347 + $(call cmd,cc_symtypes_S) 348 + 349 + 350 quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@ 351 cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $< 352 ··· 321 $(call if_changed_dep,cpp_s_S) 322 323 quiet_cmd_as_o_S = AS $(quiet_modtag) $@ 324 + 325 + ifndef CONFIG_MODVERSIONS 326 + cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< 327 + 328 + else 329 + 330 + ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h) 331 + 332 + ifeq ($(ASM_PROTOTYPES),) 333 + cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< 334 + 335 + else 336 + 337 + # versioning matches the C process described above, with difference that 338 + # we parse asm-prototypes.h C header to get function definitions. 339 + 340 + cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $< 341 + 342 + cmd_modversions_S = \ 343 + if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 344 + $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 345 + > $(@D)/.tmp_$(@F:.o=.ver); \ 346 + \ 347 + $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 348 + -T $(@D)/.tmp_$(@F:.o=.ver); \ 349 + rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ 350 + else \ 351 + mv -f $(@D)/.tmp_$(@F) $@; \ 352 + fi; 353 + endif 354 + endif 355 356 $(obj)/%.o: $(src)/%.S $(objtool_obj) FORCE 357 $(call if_changed_rule,as_o_S) ··· 430 431 $(obj)/lib-ksyms.o: $(lib-target) FORCE 432 $(call if_changed,export_list) 433 + 434 + targets += $(obj)/lib-ksyms.o 435 + 436 endif 437 438 #
+1 -1
scripts/gcc-x86_64-has-stack-protector.sh
··· 1 #!/bin/sh 2 3 - echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -O0 -mcmodel=kernel -fstack-protector - -o - 2> /dev/null | grep -q "%gs" 4 if [ "$?" -eq "0" ] ; then 5 echo y 6 else
··· 1 #!/bin/sh 2 3 + echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -O0 -mcmodel=kernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs" 4 if [ "$?" -eq "0" ] ; then 5 echo y 6 else