Skip to content

Commit 271ca78

Browse files
Ard Biesheuveltorvalds
authored andcommitted
arch: enable relative relocations for arm64, power and x86
Patch series "add support for relative references in special sections", v10. This adds support for emitting special sections such as initcall arrays, PCI fixups and tracepoints as relative references rather than absolute references. This reduces the size by 50% on 64-bit architectures, but more importantly, it removes the need for carrying relocation metadata for these sections in relocatable kernels (e.g., for KASLR) that needs to be fixed up at boot time. On arm64, this reduces the vmlinux footprint of such a reference by 8x (8 byte absolute reference + 24 byte RELA entry vs 4 byte relative reference) Patch #3 was sent out before as a single patch. This series supersedes the previous submission. This version makes relative ksymtab entries dependent on the new Kconfig symbol HAVE_ARCH_PREL32_RELOCATIONS rather than trying to infer from kbuild test robot replies for which architectures it should be blacklisted. Patch #1 introduces the new Kconfig symbol HAVE_ARCH_PREL32_RELOCATIONS, and sets it for the main architectures that are expected to benefit the most from this feature, i.e., 64-bit architectures or ones that use runtime relocations. Patch #2 add support for #define'ing __DISABLE_EXPORTS to get rid of ksymtab/kcrctab sections in decompressor and EFI stub objects when rebuilding existing C files to run in a different context. Patches #4 - #6 implement relative references for initcalls, PCI fixups and tracepoints, respectively, all of which produce sections with order ~1000 entries on an arm64 defconfig kernel with tracing enabled. This means we save about 28 KB of vmlinux space for each of these patches. [From the v7 series blurb, which included the jump_label patches as well]: For the arm64 kernel, all patches combined reduce the memory footprint of vmlinux by about 1.3 MB (using a config copied from Ubuntu that has KASLR enabled), of which ~1 MB is the size reduction of the RELA section in .init, and the remaining 300 KB is reduction of .text/.data. This patch (of 6): Before updating certain subsystems to use place relative 32-bit relocations in special sections, to save space and reduce the number of absolute relocations that need to be processed at runtime by relocatable kernels, introduce the Kconfig symbol and define it for some architectures that should be able to support and benefit from it. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]> Acked-by: Michael Ellerman <[email protected]> Reviewed-by: Will Deacon <[email protected]> Acked-by: Ingo Molnar <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Kees Cook <[email protected]> Cc: Thomas Garnier <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: "Serge E. Hallyn" <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Russell King <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Petr Mladek <[email protected]> Cc: James Morris <[email protected]> Cc: Nicolas Pitre <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Sergey Senozhatsky <[email protected]>, Cc: James Morris <[email protected]> Cc: Jessica Yu <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent bc63804 commit 271ca78

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

arch/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,16 @@ config REFCOUNT_FULL
841841
against various use-after-free conditions that can be used in
842842
security flaw exploits.
843843

844+
config HAVE_ARCH_PREL32_RELOCATIONS
845+
bool
846+
help
847+
May be selected by an architecture if it supports place-relative
848+
32-bit relocations, both in the toolchain and in the module loader,
849+
in which case relative references can be used in special sections
850+
for PCI fixup, initcalls etc which are only half the size on 64 bit
851+
architectures, and don't require runtime relocation on relocatable
852+
kernels.
853+
844854
source "kernel/gcov/Kconfig"
845855

846856
source "scripts/gcc-plugins/Kconfig"

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ config ARM64
108108
select HAVE_ARCH_KGDB
109109
select HAVE_ARCH_MMAP_RND_BITS
110110
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
111+
select HAVE_ARCH_PREL32_RELOCATIONS
111112
select HAVE_ARCH_SECCOMP_FILTER
112113
select HAVE_ARCH_STACKLEAK
113114
select HAVE_ARCH_THREAD_STRUCT_WHITELIST

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ config PPC
177177
select HAVE_ARCH_KGDB
178178
select HAVE_ARCH_MMAP_RND_BITS
179179
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
180+
select HAVE_ARCH_PREL32_RELOCATIONS
180181
select HAVE_ARCH_SECCOMP_FILTER
181182
select HAVE_ARCH_TRACEHOOK
182183
select HAVE_CBPF_JIT if !PPC64

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ config X86
124124
select HAVE_ARCH_MMAP_RND_BITS if MMU
125125
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT
126126
select HAVE_ARCH_COMPAT_MMAP_BASES if MMU && COMPAT
127+
select HAVE_ARCH_PREL32_RELOCATIONS
127128
select HAVE_ARCH_SECCOMP_FILTER
128129
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
129130
select HAVE_ARCH_TRACEHOOK

0 commit comments

Comments
 (0)