History

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.

Nicholas Piggin committed 10 years ago

Commit 4efca4e1 parent 989cea51 file · +72 −6Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/Makefile.build+72−6
@@ -159,7 +159,8 @@ cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $< · 158 unmodified lines
159159 $(obj)/%.i: $(src)/%.c FORCE
160160 $(call if_changed_dep,cpp_i_c)
161161
162−cmd_gensymtypes = \
162+# These mirror gensymtypes_S and co below, keep them in synch.
163+cmd_gensymtypes_c = \
163164 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \
164165 $(GENKSYMS) $(if $(1), -T $(2)) \
165166 $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \
@@ -169,7 +170,7 @@ cmd_gensymtypes = \ · 3 unmodified lines
169170 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
170171 cmd_cc_symtypes_c = \
171172 set -e; \
172− $(call cmd_gensymtypes,true,$@) >/dev/null; \
173+ $(call cmd_gensymtypes_c,true,$@) >/dev/null; \
173174 test -s $@ || rm -f $@
174175
175176 $(obj)/%.symtypes : $(src)/%.c FORCE
@@ -198,9 +199,10 @@ else · 22 unmodified lines
198199 # the actual value of the checksum generated by genksyms
199200
200201 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
201−cmd_modversions = \
202+
203+cmd_modversions_c = \
202204 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
203− $(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
205+ $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
204206 > $(@D)/.tmp_$(@F:.o=.ver); \
205207 \
206208 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
@@ -268,13 +270,14 @@ endif # CONFIG_STACK_VALIDATION · 61 unmodified lines
268270 define rule_cc_o_c
269271 $(call echo-cmd,checksrc) $(cmd_checksrc) \
270272 $(call cmd_and_fixdep,cc_o_c) \
271− $(cmd_modversions) \
273+ $(cmd_modversions_c) \
272274 $(cmd_objtool) \
273275 $(call echo-cmd,record_mcount) $(cmd_record_mcount)
274276 endef
275277
276278 define rule_as_o_S
277279 $(call cmd_and_fixdep,as_o_S) \
280+ $(cmd_modversions_S) \
278281 $(cmd_objtool)
279282 endef
280283
@@ -314,6 +317,39 @@ modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) · 33 unmodified lines
314317 $(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
315318 $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
316319
320+# .S file exports must have their C prototypes defined in asm/asm-prototypes.h
321+# or a file that it includes, in order to get versioned symbols. We build a
322+# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
323+# the .S file (with trailing ';'), and run genksyms on that, to extract vers.
324+#
325+# This is convoluted. The .S file must first be preprocessed to run guards and
326+# expand names, then the resulting exports must be constructed into plain
327+# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
328+# to make the genksyms input.
329+#
330+# These mirror gensymtypes_c and co above, keep them in synch.
331+cmd_gensymtypes_S = \
332+ (echo "\#include <linux/kernel.h>" ; \
333+ echo "\#include <asm/asm-prototypes.h>" ; \
334+ $(CPP) $(a_flags) $< | \
335+ grep ^___EXPORT_SYMBOL | \
336+ sed 's/___EXPORT_SYMBOL \([a-zA-Z0-9_]*\),.*/EXPORT_SYMBOL(\1);/' ) | \
337+ $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \
338+ $(GENKSYMS) $(if $(1), -T $(2)) \
339+ $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \
340+ $(if $(KBUILD_PRESERVE),-p) \
341+ -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
342+
343+quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
344+cmd_cc_symtypes_S = \
345+ set -e; \
346+ $(call cmd_gensymtypes_S,true,$@) >/dev/null; \
347+ test -s $@ || rm -f $@
348+
349+$(obj)/%.symtypes : $(src)/%.S FORCE
350+ $(call cmd,cc_symtypes_S)
351+
352+
317353 quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
318354 cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
319355
@@ -321,7 +357,37 @@ $(obj)/%.s: $(src)/%.S FORCE · 1 unmodified line
321357 $(call if_changed_dep,cpp_s_S)
322358
323359 quiet_cmd_as_o_S = AS $(quiet_modtag) $@
324−cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
360+
361+ifndef CONFIG_MODVERSIONS
362+cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
363+
364+else
365+
366+ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
367+
368+ifeq ($(ASM_PROTOTYPES),)
369+cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
370+
371+else
372+
373+# versioning matches the C process described above, with difference that
374+# we parse asm-prototypes.h C header to get function definitions.
375+
376+cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $<
377+
378+cmd_modversions_S = \
379+ if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
380+ $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
381+ > $(@D)/.tmp_$(@F:.o=.ver); \
382+ \
383+ $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
384+ -T $(@D)/.tmp_$(@F:.o=.ver); \
385+ rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
386+ else \
387+ mv -f $(@D)/.tmp_$(@F) $@; \
388+ fi;
389+endif
390+endif
325391
326392 $(obj)/%.o: $(src)/%.S $(objtool_obj) FORCE
327393 $(call if_changed_rule,as_o_S)