From: Fangrui Song <maskray@google.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: libc-alpha@sourceware.org, Joseph Myers <joseph@codesourcery.com>
Subject: Re: [PATCH v4 2/5] elf: Properly handle zero DT_RELA/DT_REL values
Date: Tue, 1 Mar 2022 11:15:55 -0800 [thread overview]
Message-ID: <20220301191555.fbr6agyoe6glx5r2@google.com> (raw)
In-Reply-To: <20220301161706.185216-3-hjl.tools@gmail.com>
On 2022-03-01, 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.
>---
> 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 5318079bac..320a9029f2 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] \
>+ && (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..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)
>+
> # 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)
>--
>2.35.1
>
Reviewed-by: Fangrui Song <maskray@google.com>
next prev parent reply other threads:[~2022-03-01 19:16 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 16:17 [PATCH v4 0/5] Support DT_RELR relative relocation format H.J. Lu
2022-03-01 16:17 ` [PATCH v4 1/5] elf: Support DT_RELR relative relocation format [BZ #27924] H.J. Lu
2022-03-01 16:17 ` [PATCH v4 2/5] elf: Properly handle zero DT_RELA/DT_REL values H.J. Lu
2022-03-01 19:15 ` Fangrui Song [this message]
2022-03-01 16:17 ` [PATCH v4 3/5] Add GLIBC_ABI_DT_RELR for DT_RELR support H.J. Lu
2022-03-01 19:31 ` Fangrui Song
2022-03-01 22:33 ` H.J. Lu
2022-03-01 22:46 ` Fangrui Song
2022-03-01 22:56 ` H.J. Lu
2022-03-01 23:42 ` Peter O'Connor
2022-03-01 16:17 ` [PATCH v4 4/5] Add --disable-default-dt-relr H.J. Lu
2022-03-01 16:17 ` [PATCH v4 5/5] NEWS: Mention DT_RELR support H.J. Lu
2022-03-01 19:21 ` Fangrui Song
2022-03-01 22:37 ` H.J. Lu
2022-03-01 22:38 ` Fāng-ruì Sòng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220301191555.fbr6agyoe6glx5r2@google.com \
--to=maskray@google.com \
--cc=hjl.tools@gmail.com \
--cc=joseph@codesourcery.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).