From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by sourceware.org (Postfix) with ESMTPS id D7F053858D1E for ; Wed, 20 Apr 2022 17:10:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D7F053858D1E Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-e2a00f2cc8so2627366fac.4 for ; Wed, 20 Apr 2022 10:10:29 -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:cc:references:from:in-reply-to :content-transfer-encoding; bh=0BF5egTfLC+dGgrnEKRSe0IJGNWFjteNHsSpq8XmdkI=; b=Wke9DmYgsLpO/h0UMQ98vzdu4zssNCMykVpMwESchF8oTrP5CB4lM24PXo/JGM/Df2 pWYq0t6WMyOvACgVHfWRT/dH3TB9xf0HOPyEhirLK9tprzPDLrkpDk2ZyFYkNSxQAzy4 0bP16LMf07v+79i/INwSmSfAtgXOrRPGqmQBT85U8zDP+6hTwhmm4+2IviImZ52Ez3jI GGrQzBPTMaQAU1nJ/FDqklpwRjA6vq9l4N2uhYwtwSQIZQrHjKAah6CyKxTfb/DTG8CN Ndih9FdVd/49GWMuI3nJhu8uMdqyYRzmDwweFP1ezb1t3G+BZe7m6qSFcEK5We2+tMnO laGg== X-Gm-Message-State: AOAM533S1DNpsYFMGLQHLCzi3CyHOFNtqt+mc2JnWSke5RPVRqxDZbxu pU2Mg2TVV/V87IEToN6nOdQb7A== X-Google-Smtp-Source: ABdhPJxJlCl8Vg+9/WiqOE/lpJpGX6EXsei4LsncNC6TrmkCaEdr6bknS88pXaJJ7aPrgWXczYGoHw== X-Received: by 2002:a05:6870:4414:b0:e6:244f:78ba with SMTP id u20-20020a056870441400b000e6244f78bamr1968512oah.201.1650474628830; Wed, 20 Apr 2022 10:10:28 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:c9d0:24b1:bd98:2ef4:714c? ([2804:431:c7ca:c9d0:24b1:bd98:2ef4:714c]) by smtp.gmail.com with ESMTPSA id l14-20020a4ac60e000000b0032993003287sm6901225ooq.38.2022.04.20.10.10.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Apr 2022 10:10:28 -0700 (PDT) Message-ID: <30dcab10-4d13-2c0b-f9dd-a1484be4690e@linaro.org> Date: Wed, 20 Apr 2022 14:10:25 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v10 4/7] elf: Properly handle zero DT_RELA/DT_REL values Content-Language: en-US To: "H.J. Lu" , libc-alpha@sourceware.org References: <20220414232129.1886210-1-hjl.tools@gmail.com> <20220414232129.1886210-5-hjl.tools@gmail.com> From: Adhemerval Zanella In-Reply-To: <20220414232129.1886210-5-hjl.tools@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.9 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: Wed, 20 Apr 2022 17:10:31 -0000 On 14/04/2022 20:21, H.J. Lu 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. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > elf/dynamic-link.h | 6 +++++- > elf/get-dynamic-info.h | 24 ++++++++++++++++++------ > 2 files changed, 23 insertions(+), 7 deletions(-) > > diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h > index 7325e0d9fc..7dd8f1b1d6 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] != NULL \ > + && (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) \ > diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h > index 6c2a3a12b1..0314baf020 100644 > --- a/elf/get-dynamic-info.h > +++ b/elf/get-dynamic-info.h > @@ -75,24 +75,36 @@ elf_get_dynamic_info (struct link_map *l, bool bootstrap, > > # define ADJUST_DYN_INFO(tag) \ > do \ > - if (info[tag] != NULL) \ > - info[tag]->d_un.d_ptr += l_addr; \ > + { \ > + if (info[tag] != NULL) \ > + info[tag]->d_un.d_ptr += l_addr; \ > + } \ > while (0) > > ADJUST_DYN_INFO (DT_HASH); > 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) > + > # 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)