On 05/12/2025 10:28 pm, 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.

Yes, .altinstructions contains relocations against the origin patch
site, which will cause it to appear to be referenced. The same will be
happening with a bunch of other sections.

Hmm.  We are surely not the first people to encounter this.

> Signed-off-by: Jason Andryuk <[email protected]>
> ---
> 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'

This is for your safety stripped-down build, I'm guessing?

It's certainly a good start.

> diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
> index 527872a6db..e3ad58f688 100644
> --- a/xen/arch/x86/xen.lds.S
> +++ b/xen/arch/x86/xen.lds.S
> @@ -98,7 +98,7 @@ SECTIONS
>  #endif
>         *(.text.__x86_indirect_thunk_*)
>  
> -       *(.fixup)
> +       KEEP(*(.fixup))

Why do we need to KEEP() this?  The references here are the other way
around to most examples.

Although I note that removing .fixup is on the cleanup list, and would
this problem too.

~Andrew

Reply via email to