-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPSTREAM: arm64: Add support for relocating the kernel with RELR relo…
…cations 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 <[email protected]> Tested-by: Nick Desaulniers <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Signed-off-by: Will Deacon <[email protected]> (cherry picked from commit 5cf896fb6be3effd9aea455b22213e27be8bdb1d) Bug: 137200966 Test: booted defconfig + CONFIG_RELR kernel on qemu Change-Id: I4c55bf5b10bc6c934543c651eca9fc8e260ffc6d Signed-off-by: Peter Collingbourne <[email protected]> (cherry picked from commit 5d61b2346a200592877de6a2270f62794a681724) (cherry picked from commit 04893c9b75563a2710f4d029e0e1ddb8dd03e9e7) Signed-off-by: engstk <[email protected]>
- Loading branch information
Showing
7 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh -eu | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
tmp_file=$(mktemp) | ||
trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT | ||
|
||
cat << "END" | "$CC" -c -x c - -o $tmp_file.o >/dev/null 2>&1 | ||
void *p = &p; | ||
END | ||
"$LD" $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr -o $tmp_file | ||
|
||
# Despite printing an error message, GNU nm still exits with exit code 0 if it | ||
# sees a relr section. So we need to check that nothing is printed to stderr. | ||
test -z "$("$NM" $tmp_file 2>&1 >/dev/null)" | ||
|
||
"$OBJCOPY" -O binary $tmp_file $tmp_file.bin |