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

Re: [PATCH] RFC: xen/x86: Enable --gc-sections


  • To: Grygorii Strashko <grygorii_strashko@xxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Mon, 8 Dec 2025 18:03:39 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=epam.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=1FDVCVnz8hiZwPdl4WPZ705nhjq/Phnvt6CIbBE2xPI=; b=HCbb+Thb7cXkAFKqQmvL4hKf54pMp0RapITK2+jq5Vyv1ra7DQe0zy+/+zrcEtKRd7bqx9pRnfSEmNTNcf+xaWJMk1EWHIUqLdYMvvA0mkd7/R4HNCIFtFsap0k9+vyPlszXyXLhnrGjcihVBysVB0QPNm+xsyRExbB67+twQ43RybweHNPVi7YjOWC3eZNTrBNmyPHtWJdgI2v/7zw0dmjE0HzxHTHNMxKd5PjdW+pD1VWPe3b8DfROfoVqbrWEkUXkv/fJ2HPyxlimzx5eUdAMNikOgRp7KZEApNS1iHQ1VvvMfNLOBp56ltjC4Cs+ug2+y68PSGd/vQhe8zLbZQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mBRoj677RD8BvCj10Ulbh0MPoGIqJod0ZsT66NR5FXUj6V+DekN5v6yRA6IdO0Il73o8cv4Caa+PTpB8Cu7o3SEb2Q8v5ecAP2yhxUWm6xWDYPAf+Om6FHB0HUqOWcaUM617l9c4V/TNAtDceCTcU2+m32xGs04ZAHLoyJWh+UhdEWWzzSarmFcckRr3TC1NQGgoag4MAniuYLQWhr2tOsApqbR9yZ6DqiF5tLDk62/vxxcKO3oi8M/FBWdVgj81vP5uisSgZti7NjrKA1/HhJ87fNGcnaYX4ZbwgXfRhNds1YEVBJXyTQBPmvtmGufFjT2bjLzn0oD9jhxEcqj4zQ==
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, "Michal Orzel" <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>
  • Delivery-date: Mon, 08 Dec 2025 23:03:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2025-12-08 13:45, Grygorii Strashko wrote:


On 06.12.25 00:28, Jason Andryuk wrote:
When linking to create xen-syms, add --gc-sections to garbage collect
unused stuff.  Relies on CONFIG_CC_SPLIT_SECTIONS

We need to add KEEP() to the linker script in assorted places to retain
appropriate data - especially the arrays created therein.

