[PATCH v4] ld.so: Replace DL_RO_DYN_SECTION with dl_relocate_ld
H.J. Lu
hjl.tools@gmail.com
Thu Sep 23 15:47:36 GMT 2021
On Thu, Sep 23, 2021 at 3:22 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > We can't relocate entries in dynamic section if it is readonly:
> >
> > 1. Add a l_ld_readonly field to struct link_map to indicate if dynamic
> > section is readonly and set it based on p_flags of PT_DYNAMIC segment.
> > 2. Replace DL_RO_DYN_SECTION with dl_relocate_ld to decide if dynamic
> > section should be relocated.
> > 3. Remove DL_RO_DYN_TEMP_CNT.
> > 4. Don't use a static dynamic section to make readonly dynamic section
> > in vDSO writable.
> > 5. Remove the temp argument from elf_get_dynamic_info.
>
> Sorry, this does not appear to work: For !DONT_USE_BOOTSTRAP_MAP,
> bootstrap_map.l_ld_readonly is not initialized during the initial
> self-relocation. This is visible as a valgrind failure on
> powerpc64le-linux-gnu:
>
> + /builddir/build/BUILDROOT/glibc-2.34.9000-9.fc36.ppc64le/lib64/ld64.so.2 --library-path /builddir/build/BUILDROOT/glibc-2.34.9000-9.fc36.ppc64le/lib64 /usr/bin/valgrind --error-exitcode=1 /builddir/build/BUILDROOT/glibc-2.34.9000-9.fc36.ppc64le/lib64/ld64.so.2 --library-path /builddir/build/BUILDROOT/glibc-2.34.9000-9.fc36.ppc64le/lib64 /usr/bin/true
> ==1924587== Memcheck, a memory error detector
> ==1924587== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
> ==1924587== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
> ==1924587== Command: /builddir/build/BUILDROOT/glibc-2.34.9000-9.fc36.ppc64le/lib64/ld64.so.2 --library-path /builddir/build/BUILDROOT/glibc-2.34.9000-9.fc36.ppc64le/lib64 /usr/bin/true
> ==1924587==
> ==1924587== Conditional jump or move depends on uninitialised value(s)
> ==1924587== at 0x191620: elf_get_dynamic_info (get-dynamic-info.h:73)
> ==1924587== by 0x191620: _dl_start (rtld.c:550)
> ==1924587== by 0x190677: (below main) (in /builddir/build/BUILDROOT/glibc-2.34.9000-9.fc36.ppc64le/lib64/ld64.so.2)
> ==1924587==
>
> For DONT_USE_BOOTSTRAP_MAP, bootstrap_map.l_ld_readonly is always zero,
> which is incorrect for RISC-V (which is PI_STATIC_AND_HIDDEN and thus
> DONT_USE_BOOTSTRAP_MAP).
>
> I don't see how to fix this without bringing back DL_RO_DYN_SECTION.
We can define DL_RO_DYN_SECTION and do
diff --git a/elf/rtld.c b/elf/rtld.c
index 8d2bba3d43..83adf1c5f5 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -547,6 +547,7 @@ _dl_start (void *arg)
/* Read our own dynamic section and fill in the info array. */
bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
+ bootstrap_map.l_ld_readonly = DL_RO_DYN_SECTION;
elf_get_dynamic_info (&bootstrap_map);
#if NO_TLS_OFFSET != 0
Will this work?
--
H.J.
More information about the Libc-alpha
mailing list