arm64: Add support for relocating the kernel with RELR relocations
authorPeter Collingbourne <pcc@google.com>
Thu, 1 Aug 2019 01:18:42 +0000 (18:18 -0700)
committerWill Deacon <will@kernel.org>
Mon, 5 Aug 2019 11:35:35 +0000 (12:35 +0100)
commit5cf896fb6be3effd9aea455b22213e27be8bdb1d
tree563e83ed04a2de71b65e831896bf52e0eaf31af0
parent66cbdf5d0c96f5fe570b548e764583ea9d793077
arm64: Add support for relocating the kernel with RELR relocations

RELR is a relocation packing format for relative relocations.
The format is described in a generic-abi proposal:
https://groups.google.com/d/topic/generic-abi/bX460iggiKg/discussion

The LLD linker can be instructed to pack relocations in the RELR
format by passing the flag --pack-dyn-relocs=relr.

This patch adds a new config option, CONFIG_RELR. Enabling this option
instructs the linker to pack vmlinux's relative relocations in the RELR
format, and causes the kernel to apply the relocations at startup along
with the RELA relocations. RELA relocations still need to be applied
because the linker will emit RELA relative relocations if they are
unrepresentable in the RELR format (i.e. address not a multiple of 2).

Enabling CONFIG_RELR reduces the size of a defconfig kernel image
with CONFIG_RANDOMIZE_BASE by 3.5MB/16% uncompressed, or 550KB/5%
compressed (lz4).

Signed-off-by: Peter Collingbourne <pcc@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
Makefile
arch/Kconfig
arch/arm64/Kconfig
arch/arm64/kernel/head.S
arch/arm64/kernel/vmlinux.lds.S
init/Kconfig
scripts/tools-support-relr.sh [new file with mode: 0755]