[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] xen: Add CONFIG_GC_SECTIONS


  • To: Jason Andryuk <jason.andryuk@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Date: Fri, 12 Dec 2025 12:42:45 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mKoF8jsSm5qGPJmylvxaCTX2wl326sDA8irhOg3O5MU=; b=mHq6ilUesAv0sTW+Vj9x7Zlfev56S+zrjxd7Aa5hWBQC6+c8aU6EGynJPmEpXG2Ga62hKePW9r2nBXjAdXp3PaUe4TikF/l7Jbmukj9vleEG9bcl7iNJb1cbn6pjv6KcyljqXlUvSsdWX68BWnWrmKZfTMcdx1iDZ/4AK//BNQVmSRr8JcmG39qF/FFD1fSXxWb1Dr/pWFJwDEw/1UUJF5XO/Bzi45SUnAQqID2OJI1nef6l6FFUyXLo3OapdNQl7wTroxPz9rPseMkYQRHXzahB88gUmF2xdR/mytNqhKVJG/Wt/VkUVcCD0l5Me0w7woseBn1atjvskpBJszNODw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=J2UUHKDyKxykGYlUT+RSSpD049Ww3PakOZrdSCwTYiEtZrgpWRAIAbYx8w/RVhhRuEalQ4jt5r6vZV4FH7vkdaxOa+V6yS4aGAl83lBu028LP//1lDnM44He9jxiW/sgCk6tYDukD3ngaX7rHjmy3OZRwUqY/RUP6AS9idE7Acdzj7tiF/+AjwdHnXwv/2O5FAT1cRDz/w3qpjTqzWHkpC6bhEDNpCXQvS6xTWDfVm4WpMNJUcTCfkaMxhhyVm5r5Z40LU57UoxFKRffxC4W9pBwIfgPKA+XJJZPWLE+3ZPa8AyokonOhfMcezVq8VkfAjkyBUnlAOmMo72ODCGzeA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Victor Lira <victorm.lira@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Timothy Pearson <tpearson@xxxxxxxxxxxxxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
  • Delivery-date: Fri, 12 Dec 2025 10:43:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Jason,

On 09.12.25 23:47, Jason Andryuk wrote:
Add a new Kconfig CONFIG_GC_SECTIONS to control linking with
--gc-sections.  --gc-sections witll garbage collect unused sections.
Combined with CONFIG_CC_SPLIT_SECTIONS, this will remove unreachable
code and data.

Linker scripts need to add KEEP() assorted places to retain
appropriate data - especially the arrays created by the linker script.

This has some affect, but it is inomplete.  In a test where memory_add()
is unreachable, it is still included.  I'm not sure, but it seems that
alternatives keep a relocation reference to it.

Only ELF xen is supported.  xen.efi fails to link with many undefined
references when using --gc-sections.

Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
v1:
Add Kconfig
select CC_SPLIT_SECTIONS
remove KEEP from .fixup
Add KEEP to .text.entry.* (Only needed with Jan's "common: honor
CONFIG_CC_SPLIT_SECTIONS also for assembly functions" ?)
Add ARM, RISC-V and PPC

Pipeline passes:
https://gitlab.com/xen-project/people/jandryuk-amd/xen/-/pipelines/2205223331

It defaults CONFIG_GC_SECTIONS=y and adds --print-gc-sections


[...]

---
  xen/Makefile              |  3 +++
  xen/arch/arm/Makefile     |  6 +++---
  xen/arch/arm/xen.lds.S    | 22 +++++++++++-----------
  xen/arch/ppc/Makefile     |  6 +++---
  xen/arch/ppc/xen.lds.S    | 14 +++++++-------
  xen/arch/riscv/Makefile   |  6 +++---
  xen/arch/riscv/xen.lds.S  | 14 +++++++-------
  xen/arch/x86/Makefile     |  6 +++---
  xen/arch/x86/xen.lds.S    | 34 +++++++++++++++++-----------------
  xen/common/Kconfig        |  9 +++++++++
  xen/include/xen/xen.lds.h | 20 ++++++++++----------
  11 files changed, 76 insertions(+), 64 deletions(-)

diff --git a/xen/Makefile b/xen/Makefile
index e6cf287425..aeb5dcf2ee 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -469,10 +469,13 @@ all-symbols-$(CONFIG_FAST_SYMBOL_LOOKUP) += --sort-by-name
include $(srctree)/arch/$(SRCARCH)/arch.mk +XEN_FINAL_LDFLAGS-$(CONFIG_GC_SECTIONS) := --gc-sections
+
  # define new variables to avoid the ones defined in Config.mk
  export XEN_CFLAGS := $(CFLAGS)
  export XEN_AFLAGS := $(AFLAGS)
  export XEN_LDFLAGS := $(LDFLAGS)
+export XEN_FINAL_LDFLAGS := $(LDFLAGS) $(XEN_FINAL_LDFLAGS-y)
  export CFLAGS_UBSAN
endif # need-config

[...]

diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S
index 2d5f1c516d..178af612a2 100644
--- a/xen/arch/arm/xen.lds.S
+++ b/xen/arch/arm/xen.lds.S
@@ -63,7 +63,7 @@ SECTIONS
. = ALIGN(4);
         __proc_info_start = .;
-       *(.proc.info)
+       KEEP(*(.proc.info))
         __proc_info_end = .;
    } :text
@@ -103,7 +103,7 @@ SECTIONS
    . = ALIGN(8);
    .arch.info : {
        _splatform = .;
-      *(.arch.info)
+      KEEP(*(.arch.info))
        _eplatform = .;
    } :text
@@ -116,7 +116,7 @@ SECTIONS
    . = ALIGN(8);
    .teemediator.info : {
        _steemediator = .;
-      *(.teemediator.info)
+      KEEP(*(.teemediator.info))
        _eteemediator = .;
    } :text
@@ -127,7 +127,7 @@ SECTIONS
         *(.init.text)
         _einittext = .;
         . = ALIGN(PAGE_SIZE);        /* Avoid mapping alt insns executable */
-       *(.altinstr_replacement)
+       KEEP(*(.altinstr_replacement))
    } :text
    . = ALIGN(PAGE_SIZE);
    __init_data_begin = .;
@@ -137,18 +137,18 @@ SECTIONS
. = ALIGN(POINTER_ALIGN);
         __setup_start = .;
-       *(.init.setup)
+       KEEP(*(.init.setup))
         __setup_end = .;
__initcall_start = .;
-       *(.initcallpresmp.init)
+       KEEP(*(.initcallpresmp.init))
         __presmp_initcall_end = .;
-       *(.initcall1.init)
+       KEEP(*(.initcall1.init))
         __initcall_end = .;

Wouldn't it be reasonable to do the same here for "initcall/setup" as was done 
for
"schedulers_array"?


[...]

--
Best regards,
-grygorii




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.