RFC: Three load segments patch (PR 30907) [version 2]
Nick Clifton
nickc@redhat.com
Wed Jun 12 15:40:37 GMT 2024
Hi Guys,
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. :-)
Cheers
Nick
PS. In addition to adding the new command line option the patch also
updates the ld/ld.int documentation file, adding descriptions of linker
scripts that were missing before. It also reorganises the
ld/scripttempl/elf.sc linker script template, making it easier to
understand how the sections are laid out. (At least that is my
opinion).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 3seg.patch
Type: text/x-patch
Size: 59373 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20240612/f17de2c7/attachment-0001.bin>
More information about the Binutils
mailing list