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

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


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Wed, 10 Dec 2025 20:28:03 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.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=6Z+Z8qADGgmCOreig4fdSc0wc8YNUCn3z0n/8lTheFc=; b=Xy1fiMF74cm9vXNopxYkJatlEy/mXHJQr4Z9eeJDIjYfEin3eEAl7M52bOPeJ5PX1LLAe0wPK7NT9Vhauh3GYzZvQlVsJcz3CjeaW84zIf113T+DiY2mvwAYm31aWNzt8BxbBLbtC+41G9PSXzIeHlSJhHI70MduTpD2155HIQ+byH2xkxQ7f/B8sjwySK9KDb0tv6hPBnKqJ3dcN2hB9I7sI79Yk32cjMpa/k27iMqw7xMWrKB+FUjfzJNIb5N10mgv2SzEVmJND+MSay9zGJXtTAeoezuGQAOzPXvU/q66nytH5b2F31Ac+Amk7DGmnESJXhe+OS+PiWbsVm1eaw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yR0PkEznYxHxbA9clEjt1I20dpiDdpMxlI+k3AKmZMsyoOJi/5mUcJroAFh7riiDEeZz0Te++BNH8R0rUbve7FUkgcsn6UsKZWe1a2lG/m2CxbZfhaPy+GO7mteNVJWuKA4m2sjbhIa+y4TRtgYKVQUkybtmOkzRIbJ5tM3q7sYkWtpfdZJCzxEGih14NpogjbAYdiwxtY01p0AV0DLqwvRerRWdk3F5sawCfkprN+VeQfHVIXRzTl7z9wbHdgCnQXykBFfD3sdcqRvIrPMcUpRbMk8Z+dxQuiv4vkbK1mZEVg3oRiXo+YNoOP0Qbndbmw5gndGsftCaC0Ibp7S/0w==
  • Cc: Victor Lira <victorm.lira@xxxxxxx>, 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>, Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Delivery-date: Thu, 11 Dec 2025 01:28:34 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2025-12-10 11:55, Andrew Cooper wrote:
On 09/12/2025 9:47 pm, Jason Andryuk wrote:
         . = ALIGN(4);
         __alt_instructions = .;
-       *(.altinstructions)
+       KEEP(*(.altinstructions))
         __alt_instructions_end = .;

Thinking about this, what we need is for there to be a reference tied to
the source location, referencing the replacement metadata and
replacement instructions.

Looking at https://maskray.me/blog/2021-02-28-linker-garbage-collection
might be able to do this with .reloc of type none.  In fact,
BFD_RELOC_NONE seems to have been invented for precisely this purpose.

This means that if and only if the source function gets included, so
does the metadata and replacement.

With Jan's -Wa,--sectname-subst changes added to CFLAGS, this seems to work somewhat. I'm trying to make the ALTERNATIVE place relocations against the .altinstructions.%%S and .altinstr_replacement sections:

diff --git c/xen/arch/x86/include/asm/alternative.h w/xen/arch/x86/include/asm/alternative.h
index 18109e3dc5..e871bfc04c 100644
--- c/xen/arch/x86/include/asm/alternative.h
+++ w/xen/arch/x86/include/asm/alternative.h
@@ -90,18 +90,25 @@ extern void alternative_instructions(void);
 /* alternative assembly primitive: */
 #define ALTERNATIVE(oldinstr, newinstr, feature)                      \
         OLDINSTR_1(oldinstr, 1)                                       \
-        ".pushsection .altinstructions, \"a\", @progbits\n"           \
+        ".reloc ., BFD_RELOC_NONE, 567f\n"                            \
+        ".reloc ., BFD_RELOC_NONE, 568f\n"                            \
+        ".pushsection .altinstructions.%%S, \"a\", @progbits\n"       \
+        "567:\n"                                                      \
         ALTINSTR_ENTRY(feature, 1)                                    \
         ".section .discard, \"a\", @progbits\n"                       \
         ".byte " alt_total_len "\n" /* total_len <= 255 */            \
         DISCARD_ENTRY(1)                                              \
         ".section .altinstr_replacement, \"ax\", @progbits\n"         \
+        "568:\n"                                                      \
         ALTINSTR_REPLACEMENT(newinstr, 1)                             \
         ".popsection\n"

--print-gc-sections shows a few .altinstructions.%%S dropped - as an example:

ld: removing unused section '.text.reserve_lapic_nmi' in file 'prelink.o'
ld: removing unused section '.text.release_lapic_nmi' in file 'prelink.o'
...
ld: removing unused section '.altinstructions..text.reserve_lapic_nmi' in file 'prelink.o' ld: removing unused section '.altinstructions..text.release_lapic_nmi' in file 'prelink.o'

The full list is below.

Unfortunately, EFI doesn't like it with ~14000 lines of:
ld: error: 0-bit reloc in dll

Also, my test of removing the path to memory_add() still doesn't drop memory_add().

There is still something wrong where I get a fault in some shadow code. I'm still investigating that.

Regards,
Jason


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.safe_copy_string_from_guest' 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.vm_event_cancel_slot' 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_destroy' 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.iommu_has_feature' in file 'prelink.o'
ld: removing unused section '.text.__erst_get_next_record_id' in file 'prelink.o'
ld: removing unused section '.text.__erst_read' in file 'prelink.o'
ld: removing unused section '.text.erst_get_record_count' in file 'prelink.o' ld: removing unused section '.text.erst_get_next_record_id' in file 'prelink.o'
ld: removing unused section '.text.erst_read' in file 'prelink.o'
ld: removing unused section '.text.erst_read_next' in file 'prelink.o'
ld: removing unused section '.text.erst_clear' 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 '.init.text.early_page_fault' in file 'prelink.o' ld: removing unused section '.text.domain_set_alloc_bitsize' in file 'prelink.o'
ld: removing unused section '.text.reserve_lapic_nmi' in file 'prelink.o'
ld: removing unused section '.text.release_lapic_nmi' 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 '.altinstructions..text.safe_copy_string_from_guest' in file 'prelink.o' ld: removing unused section '.rodata.xen_compile_host.str1.1' in file 'prelink.o' ld: removing unused section '.altinstructions..text.vm_event_cancel_slot' in file 'prelink.o' ld: removing unused section '.rodata.xmem_pool_destroy.str1.8' in file 'prelink.o' ld: removing unused section '.altinstructions..text.xmem_pool_destroy' in file 'prelink.o' ld: removing unused section '.rodata.elf_lookup_addr.str1.1' in file 'prelink.o' ld: removing unused section '.altinstructions..text.iommu_has_feature' in file 'prelink.o'
ld: removing unused section '.rodata.__erst_read.str1.8' in file 'prelink.o'
ld: removing unused section '.altinstructions..text.erst_get_record_count' in file 'prelink.o' ld: removing unused section '.altinstructions..text.erst_get_next_record_id' in file 'prelink.o' ld: removing unused section '.altinstructions..text.erst_read' in file 'prelink.o' ld: removing unused section '.altinstructions..text.erst_read_next' in file 'prelink.o' ld: removing unused section '.altinstructions..text.erst_clear' 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 '.altinstructions..text.reserve_lapic_nmi' in file 'prelink.o' ld: removing unused section '.altinstructions..text.release_lapic_nmi' in file 'prelink.o' ld: removing unused section '.data.rel.ro.local.fetch_type_names' in file 'prelink.o'
ld: removing unused section '.data.lapic_nmi_owner_lock' in file 'prelink.o'



 


Rackspace

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