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

[xen staging] x86: fold sections in final binaries



commit 4b7fd8153ddfe95d6d427ff241abb6fdf37e027b
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Wed Mar 2 09:29:55 2022 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Mar 2 09:29:55 2022 +0100

    x86: fold sections in final binaries
    
    Especially when linking a PE binary (xen.efi), standalone output
    sections are expensive: Often the linker will align the subsequent one
    on the section alignment boundary (2Mb) when the linker script doesn't
    otherwise place it. (I haven't been able to derive from observed
    behavior under what conditions it would not do so.)
    
    With gcov enabled (and with gcc11) I'm observing enough sections that,
    as of quite recently, the resulting image doesn't fit in 16Mb anymore,
    failing the final ASSERT() in the linker script. (That assertion is
    slated to go away, but that's a separate change.)
    
    Any destructor related sections can be discarded, as we never "exit"
    the hypervisor. This includes .text.exit, which is referenced from
    .dtors.*. Constructor related sections need to all be taken care of, not
    just those with historically used names: .ctors.* and .text.startup is
    what gcc11 populates. While there re-arrange ordering / sorting to match
    that used by the linker provided scripts.
    
    Finally, for xen.efi only, also discard .note.gnu.*. These are
    meaningless in a PE binary. Quite likely, while not meaningless there,
    the section is also of no use in ELF, but keep it there for now.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 xen/arch/x86/xen.lds.S | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 7b655df63f..83def6541e 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -194,6 +194,7 @@ SECTIONS
 #endif
        _sinittext = .;
        *(.init.text)
+       *(.text.startup)
        _einittext = .;
        /*
         * Here are the replacement instructions. The linker sticks them
@@ -258,9 +259,10 @@ SECTIONS
 
        . = ALIGN(8);
        __ctors_start = .;
-       *(.ctors)
+       *(SORT_BY_INIT_PRIORITY(.init_array.*))
+       *(SORT_BY_INIT_PRIORITY(.ctors.*))
        *(.init_array)
-       *(SORT(.init_array.*))
+       *(.ctors)
        __ctors_end = .;
   } PHDR(text)
 
@@ -404,16 +406,20 @@ SECTIONS
 
   /* Sections to be discarded */
   /DISCARD/ : {
+       *(.text.exit)
        *(.exit.text)
        *(.exit.data)
        *(.exitcall.exit)
        *(.discard)
        *(.discard.*)
        *(.eh_frame)
+       *(.dtors)
+       *(.dtors.*)
 #ifdef EFI
        *(.comment)
        *(.comment.*)
        *(.note.Xen)
+       *(.note.gnu.*)
 #endif
   }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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