Commit Graph

3 Commits

Author SHA1 Message Date
Sami Tolvanen
110784e046 FROMLIST: 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.

Bug: 145210207
Change-Id: I80619eac3674acd9c6d2566443d16b3d09515351
Link: https://lore.kernel.org/lkml/20201211184633.3213045-8-samitolvanen@google.com/
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2020-12-16 08:56:33 -08:00
Greg Kroah-Hartman
0472716d99 Revert "ANDROID: init: ensure initcall ordering with LTO"
This reverts commit 6c5ad8b10e as the LTO
feature causes merge issues with 5.8-rc1.  So remove it for now and
allow the developer to add the latest version of the patches later on.

Cc: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I0b67a8a0d4b54c5be30f0bfc5abdd1422b7ab2f1
2020-06-24 08:47:44 +02:00
Sami Tolvanen
6c5ad8b10e ANDROID: init: ensure initcall ordering with LTO
With LTO, the compiler doesn't necessarily obey link order for
initcalls, and the initcall variables need to be globally unique
to avoid naming collisions.

In order to preserve the intended order, this change moves each
initcall variable into its own section and generates a linker
script (in scripts/link-vmlinux.sh) to define the correct order
for these sections. We also add a __COUNTER__ prefix to the name,
so we can retain the order of initcalls within each compilation
unit, and __LINE__ to help ensure uniqueness.

Bug: 145210207
Change-Id: I602038783853497790c5a2941343c546e380c525
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
2019-11-26 13:27:43 -08:00