RFC: Three load segments patch (PR 30907) [version 2]

Jan Beulich jbeulich@suse.com
Thu Jun 13 06:10:02 GMT 2024


On 12.06.2024 17:40, Nick Clifton wrote:
>   I have been looking into the file size increase when we link binaries
>   with '-z separate-code' enabled.  The problem is that we end up
>   creating four load segments with page aligning happening between them.
>   For example linking a small hello-world type program gives:
> 
>   with: -z noseparate-code  (file size: 8544 bytes)
> 
>           File Offset  Virt Addr  FileSize Flags  Align
>     LOAD      0         400000      6d4     R E    0x1000 
>     LOAD    df8         401df8      228     RW     0x1000
> 
>   with: -z separate-code  (file size: 16736 bytes)
> 
>           File Offset  Virt Addr  FileSize Flags  Align
>     LOAD      0         400000      510     R      0x1000
>     LOAD   1000         401000      155     R E    0x1000
>     LOAD   2000         402000       dc     R      0x1000
>     LOAD   2df8         403df8      228     RW     0x1000
> 
>   The increase in size is unfortunate, and a problem for distributions,
>   where larger binary sizes equates to larger install images and more
>   download bandwidth, and the problem is even more accute for containers.
> 
>   So attached is a proposed patch to add an option that combines the two
>   read-only segments into one.  It moves the first code segment to the
>   start of the file, followed by a read only segment and then a read
>   write segment.  Thus we end up with a layout like this:
> 
>   with: -z separate-code -z one-rosegment  (file size: 8544 bytes)
> 
>           File Offset  Virt Addr  FileSize Flags  Align
>     LOAD      0         400000      435     R E    0x1000
>     LOAD    435         401435      2d7     R      0x1000
>     LOAD    df8         402df8      228     RW     0x1000
> 
>   The section mapping looks like this:
> 
>      02     .init .plt .text .fini 
>      03     .interp .note.gnu.property .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .rodata .eh_frame_hdr .eh_frame 
>      04     .init_array .fini_array .dynamic .got .got.plt .data .bss 
> 
>   The patch is incomplete.  It does not have any test cases or
>   full documentation at the moment, but I wanted to see if I am on the
>   right track this time, or if I need to go back to the drawing board
>   again. :-)

FWIW, the result of your change addresses my earlier concern. (I didn't
look closely at the implementation, though.)

Thanks for the re-work, Jan


More information about the Binutils mailing list