From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id 524FF3858432 for ; Mon, 1 Nov 2021 16:44:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 524FF3858432 Received: by mail-oi1-x230.google.com with SMTP id x8so21459531oix.2 for ; Mon, 01 Nov 2021 09:44:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:from:to:references:in-reply-to :content-transfer-encoding; bh=KRARLrVspJ7tC42NCuagePVlhaCqmnOsVTfEImtipj0=; b=Jt4cuNNf8ggA0yVotjtQnY2nlzh/BL/XannZDw6+rCOAI14zUk/Zjfxek4iVMZ47XV dDikEDmufB/8Q87GNTH+1MP2bfIEf9aY//AWr0NGdF5NNkiin6c/Ik/Vs6jl0vIP2JsU 1znw6Qehk4IDQs/Y6jWYC9va2+oQDG52giPIoqcCCNiEc2pqW/oa+39vEBb1DlwFSZeu zG/szTA1dbzh6DcB8m+8VvPzmXFnQn/kFBRaZVr+l9HNxZIFHy/FvHYELXJjNgEnME1+ sR1rWIDgRBQh0BIxX4Um8bLtGXIAztjkBa80FtW6rYWnzLjBO5gZTwlkt7Ty3/nlNluY PVeQ== X-Gm-Message-State: AOAM532kkregIYE6EPhdq6h+SKM9D71cCzMA6T5XycDNwkjIYCVbsGj1 zcwfmghuq0YPgsWWHqjnq+hwx9KFVqpq5g== X-Google-Smtp-Source: ABdhPJxwLKDE+VMKIqMFXW5vpYetkB2shhd0rPuEA3HBKxpxFYHzZxJBZlw/F6sO5lGgv64LcdFdAQ== X-Received: by 2002:a05:6808:614:: with SMTP id y20mr14287oih.161.1635785045531; Mon, 01 Nov 2021 09:44:05 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:b64f:7c54:165f:8728:a193? ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id r21sm3528055otp.55.2021.11.01.09.44.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Nov 2021 09:44:05 -0700 (PDT) Message-ID: <6a6dee64-dd5e-e9d8-38fb-6e29165b466e@linaro.org> Date: Mon, 1 Nov 2021 13:44:03 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH 3/3] elf: Assume disjointed .rela.dyn and .rela.plt for loader Content-Language: en-US From: Adhemerval Zanella To: libc-alpha@sourceware.org, =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= , "H.J. Lu" References: <20211101125003.500945-1-adhemerval.zanella@linaro.org> <20211101125003.500945-4-adhemerval.zanella@linaro.org> In-Reply-To: <20211101125003.500945-4-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, 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 16:44:07 -0000 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 >