From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 544B03858C50 for ; Tue, 29 Mar 2022 16:38:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 544B03858C50 Received: by mail-oi1-x22b.google.com with SMTP id k10so19618812oia.0 for ; Tue, 29 Mar 2022 09:38:46 -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:to:references:cc:from:in-reply-to :content-transfer-encoding; bh=gE8bh7iuTaWPkuc+ptBnp6BuNrJikheA1VTYTRpMYXU=; b=NFYrRjr+A78VI7m6uacgql0AUpvymLHESJ6siVYNdNnQTjhGJkE/TexMCZn3evnFXT KTiSYwZyn55IgJASQpdZaG+5MiTOScfNeXynj6kUGQ8XYyauhUf1HUEBtkvfyqJPlcE9 6uwCTU3O49AkY8lTHYvCUvHcLBNzaEpvN28L1QAMPgqntlGMYHnEwxiYnTPTfbTy6L3i NagDIh98J1aPXg2a+Euxed00+RKD4XehfhtVr6bhwEqo7iRFUXLH4PSrPtJOV4cVLv+1 SWGyXt3WpTwb7Nol8EfyqiLRd3E6ZJi/RlLys2E+hvAltZNJovNy+pFXKDiwXEQUKvoP C6Hw== X-Gm-Message-State: AOAM5301ge/o+RSfeth8H2UxdWdNLk/mQvwMyoGJJ+Y+g8Iq82cPMuIM MhPBayg5F4U4YV+xE/Vjf7+dbEqZgBAqRg== X-Google-Smtp-Source: ABdhPJxcPJjhblHFoiENQNsGEMO1++duKt7B+i5/AYhkv4Dfu73snie6xklcaokM6F8RtTQYhD9ZwA== X-Received: by 2002:a05:6808:1b11:b0:2da:73df:2dbd with SMTP id bx17-20020a0568081b1100b002da73df2dbdmr252387oib.293.1648571924480; Tue, 29 Mar 2022 09:38:44 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:a6c0:f1e1:dcf6:8c18:df3b? ([2804:431:c7cb:a6c0:f1e1:dcf6:8c18:df3b]) by smtp.gmail.com with ESMTPSA id 184-20020a4a03c1000000b003240492fc15sm8856748ooi.36.2022.03.29.09.38.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Mar 2022 09:38:44 -0700 (PDT) Message-ID: Date: Tue, 29 Mar 2022 13:38:41 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v6 2/5] elf: Properly handle zero DT_RELA/DT_REL values Content-Language: en-US To: libc-alpha@sourceware.org, "H.J. Lu" References: <20220310200329.1935466-1-hjl.tools@gmail.com> <20220310200329.1935466-3-hjl.tools@gmail.com> Cc: Joseph Myers From: Adhemerval Zanella In-Reply-To: <20220310200329.1935466-3-hjl.tools@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.3 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, T_SCC_BODY_TEXT_LINE 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: Tue, 29 Mar 2022 16:38:48 -0000 On 10/03/2022 17:03, H.J. Lu via Libc-alpha wrote: > With DT_RELR, there may be no relocations in DT_RELA/DT_REL and their > entry values are zero. Don't relocate DT_RELA/DT_REL and update the > combined relocation start address if their entry values are zero. Patch looks good with the two small fixes below. Reviewed-by: Adhemerval Zanella > --- > elf/dynamic-link.h | 6 +++++- > elf/get-dynamic-info.h | 18 ++++++++++++++---- > 2 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h > index d04c457e55..252f407a12 100644 > --- a/elf/dynamic-link.h > +++ b/elf/dynamic-link.h > @@ -84,7 +84,9 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], > __typeof (((ElfW(Dyn) *) 0)->d_un.d_val) nrelative; int lazy; } \ > ranges[2] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; \ > \ > - if ((map)->l_info[DT_##RELOC]) \ > + /* With DT_RELR, DT_RELA/DT_REL can have zero value. */ \ > + if ((map)->l_info[DT_##RELOC] \ Compare to NULL here. > + && (map)->l_info[DT_##RELOC]->d_un.d_ptr != 0) \ > { \ > ranges[0].start = D_PTR ((map), l_info[DT_##RELOC]); \ > ranges[0].size = (map)->l_info[DT_##RELOC##SZ]->d_un.d_val; \ > @@ -98,6 +100,8 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], > ElfW(Addr) start = D_PTR ((map), l_info[DT_JMPREL]); \ > ElfW(Addr) size = (map)->l_info[DT_PLTRELSZ]->d_un.d_val; \ > \ > + if (ranges[0].start == 0) \ > + ranges[0].start = start; \ > if (ranges[0].start + ranges[0].size == (start + size)) \ > ranges[0].size -= size; \ > if (!(do_lazy) \ Ok. > diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h > index 6c2a3a12b1..f4b957684b 100644 > --- a/elf/get-dynamic-info.h > +++ b/elf/get-dynamic-info.h > @@ -83,16 +83,26 @@ elf_get_dynamic_info (struct link_map *l, bool bootstrap, > ADJUST_DYN_INFO (DT_PLTGOT); > ADJUST_DYN_INFO (DT_STRTAB); > ADJUST_DYN_INFO (DT_SYMTAB); > + ADJUST_DYN_INFO (DT_RELR); > + ADJUST_DYN_INFO (DT_JMPREL); > + ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM)); > + ADJUST_DYN_INFO (ADDRIDX (DT_GNU_HASH)); > +# undef ADJUST_DYN_INFO > + > + /* DT_RELA/DT_REL are mandatory. But they may have zero value if > + there is DT_RELR. Don't relocate them if they are zero. */ > +# define ADJUST_DYN_INFO(tag) \ > + do \ > + if (info[tag] != NULL && info[tag]->d_un.d_ptr != 0) \ > + info[tag]->d_un.d_ptr += l_addr; \ > + while (0) > + Maybe use '{' and '}' on the do ... while. > # if ! ELF_MACHINE_NO_RELA > ADJUST_DYN_INFO (DT_RELA); > # endif > # if ! ELF_MACHINE_NO_REL > ADJUST_DYN_INFO (DT_REL); > # endif > - ADJUST_DYN_INFO (DT_RELR); > - ADJUST_DYN_INFO (DT_JMPREL); > - ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM)); > - ADJUST_DYN_INFO (ADDRIDX (DT_GNU_HASH)); > # undef ADJUST_DYN_INFO > } > if (info[DT_PLTREL] != NULL) Ok.