[PATCH 10/10] ld: Add glibc dependency for DT_RELR
H.J. Lu
hjl.tools@gmail.com
Sat Jan 8 18:37:44 GMT 2022
On Sat, Jan 8, 2022 at 12:19 AM Fangrui Song <i@maskray.me> wrote:
>
> On 2022-01-07, H.J. Lu wrote:
> >On Fri, Jan 7, 2022 at 8:43 PM Fangrui Song <i@maskray.me> wrote:
> >>
> >> On 2022-01-07, H.J. Lu via Binutils wrote:
> >> >When DT_RELR is enabled, to avoid random run-time crash with older glibc
> >> >binaries without DT_RELR support, add a GLIBC_ABI_DT_RELR symbol version,
> >> >which is provided by glibc with DT_RELR support, dependency on the shared
> >> >C library if it provides a GLIBC_2.XX symbol version.
> >> >
> >> >bfd/
> >> >
> >> > * elflink.c (elf_link_add_dt_relr_dependency): New function.
> >> > (bfd_elf_size_dynamic_sections): Call
> >> > elf_link_add_dt_relr_dependency if DT_RELR is enabled.
> >> >
> >> >ld/
> >> >
> >> > * ld.texi: Mention GLIBC_ABI_DT_RELR in -z pack-relative-relocs
> >> > entry.
> >> > * testsuite/ld-elf/dt-relr-glibc-1.c: New file.
> >> > * testsuite/ld-elf/dt-relr-glibc-1a.rd: Likewise.
> >> > * testsuite/ld-elf/dt-relr-glibc-1b.rd: Likewise.
> >> > * testsuite/ld-elf/dt-relr.exp: Likewise.
> >> >---
> >> > bfd/elflink.c | 86 +++++++++++++++++++++++++
> >> > ld/ld.texi | 4 +-
> >> > ld/testsuite/ld-elf/dt-relr-glibc-1.c | 11 ++++
> >> > ld/testsuite/ld-elf/dt-relr-glibc-1a.rd | 4 ++
> >> > ld/testsuite/ld-elf/dt-relr-glibc-1b.rd | 7 ++
> >> > ld/testsuite/ld-elf/dt-relr.exp | 44 +++++++++++++
> >> > 6 files changed, 155 insertions(+), 1 deletion(-)
> >> > create mode 100644 ld/testsuite/ld-elf/dt-relr-glibc-1.c
> >> > create mode 100644 ld/testsuite/ld-elf/dt-relr-glibc-1a.rd
> >> > create mode 100644 ld/testsuite/ld-elf/dt-relr-glibc-1b.rd
> >> > create mode 100644 ld/testsuite/ld-elf/dt-relr.exp
> >> >
> >> >diff --git a/bfd/elflink.c b/bfd/elflink.c
> >> >index 31b13f5df7a..05ac1cb7a63 100644
> >> >--- a/bfd/elflink.c
> >> >+++ b/bfd/elflink.c
> >> >@@ -2213,6 +2213,85 @@ _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
> >> > return true;
> >> > }
> >> >
> >> >+/* Return true if GLIBC_ABI_DT_RELR is added to the list of version
> >> >+ dependencies successfully. GLIBC_ABI_DT_RELR will be put into the
> >> >+ .gnu.version_r section. */
> >> >+
> >> >+static bool
> >> >+elf_link_add_dt_relr_dependency (struct elf_find_verdep_info *rinfo)
> >> >+{
> >> >+ bfd *glibc_bfd = NULL;
> >> >+ Elf_Internal_Verneed *t;
> >> >+ Elf_Internal_Vernaux *a;
> >> >+ size_t amt;
> >> >+ const char *relr = "GLIBC_ABI_DT_RELR";
> >> >+
> >> >+ /* See if we already know about GLIBC_PRIVATE_DT_RELR. */
> >> >+ for (t = elf_tdata (rinfo->info->output_bfd)->verref;
> >> >+ t != NULL;
> >> >+ t = t->vn_nextref)
> >> >+ {
> >> >+ const char *soname = bfd_elf_get_dt_soname (t->vn_bfd);
> >> >+ /* Skip the shared library if it isn't libc.so. */
> >> >+ if (!soname || !startswith (soname, "libc.so."))
> >> >+ continue;
> >>
> >> Having the dependency on ld.so is better.
> >> (The linker knows the --dynamic-linker value.)
> >> libc.so does not need to know whether DT_RELR is used.
> >>
> >> It's also easier on glibc side.
> >> Defining __glibc_abi_dt_relr@@GLIBC_ABI_DT_RELR in elf/Versions is
> >> simpler than defining it in libc.so and updating every libc.abilist.
> >
> >I chose libc.so instead of ld.so since shared libraries may
> >not be linked against ld.so. The glibc change can be simple:
> >
> >https://patchwork.sourceware.org/project/glibc/patch/20211123223053.3334224-1-hjl.tools@gmail.com/
> >
> >Please replace GLIBC_ABI_VERSION_GEN2 with
> >GLIBC_ABI_DT_RELR.
> >
> >or like
> >
> >https://gitlab.com/x86-glibc/glibc/-/commit/3bc53baa5304855b5105dabd7726b23d454605fb
> >
> >I can go either way.
>
> OK... I picked the first way:
> https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/maskray/relr
Here it is:
https://gitlab.com/x86-glibc/glibc/-/commit/0cef25a4c61f39355224c13ae4f5c15f036659f7
--
H.J.
More information about the Libc-alpha
mailing list