diff options
Diffstat (limited to 'ELF/Writer.cpp')
-rw-r--r-- | ELF/Writer.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp index e056384fbd44c..154de8cf6d186 100644 --- a/ELF/Writer.cpp +++ b/ELF/Writer.cpp @@ -625,15 +625,12 @@ void PhdrEntry::add(OutputSectionBase *Sec) { } template <class ELFT> -static Symbol *addOptionalSynthetic(StringRef Name, OutputSectionBase *Sec, - typename ELFT::uint Val, - uint8_t StOther = STV_HIDDEN) { - SymbolBody *S = Symtab<ELFT>::X->find(Name); - if (!S) - return nullptr; - if (!S->isUndefined() && !S->isShared()) - return S->symbol(); - return Symtab<ELFT>::X->addSynthetic(Name, Sec, Val, StOther); +static void addOptionalSynthetic(StringRef Name, OutputSectionBase *Sec, + typename ELFT::uint Val, + uint8_t StOther = STV_HIDDEN) { + if (SymbolBody *S = Symtab<ELFT>::X->find(Name)) + if (S->isUndefined() || S->isShared()) + Symtab<ELFT>::X->addSynthetic(Name, Sec, Val, StOther); } template <class ELFT> @@ -1447,8 +1444,13 @@ template <class ELFT> void Writer<ELFT>::setPhdrs() { } if (P.p_type == PT_LOAD) P.p_align = Config->MaxPageSize; - else if (P.p_type == PT_GNU_RELRO) + else if (P.p_type == PT_GNU_RELRO) { P.p_align = 1; + // The glibc dynamic loader rounds the size down, so we need to round up + // to protect the last page. This is a no-op on FreeBSD which always + // rounds up. + P.p_memsz = alignTo(P.p_memsz, Config->MaxPageSize); + } // The TLS pointer goes after PT_TLS. At least glibc will align it, // so round up the size to make sure the offsets are correct. |