From: Roger Pau Monne Date: Tue, 1 Mar 2022 11:34:54 +0000 (+0100) Subject: livepatch: set -f{function,data}-sections compiler option X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=refs%2Fheads%2Fsplit-sections;p=people%2Froyger%2Fxen.git livepatch: set -f{function,data}-sections compiler option If livepatching support is enabled build the hypervisor with -f{function,data}-sections compiler options, which is required by the livepatching tools to detect changes and create livepatches. This shouldn't result in any functional change on the hypervisor binary image, but does however require some changes in the linker script in order to handle that each function and data item will now be placed into its own section in object files. As a result add catch-all for .text, .data and .bss in order to merge each individual item section into the final image. The main difference will be that .text.startup will end up being part of .text rather than .init, and thus won't be freed. .text.exit will also be part of .text rather than dropped. Overall this could make the image bigger, and package some .text code in a sub-optimal way. Note that placement of the sections inside of .text is also slightly adjusted to be more similar to the position found in the default GNU ld linker script. The benefit of having CONFIG_LIVEPATCH enable those compiler options is that the livepatch build tools no longer need to fiddle with the build system in order to enable them. Note the current livepatch tools are broken after the recent build changes due to the way they attempt to set -f{function,data}-sections. Signed-off-by: Roger Pau Monné --- Changes since v1: - Introduce CC_SPLIT_SECTIONS for selecting the compiler options. - Drop check for compiler options, all supported versions have them. - Re-arrange section placement in .text, to match the default linker script. - Introduce .text.header to contain the headers bits that must appear first in the final binary. --- diff --git a/xen/Makefile b/xen/Makefile index ed4891daf1..76b529cd6e 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -269,6 +269,8 @@ else CFLAGS += -fomit-frame-pointer endif +CFLAGS-$(CONFIG_CC_SPLIT_SECTIONS) += -ffunction-sections -fdata-sections + CFLAGS += -nostdinc -fno-builtin -fno-common CFLAGS += -Werror -Wredundant-decls -Wno-pointer-arith $(call cc-option-add,CFLAGS,CC,-Wvla) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index 7a906167ef..d92d829a2d 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -120,6 +120,7 @@ #endif /* !CONFIG_EARLY_PRINTK */ + .section .text.header, "ax", @progbits .arm /* diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 66d862fc81..fc9d91880b 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -133,6 +133,7 @@ add \xb, \xb, x20 .endm + .section .text.header, "ax", @progbits /*.aarch64*/ /* diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 08016948ab..f6545e549e 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -30,9 +30,16 @@ SECTIONS _start = .; .text : { _stext = .; /* Text section */ + *(.text.header) + + *(.text.cold .text.cold.*) + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text) - *(.text.cold) - *(.text.unlikely) +#ifdef CONFIG_CC_SPLIT_SECTIONS + *(.text.*) +#endif + *(.fixup) *(.gnu.warning) _etext = .; /* End of text section */ @@ -96,6 +103,9 @@ SECTIONS *(.data.rel) *(.data.rel.*) +#ifdef CONFIG_LIVEPATCH + *(.data.*) +#endif CONSTRUCTORS } :text @@ -208,6 +218,9 @@ SECTIONS . = ALIGN(SMP_CACHE_BYTES); __per_cpu_data_end = .; *(.bss) +#ifdef CONFIG_LIVEPATCH + *(.bss.*) +#endif . = ALIGN(POINTER_ALIGN); __bss_end = .; } :text diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index dd1bea0d10..92d73345f0 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -9,7 +9,7 @@ #include #include - .text + .section .text.header, "ax", @progbits .code32 #define sym_offs(sym) ((sym) - __XEN_VIRT_START) diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 34802f6522..98b2a75cfb 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -81,9 +81,7 @@ SECTIONS _start = .; DECL_SECTION(.text) { _stext = .; /* Text and read-only data */ - *(.text) - *(.text.__x86_indirect_thunk_*) - *(.text.page_aligned) + *(.text.header) . = ALIGN(PAGE_SIZE); _stextentry = .; @@ -94,8 +92,16 @@ SECTIONS *(.text.kexec) /* Page aligned in the object file. */ kexec_reloc_end = .; - *(.text.cold) - *(.text.unlikely) + *(.text.cold .text.cold.*) + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + + *(.text) +#ifdef CONFIG_CC_SPLIT_SECTIONS + *(.text.*) +#endif + *(.text.__x86_indirect_thunk_*) + *(.text.page_aligned) + *(.fixup) *(.gnu.warning) _etext = .; /* End of text section */ @@ -330,9 +336,7 @@ SECTIONS DECL_SECTION(.data) { *(.data.page_aligned) - *(.data) - *(.data.rel) - *(.data.rel.*) + *(.data .data.*) CONSTRUCTORS } PHDR(text) @@ -348,7 +352,7 @@ SECTIONS *(.bss.percpu.read_mostly) . = ALIGN(SMP_CACHE_BYTES); __per_cpu_data_end = .; - *(.bss) + *(.bss .bss.*) . = ALIGN(POINTER_ALIGN); __bss_end = .; } PHDR(text) diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 6443943889..202f0811d1 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -350,10 +350,14 @@ source "common/sched/Kconfig" config CRYPTO bool +config CC_SPLIT_SECTIONS + bool + config LIVEPATCH bool "Live patching support" default X86 depends on "$(XEN_HAS_BUILD_ID)" = "y" + select CC_SPLIT_SECTIONS ---help--- Allows a running Xen hypervisor to be dynamically patched using binary patches without rebooting. This is primarily used to binarily