Commit 2ec54bc1 authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: Move the version magic generation into module postprocessing

Since we'll have to always do module postprocessing shortly, we can as well
get rid of the special cased init/vermagic.o which needed to be compiled
before descending, and instead include the current version magic string
during post processing. For that purpose, the generation of the string is
moved from init/vermagic.c to include/linux/vermagic.h.

People who externally maintain modules will also be happy about that.
parent 0e7d983b
...@@ -416,17 +416,6 @@ endif ...@@ -416,17 +416,6 @@ endif
endif endif
@echo ' Starting the build. KBUILD_BUILTIN=$(KBUILD_BUILTIN) KBUILD_MODULES=$(KBUILD_MODULES)' @echo ' Starting the build. KBUILD_BUILTIN=$(KBUILD_BUILTIN) KBUILD_MODULES=$(KBUILD_MODULES)'
# We need to build init/vermagic.o before descending since all modules
# (*.ko) need it already
ifdef CONFIG_MODULES
prepare: init/vermagic.o
init/vermagic.o: include/linux/version.h
endif
# This can be used by arch/$ARCH/Makefile to preprocess # This can be used by arch/$ARCH/Makefile to preprocess
# their vmlinux.lds.S file # their vmlinux.lds.S file
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#define MODULE_ARCH_VERMAGIC "" #define MODULE_ARCH_VERMAGIC ""
#endif #endif
const char vermagic[] __attribute__((section("__vermagic"))) = #define VERMAGIC_STRING \
UTS_RELEASE " " UTS_RELEASE " " \
MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT MODULE_ARCH_VERMAGIC MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
"gcc-" __stringify(__GNUC__) "." __stringify(__GNUC_MINOR__); MODULE_ARCH_VERMAGIC \
"gcc-" __stringify(__GNUC__) "." __stringify(__GNUC_MINOR__)
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
# #
obj-y := main.o version.o do_mounts.o initramfs.o obj-y := main.o version.o do_mounts.o initramfs.o
obj-$(CONFIG_MODULES) += vermagic.o
# files to be removed upon make clean # files to be removed upon make clean
clean-files := ../include/linux/compile.h clean-files := ../include/linux/compile.h
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/vermagic.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/semaphore.h> #include <asm/semaphore.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
...@@ -725,6 +726,8 @@ static int obsolete_params(const char *name, ...@@ -725,6 +726,8 @@ static int obsolete_params(const char *name,
} }
#endif /* CONFIG_OBSOLETE_MODPARM */ #endif /* CONFIG_OBSOLETE_MODPARM */
static const char vermagic[] = VERMAGIC_STRING;
#ifdef CONFIG_MODVERSIONS #ifdef CONFIG_MODVERSIONS
static int check_version(Elf_Shdr *sechdrs, static int check_version(Elf_Shdr *sechdrs,
unsigned int versindex, unsigned int versindex,
...@@ -1036,9 +1039,6 @@ static void set_license(struct module *mod, Elf_Shdr *sechdrs, int licenseidx) ...@@ -1036,9 +1039,6 @@ static void set_license(struct module *mod, Elf_Shdr *sechdrs, int licenseidx)
} }
} }
/* From init/vermagic.o */
extern char vermagic[];
/* Allocate and load the module: note that size of section 0 is always /* Allocate and load the module: note that size of section 0 is always
zero, and we rely on this for optional sections. */ zero, and we rely on this for optional sections. */
static struct module *load_module(void *umod, static struct module *load_module(void *umod,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
.PHONY: __modversions .PHONY: __modversions
__modversions: __modversions:
include .config
include scripts/Makefile.lib include scripts/Makefile.lib
# #
...@@ -28,7 +29,7 @@ quiet_cmd_ld_ko_o = LD [M] $@ ...@@ -28,7 +29,7 @@ quiet_cmd_ld_ko_o = LD [M] $@
init/vermagic.o: ; init/vermagic.o: ;
$(modules): %.ko :%.o $(if $(CONFIG_MODVERSIONS),%.ver.o) init/vermagic.o FORCE $(modules): %.ko :%.o %.ver.o FORCE
$(call if_changed,ld_ko_o) $(call if_changed,ld_ko_o)
targets += $(modules) targets += $(modules)
...@@ -45,12 +46,19 @@ targets += $(modules:.ko=.ver.o) ...@@ -45,12 +46,19 @@ targets += $(modules:.ko=.ver.o)
# Generate C source with version info for unresolved symbols # Generate C source with version info for unresolved symbols
ifdef CONFIG_MODVERSIONS
define rule_mkver_o_c define rule_mkver_o_c
echo ' MKVER $@'; \ echo ' MKVER $@'; \
( echo "#include <linux/module.h>"; \ ( echo "#include <linux/module.h>"; \
echo "#include <linux/vermagic.h>"; \
echo ""; \
echo "const char vermagic[]"; \
echo "__attribute__((section(\"__vermagic\"))) ="; \
echo "VERMAGIC_STRING;"; \
echo ""; \ echo ""; \
echo "static const struct modversion_info ____versions[]"; \ echo "static const struct modversion_info ____versions[]"; \
echo "__attribute__((section(\"__versions\"))) = {"; \ echo "__attribute__((section(\"__versions\"))) = {"; \
for sym in `nm -u $<`; do \ for sym in `nm -u $<`; do \
grep "\"$$sym\"" .tmp_all-versions \ grep "\"$$sym\"" .tmp_all-versions \
|| echo "*** Warning: $(<:.o=.ko): \"$$sym\" unresolved!" >&2;\ || echo "*** Warning: $(<:.o=.ko): \"$$sym\" unresolved!" >&2;\
...@@ -59,9 +67,35 @@ define rule_mkver_o_c ...@@ -59,9 +67,35 @@ define rule_mkver_o_c
) > $@ ) > $@
endef endef
$(modules:.ko=.ver.c): %.ver.c: %.o .tmp_all-versions FORCE # We have a fake dependency on compile.h to make sure that we notice
# if the compiler version changes under us.
$(modules:.ko=.ver.c): \
%.ver.c: %.o .tmp_all-versions include/linux/compile.h FORCE
$(call if_changed_rule,mkver_o_c)
else
define rule_mkver_o_c
echo ' MKVER $@'; \
( echo "#include <linux/module.h>"; \
echo "#include <linux/vermagic.h>"; \
echo ""; \
echo "const char vermagic[]"; \
echo "__attribute__((section(\"__vermagic\"))) ="; \
echo "VERMAGIC_STRING;"; \
) > $@
endef
# We have a fake dependency on compile.h to make sure that we notice
# if the compiler version changes under us.
$(modules:.ko=.ver.c): \
%.ver.c: %.o include/linux/compile.h FORCE
$(call if_changed_rule,mkver_o_c) $(call if_changed_rule,mkver_o_c)
endif
targets += $(modules:.ko=.ver.c)) targets += $(modules:.ko=.ver.c))
# Extract all checksums for all exported symbols # Extract all checksums for all exported symbols
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment