[PATCH v2] elf: Avoid nested functions in the loader (all ports) [BZ #27220]
Florian Weimer
fweimer@redhat.com
Thu Sep 23 17:40:05 GMT 2021
* Fāng-ruì Sòng:
> On Thu, Sep 23, 2021 at 10:13 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * Fāng-ruì Sòng:
>>
>> > For elf/dl-reloc.os on x86-64, I think the nested function version can
>> > use *(rbp - offset) to get some arguments.
>> > The new version needs more instructions but the cost is small compared
>> > with the expensive _dl_lookup_symbol_x.
>>
>> I have a patch that reduces the number of _dl_lookup_symbol_x calls for
>> the self-relocation (bootstrap or not):
>>
>> [v3,3/3] elf: Rework exception handling in the dynamic loader [BZ #25486]
>> <https://patchwork.sourceware.org/project/glibc/patch/05e1b5b43416eba58f2bab968320fa3d38e33479.1607085588.git.fweimer@redhat.com/>
>>
>> It needs rebase on the current tree.
>>
>> We recently lost the internal _r_debug reference, which is probably a
>> bug. Other architectures have some other crud in ld.so. But I think we
>> can get the number of symbols used in self-relocation down to zero on
>> all architectures fairly easily.
>>
>> Once we do that, how much of the bootstrap relocation goo is really
>> left?
>>
>> Thanks,
>> Florian
>>
>
> If self-relocations means relocations used in rtld.c and
> elf/dl-reloc-static-pie.o:
>
> The new version doesn't cause differences near _dl_lookup_symbol_x call sites.
> I think the relocation code sequence doesn't change.
>
> @@ -5757,7 +5789,7 @@
> push 0
> push 1
> call <L509>
> - 0000000000004ec7: R_X86_64_PLT32 _dl_lookup_symbol_x-0x4
> + 0000000000004f27: R_X86_64_PLT32 _dl_lookup_symbol_x-0x4
> <L509>:
> pop r8
> pop r9
>
> The new rtld.os is slightly larger, but I guess that it is just
> because GCC inlines one more place.
What I meant is that we can toss out a lot of the self-relocation code
once we *know* that we don't need to call _dl_lookup_symbol_x because no
relocations use symbols.
Thanks,
Florian
More information about the Libc-alpha
mailing list