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

Re: [PATCH] x86: fold sections in final binaries


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Tue, 1 Mar 2022 13:30:02 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=0QJG6lUHRRR5Bx3rjh8fSAN00goQWZPELfVy7v1+b2g=; b=g/wBM+R9+ZkxQuGJKz3t0XsQmgoqtv4unBhXtsDFuYVQOCtT6PoYIc8d+lDKLs1R/nzGmeI1sP+jS0qsrIc/wJ+Vn6gWbyhPbOE/g2QIyHPtN1srAUWlASiXOB9kDsaVH8kJVRzbcVxVKG//j0N/haM1FhMSvxOb53tkC6vHEUN9eus6m+AiwytXFUoX+Zz2Ra4gwa76jjRJrnH65CS0+/0t1Akro21zwKFzNUS9xDjuGhzgsiZIv5t1UhqscMMue+o8Ic4JnvZCIFNLqyq84xpTf4qDpn23baGPnv5EXmyo1ASPSu1YpxqdjfVBbK053eO8obraiLlP8a8S4bpOJw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XfdY3iVlxJxOxz1M/69x0h5civqz40qpLF7kjNK/dFl7xl4TDGfpEFdQQJyd5JUeHqZrt4I2vcTMrEpkq6XbnI2ETeEaChxF4uowJrG3wLM136sQ95DsXIIooZ8O3LQEjjczPAZ3vRbAuhx9kO8BHCpEj0ingg2fRnucMEC/6kOx2xwNtytStxKQi4cZNs/DD1KymRdmcb0g2ph7owgw6JRLmApyeAa2ZnCX5eeu/68SSx/gFM6BKa3BQ5zXM0vfx4lN4ME1qhzFaMki+biIs3OCb0cc+X7JyKz+XLaFwPnhxZCEMtKuZxsTc0ii+42NAQ1jXHCcR13AQEmtk1S+UQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 01 Mar 2022 13:30:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYLUowkdMxBaiHpEebmldzPiiqI6yqOnQAgABL34A=
  • Thread-topic: [PATCH] x86: fold sections in final binaries

Hi Jan,

> On 1 Mar 2022, at 08:58, Jan Beulich <jbeulich@xxxxxxxx> wrote:
> 
> On 01.03.2022 09:55, Jan Beulich wrote:
>> 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>
> 
> Some of this will likely want mirroring to Arm as well, even if xen.efi
> there isn't produced by the linker. Sections are better properly folded
> even for ELF, and constructors not ending up in [__ctors_start,__ctors_end)
> can surely not do any good.

I fully agree with that and it would make sense to do both changes together to
avoid differences between x86 and arm unless required.

Right now our discard section on arm is a lot shorter and I do not see why we
would need any of the sections that are discarded on x86.

As this needs testing and checking I do not think it makes sense for you to do
that right now.
@Stefano and Julien: I am ok to create myself a task to sync with x86 in the
 next weeks/months, what do you think ?

Cheers
Bertrand

> 
> Jan
> 
>> ---
>> TBD: We also use CONSTRUCTORS for an unknown reason. Documentation for
>>     ld is quite clear that this is an a.out-only construct.
>>     Implementation doesn't look to fully match this for ELF, but I'd
>>     nevertheless be inclined to remove its use.
>> 
>> --- 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
>>   }




 


Rackspace

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