summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.build128
-rw-r--r--scripts/Makefile.lib17
-rw-r--r--scripts/Makefile.modver133
-rw-r--r--scripts/per-cpu-check.awk2
4 files changed, 167 insertions, 113 deletions
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index f5886c69a196..b655c60afeee 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -45,11 +45,67 @@ O_TARGET := $(obj)/built-in.o
endif
endif
+ifdef CONFIG_MODVERSIONS
+modules := $(obj-m)
+touch-module = @mkdir -p $(MODVERDIR)/$(@D); touch $(MODVERDIR)/$(@:.o=.ko)
+else
+modules := $(obj-m:.o=.ko)
+endif
+
__build: $(if $(KBUILD_BUILTIN),$(O_TARGET) $(L_TARGET) $(EXTRA_TARGETS)) \
- $(if $(KBUILD_MODULES),$(obj-m:.o=.ko)) \
+ $(if $(KBUILD_MODULES),$(modules)) \
$(subdir-ym) $(build-targets)
@:
+# Module versioning
+# ---------------------------------------------------------------------------
+
+ifdef CONFIG_MODVERSIONS
+
+# $(call if_changed_rule,vcc_o_c) does essentially the same as the
+# normal $(call if_changed_dep,cc_o_c), i.e. compile an object file
+# from a C file, keeping track of the command line and dependencies.
+#
+# However, actually it does:
+# o compile a .tmp_<file>.o from <file>.c
+# o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
+# not export symbols, we just rename .tmp_<file>.o to <file>.o and
+# are done.
+# o otherwise, we calculate symbol versions using the good old
+# genksyms on the preprocessed source and postprocess them in a way
+# that they are usable as a linker script
+# o generate <file>.o from .tmp_<file>.o using the linker to
+# replace the unresolved symbols __crc_exported_symbol with
+# the actual value of the checksum generated by genksyms
+
+quiet_cmd_vcc_o_c = CC $(quiet_modtag) $@
+cmd_vcc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
+
+define rule_vcc_o_c
+ $(if $($(quiet)cmd_vcc_o_c),echo ' $($(quiet)cmd_vcc_o_c)';) \
+ $(cmd_vcc_o_c); \
+ \
+ if ! $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
+ mv $(@D)/.tmp_$(@F) $@; \
+ else \
+ $(CPP) -D__GENKSYMS__ $(c_flags) $< \
+ | $(GENKSYMS) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) \
+ | grep __ver \
+ | sed 's/\#define __ver_\([^ ]*\)[ ]*\([^ ]*\)/__crc_\1 = 0x\2 ;/g' \
+ > $(@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); \
+ fi;
+ \
+ scripts/fixdep $(depfile) $@ '$(cmd_vcc_o_c)' > $(@D)/.$(@F).tmp; \
+ rm -f $(depfile); \
+ mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
+endef
+
+endif
+
# Compile C sources (.c)
# ---------------------------------------------------------------------------
@@ -69,11 +125,6 @@ $(real-objs-m:.o=.lst): quiet_modtag := [M]
$(obj-m) : quiet_modtag := [M]
-$(export-objs) : export_flags := $(EXPORT_FLAGS)
-$(export-objs:.o=.i) : export_flags := $(EXPORT_FLAGS)
-$(export-objs:.o=.s) : export_flags := $(EXPORT_FLAGS)
-$(export-objs:.o=.lst): export_flags := $(EXPORT_FLAGS)
-
# Default for not multi-part modules
modname = $(*F)
@@ -102,7 +153,20 @@ quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
%.o: %.c FORCE
+ifdef CONFIG_MODVERSIONS
+ $(call if_changed_rule,vcc_o_c)
+else
$(call if_changed_dep,cc_o_c)
+endif
+
+# For modversioning, we need to special case single-part modules
+# to mark them in $(MODVERDIR)
+
+ifdef CONFIG_MODVERSIONS
+$(single-used-m): %.o: %.c FORCE
+ $(touch-module)
+ $(call if_changed_rule,vcc_o_c)
+endif
quiet_cmd_cc_lst_c = MKLST $@
cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
@@ -147,7 +211,7 @@ ifdef O_TARGET
quiet_cmd_link_o_target = LD $@
# If the list of objects to link is empty, just create an empty O_TARGET
cmd_link_o_target = $(if $(strip $(obj-y)),\
- $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^),\
+ $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
rm -f $@; $(AR) rcs $@)
$(O_TARGET): $(obj-y) FORCE
@@ -172,19 +236,20 @@ endif
#
# Rule to link composite objects
#
+# Composite objects are specified in kbuild makefile as follows:
+# <composite-object>-objs := <list of .o files>
+# or
+# <composite-object>-y := <list of .o files>
+link_multi_deps = \
+$(filter $(addprefix $(obj)/, \
+$($(subst $(obj)/,,$(@:.o=-objs))) \
+$($(subst $(obj)/,,$(@:.o=-y)))), $^)
+
quiet_cmd_link_multi-y = LD $@
-cmd_link_multi-y = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(addprefix $(obj)/,$($(subst $(obj)/,,$(@:.o=-objs))) $($(subst $(obj)/,,$(@:.o=-y)))),$^)
+cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps)
quiet_cmd_link_multi-m = LD [M] $@
-cmd_link_multi-m = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_MODULE) -o $@ $(filter $(addprefix $(obj)/,$($(subst $(obj)/,,$(@:.ko=-objs))) $($(subst $(obj)/,,$(@:.ko=-y)))),$^) init/vermagic.o
-
-quiet_cmd_link_single-m = LD [M] $@
-cmd_link_single-m = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_MODULE) -o $@ $< init/vermagic.o
-
-# Don't rebuilt vermagic.o unless we actually are in the init/ dir
-ifneq ($(obj),init)
-init/vermagic.o: ;
-endif
+cmd_link_multi-m = $(LD) $(ld_flags) $(LDFLAGS_MODULE) -o $@ $(link_multi_deps)
# We would rather have a list of rules like
# foo.o: $(foo-objs)
@@ -193,13 +258,34 @@ endif
$(multi-used-y) : %.o: $(multi-objs-y) FORCE
$(call if_changed,link_multi-y)
-$(multi-used-m:.o=.ko) : %.ko: $(multi-objs-m) init/vermagic.o FORCE
+$(multi-used-m) : %.o: $(multi-objs-m) FORCE
+ $(touch-module)
$(call if_changed,link_multi-m)
-$(single-used-m:.o=.ko) : %.ko: %.o init/vermagic.o FORCE
- $(call if_changed,link_single-m)
+targets += $(multi-used-y) $(multi-used-m)
+
+#
+# Rule to link modules ( .o -> .ko )
+#
+
+# With CONFIG_MODVERSIONS, generation of the final .ko is handled
+# by scripts/Makefile.modver
+ifndef CONFIG_MODVERSIONS
+
+quiet_cmd_link_module = LD [M] $@
+cmd_link_module = $(LD) $(ld_flags) $(LDFLAGS_MODULE) -o $@ $< init/vermagic.o
-targets += $(multi-used-y) $(multi-used-m:.o=.ko) $(single-used-m:.o=.ko)
+# Don't rebuilt vermagic.o unless we actually are in the init/ dir
+ifneq ($(obj),init)
+init/vermagic.o: ;
+endif
+
+$(single-used-m:.o=.ko) $(multi-used-m:.o=.ko): %.ko: %.o init/vermagic.o FORCE
+ $(call if_changed,link_module)
+
+targets += $(single-used-m:.o=.ko) $(multi-used-m:.o=.ko)
+
+endif
# Compile programs on the host
# ===========================================================================
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index bc1d58cb93c1..96eef1a89ebc 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -34,14 +34,9 @@ obj-m := $(filter-out %/, $(obj-m))
subdir-ym := $(sort $(subdir-y) $(subdir-m))
-# export.o is never a composite object, since $(export-objs) has a
-# fixed meaning (== objects which EXPORT_SYMBOL())
-__obj-y = $(filter-out export.o,$(obj-y))
-__obj-m = $(filter-out export.o,$(obj-m))
-
# if $(foo-objs) exists, foo.o is a composite object
-multi-used-y := $(sort $(foreach m,$(__obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
-multi-used-m := $(sort $(foreach m,$(__obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
+multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
+multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
multi-used := $(multi-used-y) $(multi-used-m)
single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
@@ -59,9 +54,6 @@ subdir-obj-y := $(foreach o,$(obj-y),$(if $(filter-out $(o),$(notdir $(o))),$(o)
real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(EXTRA_TARGETS)
real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
-# Only build module versions for files which are selected to be built
-export-objs := $(filter $(export-objs),$(real-objs-y) $(real-objs-m))
-
# C code
# Executables compiled from a single .c file
host-csingle := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m)))
@@ -96,7 +88,6 @@ EXTRA_TARGETS := $(addprefix $(obj)/,$(EXTRA_TARGETS))
build-targets := $(addprefix $(obj)/,$(build-targets))
obj-y := $(addprefix $(obj)/,$(obj-y))
obj-m := $(addprefix $(obj)/,$(obj-m))
-export-objs := $(addprefix $(obj)/,$(export-objs))
subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y))
real-objs-y := $(addprefix $(obj)/,$(real-objs-y))
real-objs-m := $(addprefix $(obj)/,$(real-objs-m))
@@ -130,13 +121,14 @@ basename_flags = -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F)))
modname_flags = $(if $(filter 1,$(words $(modname))),-DKBUILD_MODNAME=$(subst $(comma),_,$(subst -,_,$(modname))))
c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
$(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
- $(basename_flags) $(modname_flags) $(export_flags)
+ $(basename_flags) $(modname_flags)
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS)\
$(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
hostc_flags = -Wp,-MD,$(depfile) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS)\
$(HOSTCFLAGS_$(*F).o)
hostcxx_flags = -Wp,-MD,$(depfile) $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS)\
$(HOSTCXXFLAGS_$(*F).o)
+ld_flags = $(LDFLAGS) $(EXTRA_LDFLAGS)
# Finds the multi-part object the current object will be linked into
modname-multi = $(sort $(foreach m,$(multi-used),\
@@ -217,7 +209,6 @@ if_changed_rule = $(if $(strip $? \
$(filter-out $(cmd_$(1)),$(cmd_$@))\
$(filter-out $(cmd_$@),$(cmd_$(1)))),\
@set -e; \
- mkdir -p $(dir $@); \
$(rule_$(1)))
# If quiet is set, only print short version of command
diff --git a/scripts/Makefile.modver b/scripts/Makefile.modver
index 6f9c56dd32a8..95c9a772eda4 100644
--- a/scripts/Makefile.modver
+++ b/scripts/Makefile.modver
@@ -2,105 +2,82 @@
# Module versions
# ===========================================================================
-src := $(obj)
+.PHONY: __modversions
+__modversions:
-MODVERDIR := include/linux/modules
+include scripts/Makefile.lib
-.PHONY: modver
-modver:
+#
-include .config
+modules := $(patsubst ./%,%,$(shell cd $(MODVERDIR); find . -name \*.ko))
-include $(obj)/Makefile
+__modversions: $(modules)
+ @:
-include scripts/Makefile.lib
+# The final module link
-# ===========================================================================
+quiet_cmd_ld_ko_o = LD [M] $@
+ cmd_ld_ko_o = $(LD) $(LDFLAGS) $(LDFLAGS_MODULE) -o $@ \
+ $(filter-out FORCE,$^)
-ifeq ($(strip $(export-objs)),)
+init/vermagic.o: ;
-# If we don't export any symbols in this dir, just descend
-# ---------------------------------------------------------------------------
+$(modules): %.ko :%.o %.ver.o init/vermagic.o FORCE
+ $(call if_changed,ld_ko_o)
-modver: $(subdir-ym)
- @:
+targets += $(modules)
-else
+# Compile version info for unresolved symbols
-# This sets version suffixes on exported symbols
-# ---------------------------------------------------------------------------
+quiet_cmd_cc_o_c = CC $@
+ cmd_cc_o_c = $(CC) $(CFLAGS) -c -o $@ $<
-#
-# Added the SMP separator to stop module accidents between uniprocessor
-# and SMP Intel boxes - AC - from bits by Michael Chastain
-#
+$(modules:.ko=.ver.o): %.ver.o: %.ver.c FORCE
+ $(call if_changed,cc_o_c)
-ifdef CONFIG_SMP
- genksyms_smp_prefix := -p smp_
-else
- genksyms_smp_prefix :=
-endif
+targets += $(modules:.ko=.ver.o)
+
+# Generate C source with version info for unresolved symbols
-# Don't include modversions.h, we're just about to generate it here.
-
-CFLAGS_MODULE := $(filter-out -include include/linux/modversions.h,$(CFLAGS_MODULE))
-
-$(addprefix $(MODVERDIR)/,$(real-objs-y:.o=.ver)): modkern_cflags := $(CFLAGS_KERNEL)
-$(addprefix $(MODVERDIR)/,$(real-objs-m:.o=.ver)): modkern_cflags := $(CFLAGS_MODULE)
-$(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver)): export_flags := -D__GENKSYMS__
-# Default for not multi-part modules
-modname = $(*F)
-
-$(addprefix $(MODVERDIR)/,$(multi-objs:.o=.ver)) : modname = $(modname-multi)
-
-# Our objects only depend on modversions.h, not on the individual .ver
-# files (fix-dep filters them), so touch modversions.h if any of the .ver
-# files changes
-
-quiet_cmd_cc_ver_c = MKVER include/linux/modules/$*.ver
-cmd_cc_ver_c = $(CPP) $(c_flags) $< | $(GENKSYMS) $(genksyms_smp_prefix) \
- -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp
-
-# Okay, let's explain what's happening in rule_make_cc_ver_c:
-# o echo the command
-# o execute the command
-# o If the $(CPP) fails, we won't notice because it's output is piped
-# to $(GENKSYMS) which does not fail. We recognize this case by
-# looking if the generated $(depfile) exists, though.
-# o If the .ver file changed, touch modversions.h, which is our marker
-# of any changed .ver files.
-# o Move command line and deps into their normal .*.cmd place.
-
-define rule_cc_ver_c
- $(if $($(quiet)cmd_cc_ver_c),echo ' $($(quiet)cmd_cc_ver_c)';) \
- $(cmd_cc_ver_c); \
- if [ ! -r $(depfile) ]; then exit 1; fi; \
- scripts/fixdep $(depfile) $@ '$(cmd_cc_ver_c)' > $(@D)/.$(@F).tmp; \
- rm -f $(depfile); \
- if [ ! -r $@ ] || cmp -s $@ $@.tmp; then \
- touch include/linux/modversions.h; \
- fi; \
- mv -f $@.tmp $@
- mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
+define rule_mkver_o_c
+ echo ' MKVER $@'; \
+ ( echo "#include <linux/module.h>"; \
+ echo ""; \
+ echo "static const struct modversion_info ____versions[]"; \
+ echo "__attribute__((section(\"__versions\"))) = {"; \
+ for sym in `nm -u $<`; do \
+ grep "\"$$sym\"" .tmp_all-versions \
+ || echo "*** Warning: $(<:.o=.ko): \"$$sym\" unresolved!" >&2;\
+ done; \
+ echo "};"; \
+ ) > $@
endef
-targets := $(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver))
+$(modules:.ko=.ver.c): %.ver.c: %.o .tmp_all-versions FORCE
+ $(call if_changed_rule,mkver_o_c)
-$(MODVERDIR)/%.ver: %.c FORCE
- @$(call if_changed_rule,cc_ver_c)
+targets += $(modules:.ko=.ver.c))
-modver: $(targets) $(subdir-ym)
- @mkdir -p $(dir $(addprefix .tmp_export-objs/modules/,$(export-objs:.o=.ver)))
- @touch $(addprefix .tmp_export-objs/modules/,$(export-objs:.o=.ver))
+# Extract all checksums for all exported symbols
-endif # export-objs
+export-objs := $(shell for m in vmlinux $(modules:.ko=.o); do objdump -h $$m | grep -q __ksymtab && echo $$m; done)
-# Descending
-# ---------------------------------------------------------------------------
+cmd_gen-all-versions = mksyms $(export-objs)
+define rule_gen-all-versions
+ echo ' MKSYMS $@'; \
+ for mod in $(export-objs); do \
+ modname=`basename $$mod`; \
+ nm $$mod \
+ | grep ' __crc_' \
+ | sed "s/\([^ ]*\) A __crc_\(.*\)/{ 0x\1, \"\2\" }, \/* $$modname *\//g;s/.* w __crc_\(.*\)/{ 0x0 , \"\1\" }, \/* $$modname *\//g"; \
+ done > $@; \
+ echo 'cmd_$@ := $(cmd_$(1))' > $(@D)/.$(@F).cmd
+endef
+
+.tmp_all-versions: $(export-objs) FORCE
+ $(call if_changed_rule,gen-all-versions)
-.PHONY: $(subdir-ym)
-$(subdir-ym):
- $(Q)$(MAKE) -f scripts/Makefile.modver obj=$@
+targets += .tmp_all-versions
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
# ---------------------------------------------------------------------------
diff --git a/scripts/per-cpu-check.awk b/scripts/per-cpu-check.awk
index f1b34c42df4b..3be9f0d25ebd 100644
--- a/scripts/per-cpu-check.awk
+++ b/scripts/per-cpu-check.awk
@@ -6,7 +6,7 @@
IN_PER_CPU=0
}
-/__per_cpu$$/ && ! ( / __ksymtab_/ || / __kstrtab_/ ) {
+/__per_cpu$$/ && ! ( / __ksymtab_/ || / __kstrtab_/ || / __kcrctab_/ ) {
if (!IN_PER_CPU) {
print $$3 " not in per-cpu section" > "/dev/stderr";
FOUND=1;