diff options
-rw-r--r-- | lld/ELF/Writer.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 3fd1ab9af1e..3cb233290e1 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -567,18 +567,27 @@ static int getMipsSectionRank(const OutputSectionBase *S) { return 2; } +// Today's loaders have a feature to make segments read-only after +// processing dynamic relocations to enhance security. PT_GNU_RELRO +// is defined for that. +// +// This function returns true if a section needs to be put into a +// PT_GNU_RELRO segment. template <class ELFT> bool elf::isRelroSection(const OutputSectionBase *Sec) { if (!Config->ZRelro) return false; + uint64_t Flags = Sec->Flags; if (!(Flags & SHF_ALLOC) || !(Flags & SHF_WRITE)) return false; if (Flags & SHF_TLS) return true; + uint32_t Type = Sec->Type; if (Type == SHT_INIT_ARRAY || Type == SHT_FINI_ARRAY || Type == SHT_PREINIT_ARRAY) return true; + if (Sec == In<ELFT>::GotPlt->OutSec) return Config->ZNow; if (Sec == In<ELFT>::Dynamic->OutSec) @@ -587,6 +596,7 @@ template <class ELFT> bool elf::isRelroSection(const OutputSectionBase *Sec) { return true; if (Sec == Out<ELFT>::BssRelRo) return true; + StringRef S = Sec->getName(); return S == ".data.rel.ro" || S == ".ctors" || S == ".dtors" || S == ".jcr" || S == ".eh_frame" || S == ".openbsd.randomdata"; |