From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 48EC03876053 for ; Tue, 29 Mar 2022 22:31:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 48EC03876053 Received: by mail-pl1-x62d.google.com with SMTP id c23so18931109plo.0 for ; Tue, 29 Mar 2022 15:31:25 -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=+ZPyEIkMYZ5YqZs+iKMeaF2dhgHSJibtzoN0Nfg105w=; b=Kw9YQY1Jk/IqrHutO7mMxYPeTr1e/pFVds7Y8nEra9s9Itaqy5LfDLS98vwH4kFIDt LdsVY7hdcGZtVsgMdAgphov7eGyYiuSKvjiWOyzakZv46k49tNL5It//sqHRhKNFKqgP QIYjGGVHfcKare40vwVJe6/zwZ5ckFpKJFwuCPyFO+D+76QUoQw3sUolAPYiXBiHwDNv LJ1a9JVrCRHKSkjetFDM346lX+y+1+EK7ekObZTLYI4rE7j3J7YkQ8nc8WfmU7UMvSAk 7suieO2QB+R2OmuSTBmMP7okBG13xPIK4UiLGRY6IG0WlHZ75aob3Sai2kl2wgVKPlVr 2PQw== X-Gm-Message-State: AOAM530gaW5BnNizDZrSOXOi3bhTPNhwAY182W/TMW2w7gPR4YM8Ls65 L1243MiyEsp9BjImcMtdt7em8xH83n9EUAAmmHI= X-Google-Smtp-Source: ABdhPJwnsEY9WLzCW6zW5dBuWY5/7jB1YsyRcbKG6ax2NOxlE4mPJaYCiUY4grEIARcKyPUEA4ZMp5vJcMWBUNk+t8Y= X-Received: by 2002:a17:90b:4c41:b0:1c7:3fa8:9b6a with SMTP id np1-20020a17090b4c4100b001c73fa89b6amr1422421pjb.120.1648593084323; Tue, 29 Mar 2022 15:31:24 -0700 (PDT) MIME-Version: 1.0 References: <20220310200329.1935466-1-hjl.tools@gmail.com> <20220310200329.1935466-3-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Tue, 29 Mar 2022 15:30:48 -0700 Message-ID: Subject: Re: [PATCH v6 2/5] elf: Properly handle zero DT_RELA/DT_REL values To: Adhemerval Zanella Cc: GNU C Library , Joseph Myers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3025.9 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, 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 22:31:27 -0000 On Tue, Mar 29, 2022 at 9:38 AM Adhemerval Zanella wrote: > > > > 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. Fixed in v7. > > + && (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. Fixed in v7. > > # 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. Thanks. -- H.J.