From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 76BDA3858432 for ; Mon, 1 Nov 2021 17:17:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 76BDA3858432 Received: by mail-pg1-x52a.google.com with SMTP id s136so17745332pgs.4 for ; Mon, 01 Nov 2021 10:17:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=F6T+6UFX1q+0OTORuq/YJP8V04Kmvenj0zzSKp13icE=; b=uXi4MgGXCRgVilZ+IdZwXLCDOqxOf52yXWrMb0pSLcb6dn1HZeMbOt2LvXRHPUoYeL /1OUZadTioPdU//SOMmF8YvOnVGnToDUP5qUeUfTIsSrhX9vQYO7b1Nsx6gUKL/l8Fn3 2KJMnKLtPYSlfwp/kJKZeFt/kTBOYTKKZqaD+67GZeuojyjiecsMd1T3K7GXJdNvbm23 6Xx3Un7OK0hHb77VTtBC9jgrVq/f2ndX81xI4857LVWIXqjmAxk0XXwLlCiZrCX7HWfR 0VhLqzzjHr6aJUjHlesGkn75yGNN9HBs3Novjs/c7lXDabZhIJy4nir22Niv87GYv8v+ nqVg== X-Gm-Message-State: AOAM532Iqbu31GOoU+JTzFULwxrPKRb6NRVOcyyGOD8FXvW8p9aaixbl AMOaYzycPFIZRZlFQaUYqmS3k66Ey6cJSoTtPfmM+36x X-Google-Smtp-Source: ABdhPJx8HACFHyDGMsm159vcsIg8LG//6u1S5sLVHtfYzzLMpPE7HrrfDhn+ggt8ypmKmr9An90cMsmp4J6GW0Cyx1s= X-Received: by 2002:a62:1707:0:b0:480:f85a:f3b0 with SMTP id 7-20020a621707000000b00480f85af3b0mr13430223pfx.43.1635787035561; Mon, 01 Nov 2021 10:17:15 -0700 (PDT) MIME-Version: 1.0 References: <20211101125003.500945-1-adhemerval.zanella@linaro.org> <20211101125003.500945-4-adhemerval.zanella@linaro.org> <6a6dee64-dd5e-e9d8-38fb-6e29165b466e@linaro.org> In-Reply-To: <6a6dee64-dd5e-e9d8-38fb-6e29165b466e@linaro.org> From: "H.J. Lu" Date: Mon, 1 Nov 2021 10:16:39 -0700 Message-ID: Subject: Re: [PATCH 3/3] elf: Assume disjointed .rela.dyn and .rela.plt for loader To: Adhemerval Zanella Cc: GNU C Library , =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3029.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Nov 2021 17:17:18 -0000 On Mon, Nov 1, 2021 at 9:44 AM Adhemerval Zanella wrote: > > > > On 01/11/2021 09:50, Adhemerval Zanella wrote: > > The linker might add another section between the two relocation section > > for the loader as well. For instance on arm, lld does: > > > > [ 7] .rel.dyn REL 000007f0 0007f0 000088 08 A 1 0 4 > > [ 8] .ARM.exidx ARM_EXIDX 00000878 000878 0000b0 00 AL1 2 0 4 > > [ 9] .rel.plt REL 00000928 000928 000028 08 AI 1 17 4 > > > > This patch removes the ELF_DURING_STARTUP optimization and assume > > both section might no be linear. > > > > Checked on x86_64, i686, aarch64, armhf, powerpc64le, powerpc64, > > and powerpc (to check if this breaks on different architectures). > > Following up the discussion on glibc call, below it an update of the > patch description. > > --- > > The patch removes the the ELF_DURING_STARTUP optimization and assume > both .rel.dyn and .rel.plt might no be linear. This allows some > code simplification since relocation will be handled independently > where it done on bootstrap. > > I could not see any performance implications, at least on x86_64. > Running 10000 time the command > > LD_DEBUG=statistics ./elf/ld.so ./libc.so > > And filtering the "total startup time in dynamic loader" result, > the geometric mean I see are: > > patched master > Ryzen 7 5900x 24140 24952 > i7-4510U 45957 45982 > > (the results do show some variation, I did not make any statistical > analysis). > > It also allows build arm with lld, since it inserts ".ARM.exidx" > between ".rel.dyn" and ".rel.plt" for the loader. > > Checked on x86_64-linux-gnu and arm-linux-gnueabihf. > > > --- > > elf/dynamic-link.h | 32 +++++++++----------------------- > > 1 file changed, 9 insertions(+), 23 deletions(-) > > > > diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h > > index ac4cc70dea..f619615e5c 100644 > > --- a/elf/dynamic-link.h > > +++ b/elf/dynamic-link.h > > @@ -65,12 +65,6 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], > > > > #ifdef RESOLVE_MAP > > > > -# if defined RTLD_BOOTSTRAP || defined STATIC_PIE_BOOTSTRAP > > -# define ELF_DURING_STARTUP (1) > > -# else > > -# define ELF_DURING_STARTUP (0) > > -# endif > > - > > /* Get the definitions of `elf_dynamic_do_rel' and `elf_dynamic_do_rela'. > > These functions are almost identical, so we use cpp magic to avoid > > duplicating their code. It cannot be done in a more general function > > @@ -106,9 +100,8 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], > > \ > > if (ranges[0].start + ranges[0].size == (start + size)) \ > > ranges[0].size -= size; \ > > - if (ELF_DURING_STARTUP \ > > - || (!(do_lazy) \ > > - && (ranges[0].start + ranges[0].size) == start)) \ > > + if (!(do_lazy) \ > > + && (ranges[0].start + ranges[0].size) == start) \ > > { \ > > /* Combine processing the sections. */ \ > > ranges[0].size += size; \ > > @@ -121,20 +114,13 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], > > } \ > > } \ > > \ > > - if (ELF_DURING_STARTUP) \ > > - elf_dynamic_do_##reloc ((map), scope, ranges[0].start, ranges[0].size, \ > > - ranges[0].nrelative, 0, skip_ifunc); \ > > - else \ > > - { \ > > - int ranges_index; \ > > - for (ranges_index = 0; ranges_index < 2; ++ranges_index) \ > > - elf_dynamic_do_##reloc ((map), scope, \ > > - ranges[ranges_index].start, \ > > - ranges[ranges_index].size, \ > > - ranges[ranges_index].nrelative, \ > > - ranges[ranges_index].lazy, \ > > - skip_ifunc); \ > > - } \ > > + for (int ranges_index = 0; ranges_index < 2; ++ranges_index) \ > > + elf_dynamic_do_##reloc ((map), scope, \ > > + ranges[ranges_index].start, \ > > + ranges[ranges_index].size, \ > > + ranges[ranges_index].nrelative, \ > > + ranges[ranges_index].lazy, \ > > + skip_ifunc); \ > > } while (0) > > > > # if ELF_MACHINE_NO_REL || ELF_MACHINE_NO_RELA > > Please submit the v2 patch with the updated commit log. Thanks. -- H.J.