arm64: extable: sort the exception table at build time
PATCH 1/1 arm64: extable: sort the exception table at build time
As is done for other architectures, sort the exception table at build-time rather than during boot.
Since sortextable appears to be a standalone C program relying on the host elf.h to provide EM_AARCH64, I've had to add a conditional check in order to allow cross-compilation on machines that aren't running a bleeding-edge libc-dev.
--- arch/arm64/Kconfig | 1 + arch/arm64/kernel/vmlinux.lds.S | 15 +++++++-------- scripts/sortextable.c | 5 +++++ 3 files changed, 13 insertions(+), 8 deletions(-)
arch/arm64/Kconfig +1 -0
@@ -7,6 +7,7 @@ config ARM64 select ARM_AMBA select ARM_ARCH_TIMER select ARM_GIC + select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS select COMMON_CLK select GENERIC_CLOCKEVENTS
arch/arm64/kernel/vmlinux.lds.S +7 -8
@@ -57,6 +57,13 @@ SECTIONS RO_DATA(PAGE_SIZE) + . = ALIGN(8); + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { + __start___ex_table = .; + *(__ex_table) + __stop___ex_table = .; + } + _etext = .; /* End of text and rodata section */ . = ALIGN(PAGE_SIZE);
@@ -99,14 +106,6 @@ SECTIONS READ_MOSTLY_DATA(64) /* - * The exception fixup table (might need resorting at runtime) - */ - . = ALIGN(32); - __start___ex_table = .; - *(__ex_table) - __stop___ex_table = .; - - /* * and the usual data section */ DATA_DATA
scripts/sortextable.c +5 -0
@@ -31,6 +31,10 @@#include <tools/be_byteshift.h> #include <tools/le_byteshift.h> +#ifndef EM_AARCH64 +#define EM_AARCH64 183 +#endif +static int fd_map;/* File descriptor for file being modified. */ static int mmap_failed;/* Boolean flag. */ static void *ehdr_curr;/* current ElfXX_Ehdr * for resource cleanup */
@@ -249,6 +253,7 @@ do_file(char const *const fname) custom_sort = sort_relative_table;break ;case EM_ARM : +case EM_AARCH64 :case EM_MIPS :break ; }/* end switch */
Signature · 1 line
1.8.2.2
Quoted 33 lines · Will Deacon
As is done for other architectures, sort the exception table at build-time rather than during boot.
Since sortextable appears to be a standalone C program relying on the host
elf.hto provideEM_AARCH64, I've had to add a conditional check in order to allow cross-compilation on machines that aren't running a bleeding-edge libc-dev.Signed-off-by Will Deacon <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/kernel/vmlinux.lds.S | 15 +++++++-------- scripts/sortextable.c | 5 +++++ 3 files changed, 13 insertions(+), 8 deletions(-)arch/arm64/Kconfig +1
-0@@ -7,6 +7,7 @@ config ARM64 select ARM_AMBA select ARM_ARCH_TIMER select ARM_GIC + select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS select COMMON_CLK select GENERIC_CLOCKEVENTSarch/arm64/kernel/vmlinux.lds.S +0
-0@@ -57,6 +57,13 @@ SECTIONS
arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 67
Quoted 10 lines
arch/arm64/kernel/vmlinux.lds.S +7
-0RO_DATA(PAGE_SIZE) + . = ALIGN(8); + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { + __start___ex_table = .; + *(__ex_table) + __stop___ex_table = .; + } + _etext = .; /* End of text and rodata section */
You have moved this to rodata.
o Will the runtime sort still work like this?
o Do we care? Maybe not.
David Daney
Quoted 41 lines
arch/arm64/kernel/vmlinux.lds.S +0
-8. = ALIGN(PAGE_SIZE);@@ -99,14 +106,6 @@ SECTIONS READ_MOSTLY_DATA(64) /* - * The exception fixup table (might need resorting at runtime) - */ - . = ALIGN(32); - __start___ex_table = .; - *(__ex_table) - __stop___ex_table = .; - - /* * and the usual data section */ DATA_DATAscripts/sortextable.c +5
-0@@ -31,6 +31,10 @@#include <tools/be_byteshift.h> #include <tools/le_byteshift.h> +#ifndef EM_AARCH64 +#define EM_AARCH64 183 +#endif +static int fd_map;/* File descriptor for file being modified. */ static int mmap_failed;/* Boolean flag. */ static void *ehdr_curr;/* current ElfXX_Ehdr * for resource cleanup */ @@ -249,6 +253,7 @@ do_file(char const *const fname) custom_sort = sort_relative_table;break ;case EM_ARM : +case EM_AARCH64 :case EM_MIPS :break ; }/* end switch */
Hi David,
Quoted 36 lines · David Daney
Quoted 35 lines · Will Deacon
As is done for other architectures, sort the exception table at build-time rather than during boot.
Since sortextable appears to be a standalone C program relying on the host
elf.hto provideEM_AARCH64, I've had to add a conditional check in order to allow cross-compilation on machines that aren't running a bleeding-edge libc-dev.Signed-off-by Will Deacon <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/kernel/vmlinux.lds.S | 15 +++++++-------- scripts/sortextable.c | 5 +++++ 3 files changed, 13 insertions(+), 8 deletions(-)arch/arm64/Kconfig +1
-0@@ -7,6 +7,7 @@ config ARM64 select ARM_AMBA select ARM_ARCH_TIMER select ARM_GIC + select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS select COMMON_CLK select GENERIC_CLOCKEVENTSarch/arm64/kernel/vmlinux.lds.S +0
-0@@ -57,6 +57,13 @@ SECTIONS RO_DATA(PAGE_SIZE)
Quoted 11 lines
arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 67
Quoted 8 lines
arch/arm64/kernel/vmlinux.lds.S +7
-0+ . = ALIGN(8); + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { + __start___ex_table = .; + *(__ex_table) + __stop___ex_table = .; + } + _etext = .; /* End of text and rodata section */You have moved this to rodata.
I don't think I have moved this to rodata. The RO_DATA macro expands to a bunch of sections, but it doesn't leave any of them open at the end.
Quoted 3 lines
o Will the runtime sort still work like this?
o Do we care? Maybe not.
For arm64 we'd be moving exclusively to build-time sorting, so I guess we *could* stick the thing in rodata if we wanted to. Not sure it's worth the linker script munging though.
Will
Quoted 32 lines · Will Deacon
As is done for other architectures, sort the exception table at build-time rather than during boot.
Since sortextable appears to be a standalone C program relying on the host
elf.hto provideEM_AARCH64, I've had to add a conditional check in order to allow cross-compilation on machines that aren't running a bleeding-edge libc-dev.Signed-off-by Will Deacon <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/kernel/vmlinux.lds.S | 15 +++++++-------- scripts/sortextable.c | 5 +++++ 3 files changed, 13 insertions(+), 8 deletions(-)arch/arm64/Kconfig +1
-0@@ -7,6 +7,7 @@ config ARM64 select ARM_AMBA select ARM_ARCH_TIMER select ARM_GIC + select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS select COMMON_CLK select GENERIC_CLOCKEVENTSarch/arm64/kernel/vmlinux.lds.S +0
-0
arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 65
Quoted 9 lines
arch/arm64/kernel/vmlinux.lds.S +6
-0@@ -57,6 +57,13 @@ SECTIONS RO_DATA(PAGE_SIZE) + . = ALIGN(8); + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { + __start___ex_table = .; + *(__ex_table) + __stop___ex_table = .; + }
Here you could use:
EXCEPTION_TABLE(align)
(From include/asm-generic/vmlinux.lds.h)
Sam
Quoted 11 lines · Sam Ravnborg
arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 65
Quoted 6 lines · Will Deacon
arch/arm64/kernel/vmlinux.lds.S +6
-0+ . = ALIGN(8); + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { + __start___ex_table = .; + *(__ex_table) + __stop___ex_table = .; + }Here you could use:
EXCEPTION_TABLE(align)
Quoted 1 line
(From
include/asm-generic/vmlinux.lds.h)
Good spot, I'll spin a v2 using that. Looks like we don't use that for arch/arm/ because we want to discard the section ifdef CONFIG_MMU. Maybe we could change the generic macro to expand to nothing if !MMU, but I'm not sure if other MMU-less architectures are playing tricks with this.
Will