Something is off though.  In a test where memory_add() is unreachable,
it is still included.  I'm not sure, but I am wondering if it's the
alternatives somehow keeping a reference to it.

Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
With --print-gc-sections on defconfig:
ld: removing unused section '.text.__bitmap_full' in file 'prelink.o'
ld: removing unused section '.text.__bitmap_xor' in file 'prelink.o'
ld: removing unused section '.text.__bitmap_set' in file 'prelink.o'
ld: removing unused section '.text.__bitmap_clear' in file 'prelink.o'
ld: removing unused section '.text.bitmap_find_free_region' in file 'prelink.o' ld: removing unused section '.text.bitmap_release_region' in file 'prelink.o' ld: removing unused section '.text.domain_has_ioreq_server' in file 'prelink.o'
ld: removing unused section '.text.compat_kexec_op' in file 'prelink.o'
ld: removing unused section '.text.in_atomic' in file 'prelink.o'
ld: removing unused section '.text.radix_tree_next_hole' in file 'prelink.o' ld: removing unused section '.text.radix_tree_prev_hole' in file 'prelink.o' ld: removing unused section '.text.radix_tree_gang_lookup_slot' in file 'prelink.o'
ld: removing unused section '.text._nrspin_trylock' in file 'prelink.o'
ld: removing unused section '.text.xen_compile_host' in file 'prelink.o'
ld: removing unused section '.text.vscnprintf' in file 'prelink.o'
ld: removing unused section '.text.wake_up_one' in file 'prelink.o'
ld: removing unused section '.text.xmem_pool_get_used_size' in file 'prelink.o' ld: removing unused section '.text.xmem_pool_get_total_size' in file 'prelink.o' ld: removing unused section '.text.xmem_pool_maxalloc' in file 'prelink.o'
ld: removing unused section '.text.xlat_start_info' in file 'prelink.o'
ld: removing unused section '.text.elf_sym_by_name' in file 'prelink.o'
ld: removing unused section '.text.elf_sym_by_index' in file 'prelink.o'
ld: removing unused section '.text.elf_get_ptr' in file 'prelink.o'
ld: removing unused section '.text.elf_lookup_addr' in file 'prelink.o'
ld: removing unused section '.text.serial_vuart_info' in file 'prelink.o'
ld: removing unused section '.text.pci_find_next_cap' in file 'prelink.o'
ld: removing unused section '.text.free_hvm_irq_dpci' in file 'prelink.o'
ld: removing unused section '.text.mce_barrier_init' in file 'prelink.o'
ld: removing unused section '.text.mce_barrier_dec' in file 'prelink.o'
ld: removing unused section '.text.mce_barrier' in file 'prelink.o'
ld: removing unused section '.text.apei_read_mce' in file 'prelink.o'
ld: removing unused section '.text.apei_check_mce' in file 'prelink.o'
ld: removing unused section '.text.apei_clear_mce' in file 'prelink.o'
ld: removing unused section '.text.efi_halt_system' in file 'prelink.o'
ld: removing unused section '.text.get_vvmcs_virtual_safe' in file 'prelink.o' ld: removing unused section '.text.get_vvmcs_real_safe' in file 'prelink.o'
ld: removing unused section '.text.set_vvmcs_real' in file 'prelink.o'
ld: removing unused section '.text.set_vvmcs_virtual_safe' in file 'prelink.o' ld: removing unused section '.text.set_vvmcs_real_safe' in file 'prelink.o' ld: removing unused section '.text.domain_set_alloc_bitsize' in file 'prelink.o'
ld: removing unused section '.text.watchdog_enabled' in file 'prelink.o'
ld: removing unused section '.text.unset_nmi_callback' in file 'prelink.o'
ld: removing unused section '.text.sha2_256_init' in file 'prelink.o'
ld: removing unused section '.text.xxh64_copy_state' in file 'prelink.o'
ld: removing unused section '.text.xxh64' in file 'prelink.o'
ld: removing unused section '.discard' in file 'prelink.o'
ld: removing unused section '.rodata.xen_compile_host.str1.1' in file 'prelink.o' ld: removing unused section '.rodata.elf_lookup_addr.str1.1' in file 'prelink.o' ld: removing unused section '.rodata.apei_read_mce.str1.8' in file 'prelink.o' ld: removing unused section '.rodata.efi_halt_system.str1.8' in file 'prelink.o' ld: removing unused section '.rodata.play_dead.str1.1' in file 'prelink.o' ld: removing unused section '.data.rel.ro.local.fetch_type_names' in file 'prelink.o'
---
  xen/arch/x86/Makefile     |  3 +++
  xen/arch/x86/xen.lds.S    | 38 +++++++++++++++++++-------------------
  xen/include/xen/xen.lds.h | 18 +++++++++---------
  3 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 300cc67407..934c79411a 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -137,18 +137,21 @@ $(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
      $(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S
      $(MAKE) $(build)=$(@D) $(dot-target).0.o
      $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
+          --gc-sections \
            $(dot-target).0.o -o $(dot-target).0
      $(NM) -pa --format=sysv $(dot-target).0 \
          | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
          > $(dot-target).1.S
      $(MAKE) $(build)=$(@D) $(dot-target).1.o
      $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
+          --gc-sections \
          $(dot-target).1.o -o $(dot-target).1
      $(NM) -pa --format=sysv $(dot-target).1 \
          | $(objtree)/tools/symbols $(all_symbols) --sysv --sort $(syms-warn-dup-y) \
          > $(dot-target).2.S
      $(MAKE) $(build)=$(@D) $(dot-target).2.o
      $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
+          --gc-sections \

It should work if --gc-sections is used only here - last LD statement.

I think we want to add it to all three. That way the same operations are performed when generating the symbols in the first two rounds of linking. I think that would omit symbols that may get dropped.

Regards,
Jason



 


Rackspace

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