]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
livepatch: set -f{function,data}-sections compiler option split-sections gitlab/split-sections
authorRoger Pau Monne <roger.pau@citrix.com>
Tue, 1 Mar 2022 11:34:54 +0000 (12:34 +0100)
committerRoger Pau Monne <roger.pau@citrix.com>
Thu, 3 Mar 2022 14:18:40 +0000 (15:18 +0100)
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é <roger.pau@citrix.com>
---
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.

xen/Makefile
xen/arch/arm/arm32/head.S
xen/arch/arm/arm64/head.S
xen/arch/arm/xen.lds.S
xen/arch/x86/boot/head.S
xen/arch/x86/xen.lds.S
xen/common/Kconfig

index ed4891daf121583c9afb275a8ddb478b8687f64e..76b529cd6e9fc9b748e82c5b527bbf1e04a9c267 100644 (file)
@@ -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)
index 7a906167efca8790db0b58c6aaec7a77af92242a..d92d829a2d8769d23c9ba5aea6d8db4881a3b509 100644 (file)
 
 #endif /* !CONFIG_EARLY_PRINTK */
 
+        .section .text.header, "ax", @progbits
         .arm
 
         /*
index 66d862fc813741faaf7b97fe1a967752da170374..fc9d91880beceb6de611445e854f6c2ac8ba864e 100644 (file)
         add \xb, \xb, x20
 .endm
 
+        .section .text.header, "ax", @progbits
         /*.aarch64*/
 
         /*
index 08016948ab3139f923327f7884dd09dd56fd3853..f6545e549ecc6c5a84e4b0cf39ddf308da6d4970 100644 (file)
@@ -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
index dd1bea0d10b3e813595204dc701ffec5a22b75d5..92d73345f0c9f0e1c9f72857471aae689b02d351 100644 (file)
@@ -9,7 +9,7 @@
 #include <asm/cpufeature.h>
 #include <public/elfnote.h>
 
-        .text
+        .section .text.header, "ax", @progbits
         .code32
 
 #define sym_offs(sym)     ((sym) - __XEN_VIRT_START)
index 34802f6522f7368ee2c01dab9b8235e2aadabe11..98b2a75cfb47d9b39545e2fd493643ba2bd1711c 100644 (file)
@@ -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)
index 64439438891c06d063eb6e630c4342b17a30f789..202f0811d105822b10d413baaae4d9e1501f3f64 100644 (file)
@@ -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