]> git.baikalelectronics.ru Git - kernel.git/commit
init: lto: ensure initcall ordering
authorSami Tolvanen <samitolvanen@google.com>
Fri, 11 Dec 2020 18:46:24 +0000 (10:46 -0800)
committerKees Cook <keescook@chromium.org>
Thu, 14 Jan 2021 16:21:09 +0000 (08:21 -0800)
commitd1f9066a159eaacee4f494fad82bbbfccf9b9588
treed9960a5b4de9403c9a602287c051adfcd3794fe7
parentddbf5da454681dd1237884f53b1eb9e5f5511814
init: lto: ensure initcall ordering

With LTO, the compiler doesn't necessarily obey the link order for
initcalls, and initcall variables need globally unique names to avoid
collisions at link time.

This change exports __KBUILD_MODNAME and adds the initcall_id() macro,
which uses it together with __COUNTER__ and __LINE__ to help ensure
these variables have unique names, and moves each variable to its own
section when LTO is enabled, so the correct order can be specified using
a linker script.

The generate_initcall_ordering.pl script uses nm to find initcalls from
the object files passed to the linker, and generates a linker script
that specifies the same order for initcalls that we would have without
LTO. With LTO enabled, the script is called in link-vmlinux.sh through
jobserver-exec to limit the number of jobs spawned.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20201211184633.3213045-8-samitolvanen@google.com
include/linux/init.h
scripts/Makefile.lib
scripts/generate_initcall_order.pl [new file with mode: 0755]
scripts/link-vmlinux.sh