tech-userlevel archive

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

Re: dynamic linker change to handle multiple PT_LOAD segments



On 1/6/23 1:53 AM, Christos Zoulas wrote:
>
Our dynamic linker ld_elf.so in map_object.c currently can only handle 2 PT_LOAD segments (one for text and one for data); the kernel elf loader does not have this limitation, it can load multiple PT_LOAD segment. The following patch (from FreeBSD) removes this limitation from the dynamic linker. The reason I made this patch now is that the latest binutils (2.39) for amd64 sets a maxinum pagesize of 2Mb, and when using relocation read only binaries (ld -z relro) this will cause the binaries to have an extra 2Mbytes for alignment. This can be fixed by building binutils to set a separate code segment by default (ld -z separate-code). Binutils then sets the maximum page size to 4Kb. Setting this option creates 4 PT_LOAD segments, two for text (r--, r-x) and two for data (r--, rw-), which also improves security. This is the default for linux on x86 and the patch also makes it the default for NetBSD x86. The patch also adds -z noseparate-code to the kernel builds so that we don't need to fix the boot loaders. I am planning to commit this soon, so please let me know if you hsve any objections.

Yes please! I've been tired of BFD ld running so slow and eating up all the memory, and have been seeking for a good alternative. mold[1] looks very promising but it tends to produce more than two PT_LOADs so we can't use it right now.

[1] https://github.com/rui314/mold


Home | Main Index | Thread Index | Old Index