[llvm-dev] [lld][ELF] Add option to make .dynamic read only
Rafael Avila de Espindola via llvm-dev
llvm-dev at lists.llvm.org
Thu May 18 10:15:11 PDT 2017
Jake Ehrlich via llvm-dev <llvm-dev at lists.llvm.org> writes:
> Hi,
>
> This is a proposal to add an option to lld that forces .dynamic sections to
> be read-only.
>
> The .dynamic section is almost read-only except for the DT_DEBUG entry
> which requires the dynamic linker to modify a word. MIPS has long since had
> a solution to this using the DT_MIPS_RLD_MAP entry to give a pointer to
> another section which is writable. It would be nice to have this
> functionality on other targets as well however. Right now many dynamic
> linkers do not support this layer of indirection so this can't happen by
> default, it must be an option. Currently .dynamic gets mapped to a
> PT_GNU_RELRO section. PT_GNU_RELRO sections are not shared between
> instances of a executable however. It would be a nice optimization to share
> the .dynamic section of an application where possible. In particular we
> would like to have this option for Fuchsia. Other dynamic linkers, like
> musl, already have some support for this on non-MIPS targets as seen here:
> http://git.musl-libc.org/cgit/musl/tree/ldso/dynlink.c#n1629. In particular
> the DT_DEBUG_INDIRECT entry is recognized.
Actually, that is just a nice name they use. It is only defined to non
zero in
arch/mips/reloc.h:#define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
arch/mips64/reloc.h:#define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
arch/mipsn32/reloc.h:#define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
so it is still mips only.
Also, according to
https://sourceware.org/ml/binutils/2014-02/msg00073.html
The idea of having .dynamic be RW is that the .d_ptr fields can be
relocated. Not sure if any dynamic linker actually does it, but we
should check.
> This change would refactor code that already exists for MIPS specific
> .dynamic sections and make them available to other targets. Mostly this
> would just require renaming some things and moving a few lines around. The
> biggest part of this change would be to add the flag. I propose it be a -z
> keyword called "rodynamic".
>
> I have already made a patch for this change which can be seen here:
> https://reviews.llvm.org/D33251
The main issue if that you cannot reuse the mips specific flag value. If
you want something architecture independent you need a new flag.
Cheers,
Rafael
More information about the llvm-dev
mailing list