From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam02on0137.outbound.protection.outlook.com ([104.47.36.137]:63678 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032198AbeCAPaf (ORCPT ); Thu, 1 Mar 2018 10:30:35 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Nicholas Piggin , Michal Marek , Sasha Levin Subject: [added to the 4.1 stable tree] kbuild: modversions for EXPORT_SYMBOL() for asm Date: Thu, 1 Mar 2018 15:24:32 +0000 Message-ID: <20180301152116.1486-199-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Nicholas Piggin This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 4efca4ed05cbdfd13ec3e8cb623fb77d6e4ab187 ] Allow architectures to create asm/asm-prototypes.h file that provides C prototypes for exported asm functions, which enables proper CRC versions to be generated for them. Signed-off-by: Nicholas Piggin Signed-off-by: Michal Marek Signed-off-by: Sasha Levin --- scripts/Makefile.build | 87 ++++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 80 insertions(+), 7 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 01df30af4d4a..18209917e379 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -158,7 +158,8 @@ cmd_cc_i_c =3D $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(src)/%.c FORCE $(call if_changed_dep,cc_i_c) =20 -cmd_gensymtypes =3D = \ +# These mirror gensymtypes_S and co below, keep them in synch. +cmd_gensymtypes_c =3D = \ $(CPP) -D__GENKSYMS__ $(c_flags) $< | = \ $(GENKSYMS) $(if $(1), -T $(2)) = \ $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) = \ @@ -168,7 +169,7 @@ cmd_gensymtypes =3D = \ quiet_cmd_cc_symtypes_c =3D SYM $(quiet_modtag) $@ cmd_cc_symtypes_c =3D = \ set -e; = \ - $(call cmd_gensymtypes,true,$@) >/dev/null; = \ + $(call cmd_gensymtypes_c,true,$@) >/dev/null; = \ test -s $@ || rm -f $@ =20 $(obj)/%.symtypes : $(src)/%.c FORCE @@ -197,9 +198,10 @@ else # the actual value of the checksum generated by genksyms =20 cmd_cc_o_c =3D $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $< -cmd_modversions =3D \ + +cmd_modversions_c =3D \ if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ - $(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=3D.symtypes)) \ + $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=3D.symtypes)) \ > $(@D)/.tmp_$(@F:.o=3D.ver); \ \ $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ @@ -244,7 +246,7 @@ endif define rule_cc_o_c $(call echo-cmd,checksrc) $(cmd_checksrc) \ $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ - $(cmd_modversions) \ + $(cmd_modversions_c) \ $(call echo-cmd,record_mcount) \ $(cmd_record_mcount) \ scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \ @@ -253,6 +255,15 @@ define rule_cc_o_c mv -f $(dot-target).tmp $(dot-target).cmd endef =20 +define rule_as_o_S + $(call echo-cmd,as_o_S) $(cmd_as_o_S); \ + scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,as_o_S)' > \ + $(dot-target).tmp; \ + $(cmd_modversions_S) \ + rm -f $(depfile); \ + mv -f $(dot-target).tmp $(dot-target).cmd +endef + # Built-in and composite module parts $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE $(call cmd,force_checksrc) @@ -281,6 +292,38 @@ modkern_aflags :=3D $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_K= ERNEL) $(real-objs-m) : modkern_aflags :=3D $(KBUILD_AFLAGS_MODULE) $(AFLAGS= _MODULE) $(real-objs-m:.o=3D.s): modkern_aflags :=3D $(KBUILD_AFLAGS_MODULE) $(AFLA= GS_MODULE) =20 +# .S file exports must have their C prototypes defined in asm/asm-prototyp= es.h +# or a file that it includes, in order to get versioned symbols. We build = a +# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines fr= om +# the .S file (with trailing ';'), and run genksyms on that, to extract ve= rs. +# +# This is convoluted. The .S file must first be preprocessed to run guards= and +# expand names, then the resulting exports must be constructed into plain +# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preproce= ssed +# to make the genksyms input. +# +# These mirror gensymtypes_c and co above, keep them in synch. +cmd_gensymtypes_S =3D = \ + (echo "\#include " ; = \ + echo "\#include " ; = \ + $(CPP) $(a_flags) $< | = \ + grep "\<___EXPORT_SYMBOL\>" | = \ + sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.= */EXPORT_SYMBOL(\1);/' ) | \ + $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | = \ + $(GENKSYMS) $(if $(1), -T $(2)) = \ + $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) = \ + $(if $(KBUILD_PRESERVE),-p) = \ + -r $(firstword $(wildcard $(2:.symtypes=3D.symref) /dev/null)) + +quiet_cmd_cc_symtypes_S =3D SYM $(quiet_modtag) $@ +cmd_cc_symtypes_S =3D = \ + set -e; = \ + $(call cmd_gensymtypes_S,true,$@) >/dev/null; = \ + test -s $@ || rm -f $@ + +$(obj)/%.symtypes : $(src)/%.S FORCE + $(call cmd,cc_symtypes_S) + quiet_cmd_as_s_S =3D CPP $(quiet_modtag) $@ cmd_as_s_S =3D $(CPP) $(a_flags) -o $@ $< =20 @@ -288,10 +331,40 @@ $(obj)/%.s: $(src)/%.S FORCE $(call if_changed_dep,as_s_S) =20 quiet_cmd_as_o_S =3D AS $(quiet_modtag) $@ -cmd_as_o_S =3D $(CC) $(a_flags) -c -o $@ $< + +ifndef CONFIG_MODVERSIONS +cmd_as_o_S =3D $(CC) $(a_flags) -c -o $@ $< + +else + +ASM_PROTOTYPES :=3D $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-= prototypes.h) + +ifeq ($(ASM_PROTOTYPES),) +cmd_as_o_S =3D $(CC) $(a_flags) -c -o $@ $< + +else + +# versioning matches the C process described above, with difference that +# we parse asm-prototypes.h C header to get function definitions. + +cmd_as_o_S =3D $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $< + +cmd_modversions_S =3D \ + if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ + $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=3D.symtypes)) \ + > $(@D)/.tmp_$(@F:.o=3D.ver); \ + \ + $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ + -T $(@D)/.tmp_$(@F:.o=3D.ver); \ + rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=3D.ver); \ + else \ + mv -f $(@D)/.tmp_$(@F) $@; \ + fi; +endif +endif =20 $(obj)/%.o: $(src)/%.S FORCE - $(call if_changed_dep,as_o_S) + $(call if_changed_rule,as_o_S) =20 targets +=3D $(real-objs-y) $(real-objs-m) $(lib-y) targets +=3D $(extra-y) $(MAKECMDGOALS) $(always) --=20 2.14.1