mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	kbuild: modversions for EXPORT_SYMBOL() for asm
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 <npiggin@gmail.com> Signed-off-by: Michal Marek <mmarek@suse.com>
This commit is contained in:
		
							parent
							
								
									989cea5c14
								
							
						
					
					
						commit
						4efca4ed05
					
				
					 1 changed files with 72 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -159,7 +159,8 @@ cmd_cpp_i_c       = $(CPP) $(c_flags) -o $@ $<
 | 
			
		|||
$(obj)/%.i: $(src)/%.c FORCE
 | 
			
		||||
	$(call if_changed_dep,cpp_i_c)
 | 
			
		||||
 | 
			
		||||
cmd_gensymtypes =                                                           \
 | 
			
		||||
# These mirror gensymtypes_S and co below, keep them in synch.
 | 
			
		||||
cmd_gensymtypes_c =                                                         \
 | 
			
		||||
    $(CPP) -D__GENKSYMS__ $(c_flags) $< |                                   \
 | 
			
		||||
    $(GENKSYMS) $(if $(1), -T $(2))                                         \
 | 
			
		||||
     $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX))             \
 | 
			
		||||
| 
						 | 
				
			
			@ -169,7 +170,7 @@ cmd_gensymtypes =                                                           \
 | 
			
		|||
quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
 | 
			
		||||
cmd_cc_symtypes_c =                                                         \
 | 
			
		||||
    set -e;                                                                 \
 | 
			
		||||
    $(call cmd_gensymtypes,true,$@) >/dev/null;                             \
 | 
			
		||||
    $(call cmd_gensymtypes_c,true,$@) >/dev/null;                           \
 | 
			
		||||
    test -s $@ || rm -f $@
 | 
			
		||||
 | 
			
		||||
$(obj)/%.symtypes : $(src)/%.c FORCE
 | 
			
		||||
| 
						 | 
				
			
			@ -198,9 +199,10 @@ else
 | 
			
		|||
#   the actual value of the checksum generated by genksyms
 | 
			
		||||
 | 
			
		||||
cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
 | 
			
		||||
cmd_modversions =								\
 | 
			
		||||
 | 
			
		||||
cmd_modversions_c =								\
 | 
			
		||||
	if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then		\
 | 
			
		||||
		$(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))	\
 | 
			
		||||
		$(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))	\
 | 
			
		||||
		    > $(@D)/.tmp_$(@F:.o=.ver);					\
 | 
			
		||||
										\
 | 
			
		||||
		$(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) 			\
 | 
			
		||||
| 
						 | 
				
			
			@ -268,13 +270,14 @@ endif # CONFIG_STACK_VALIDATION
 | 
			
		|||
define rule_cc_o_c
 | 
			
		||||
	$(call echo-cmd,checksrc) $(cmd_checksrc)			  \
 | 
			
		||||
	$(call cmd_and_fixdep,cc_o_c)					  \
 | 
			
		||||
	$(cmd_modversions)						  \
 | 
			
		||||
	$(cmd_modversions_c)						  \
 | 
			
		||||
	$(cmd_objtool)						          \
 | 
			
		||||
	$(call echo-cmd,record_mcount) $(cmd_record_mcount)
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
define rule_as_o_S
 | 
			
		||||
	$(call cmd_and_fixdep,as_o_S)					  \
 | 
			
		||||
	$(cmd_modversions_S)						  \
 | 
			
		||||
	$(cmd_objtool)
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -314,6 +317,39 @@ modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)
 | 
			
		|||
$(real-objs-m)      : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
 | 
			
		||||
$(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
 | 
			
		||||
 | 
			
		||||
# .S file exports must have their C prototypes defined in asm/asm-prototypes.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 from
 | 
			
		||||
# the .S file (with trailing ';'), and run genksyms on that, to extract vers.
 | 
			
		||||
#
 | 
			
		||||
# 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 preprocessed
 | 
			
		||||
# to make the genksyms input.
 | 
			
		||||
#
 | 
			
		||||
# These mirror gensymtypes_c and co above, keep them in synch.
 | 
			
		||||
cmd_gensymtypes_S =                                                         \
 | 
			
		||||
    (echo "\#include <linux/kernel.h>" ;                                    \
 | 
			
		||||
     echo "\#include <asm/asm-prototypes.h>" ;                              \
 | 
			
		||||
    $(CPP) $(a_flags) $< |                                                  \
 | 
			
		||||
     grep ^___EXPORT_SYMBOL |                                               \
 | 
			
		||||
     sed 's/___EXPORT_SYMBOL \([a-zA-Z0-9_]*\),.*/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=.symref) /dev/null))
 | 
			
		||||
 | 
			
		||||
quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
 | 
			
		||||
cmd_cc_symtypes_S =                                                         \
 | 
			
		||||
    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_cpp_s_S = CPP $(quiet_modtag) $@
 | 
			
		||||
cmd_cpp_s_S       = $(CPP) $(a_flags) -o $@ $<
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -321,7 +357,37 @@ $(obj)/%.s: $(src)/%.S FORCE
 | 
			
		|||
	$(call if_changed_dep,cpp_s_S)
 | 
			
		||||
 | 
			
		||||
quiet_cmd_as_o_S = AS $(quiet_modtag)  $@
 | 
			
		||||
cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
 | 
			
		||||
 | 
			
		||||
ifndef CONFIG_MODVERSIONS
 | 
			
		||||
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
 | 
			
		||||
 | 
			
		||||
else
 | 
			
		||||
 | 
			
		||||
ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
 | 
			
		||||
 | 
			
		||||
ifeq ($(ASM_PROTOTYPES),)
 | 
			
		||||
cmd_as_o_S = $(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 = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $<
 | 
			
		||||
 | 
			
		||||
cmd_modversions_S =								\
 | 
			
		||||
	if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then		\
 | 
			
		||||
		$(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))	\
 | 
			
		||||
		    > $(@D)/.tmp_$(@F:.o=.ver);					\
 | 
			
		||||
										\
 | 
			
		||||
		$(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) 			\
 | 
			
		||||
			-T $(@D)/.tmp_$(@F:.o=.ver);				\
 | 
			
		||||
		rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver);		\
 | 
			
		||||
	else									\
 | 
			
		||||
		mv -f $(@D)/.tmp_$(@F) $@;					\
 | 
			
		||||
	fi;
 | 
			
		||||
endif
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
$(obj)/%.o: $(src)/%.S $(objtool_obj) FORCE
 | 
			
		||||
	$(call if_changed_rule,as_o_S)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue